mailr14528 - /1.3/gui/interpreter.py


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

Header


Content

Posted by edward on August 30, 2011 - 16:10:
Author: bugman
Date: Tue Aug 30 16:10:19 2011
New Revision: 14528

URL: http://svn.gna.org/viewcvs/relax?rev=14528&view=rev
Log:
The GUI interpreter object has been converted into a singleton.


Modified:
    1.3/gui/interpreter.py

Modified: 1.3/gui/interpreter.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/interpreter.py?rev=14528&r1=14527&r2=14528&view=diff
==============================================================================
--- 1.3/gui/interpreter.py (original)
+++ 1.3/gui/interpreter.py Tue Aug 30 16:10:19 2011
@@ -42,20 +42,31 @@
 from gui.errors import gui_raise
 
 
-class Interpreter:
+class Interpreter(object):
     """The threaded interpreter."""
 
-    def __init__(self):
-        """Initialise the object."""
-
-        # Load a copy of the relax interpreter.
-        self._interpreter = interpreter.Interpreter(show_script=False, 
quit=False, raise_relax_error=True)
-        self._interpreter.populate_self()
-        self._interpreter.on(verbose=False)
-
-        # Start the interpreter thread for asynchronous operations.
-        self._interpreter_thread = Interpreter_thread()
-        self._interpreter_thread.start()
+    # Class variable for storing the class instance (for the singleton).
+    _instance = None
+
+    def __new__(self, *args, **kargs):
+        """Replacement method for implementing the singleton design 
pattern."""
+
+        # First instantiation.
+        if self._instance is None:
+            # Instantiate.
+            self._instance = object.__new__(self, *args, **kargs)
+
+            # Load a copy of the relax interpreter.
+            self._instance._interpreter = 
interpreter.Interpreter(show_script=False, quit=False, raise_relax_error=True)
+            self._instance._interpreter.populate_self()
+            self._instance._interpreter.on(verbose=False)
+
+            # Start the interpreter thread for asynchronous operations.
+            self._instance._interpreter_thread = Interpreter_thread()
+            self._instance._interpreter_thread.start()
+
+        # Already instantiated, so return the instance.
+        return self._instance
 
 
     def _get_uf(self, uf):




Related Messages


Powered by MHonArc, Updated Tue Aug 30 16:20:02 2011