mailr10862 - /1.3/info.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on February 23, 2010 - 18:20:
Author: bugman
Date: Tue Feb 23 18:20:45 2010
New Revision: 10862

URL: http://svn.gna.org/viewcvs/relax?rev=10862&view=rev
Log:
Converted the Info_box into a singleton.

This will allow for execution specific info to be placed in here and accessed 
by all.


Modified:
    1.3/info.py

Modified: 1.3/info.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/info.py?rev=10862&r1=10861&r2=10862&view=diff
==============================================================================
--- 1.3/info.py (original)
+++ 1.3/info.py Tue Feb 23 18:20:45 2010
@@ -35,6 +35,9 @@
 class Info_box:
     """A container storing information about relax."""
 
+    # Class variable for storing the class instance.
+    instance = None
+
     def __init__(self):
         """Create the program introduction text stings.
 
@@ -75,6 +78,17 @@
 
         # References.
         self._setup_references()
+
+
+    def __new__(self, *args, **kargs):
+        """Replacement function for implementing the singleton design 
pattern."""
+
+        # First initialisation.
+        if self.instance is None:
+            self.instance = dict.__new__(self, *args, **kargs)
+
+        # Already initialised, so return the instance.
+        return self.instance
 
 
     def _setup_references(self):




Related Messages


Powered by MHonArc, Updated Tue Feb 23 18:40:02 2010