mailr13581 - /branches/gui_testing/generic_fns/pipes.py


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

Header


Content

Posted by edward on July 13, 2011 - 12:56:
Author: bugman
Date: Wed Jul 13 12:56:06 2011
New Revision: 13581

URL: http://svn.gna.org/viewcvs/relax?rev=13581&view=rev
Log:
Created generic_fns.pipes.Pipe_switch_observer for observing switches in the 
current data pipe.

Pipe_switch_observer.notify_observers() is now called by the switch() and 
delete() functions.


Modified:
    branches/gui_testing/generic_fns/pipes.py

Modified: branches/gui_testing/generic_fns/pipes.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/gui_testing/generic_fns/pipes.py?rev=13581&r1=13580&r2=13581&view=diff
==============================================================================
--- branches/gui_testing/generic_fns/pipes.py (original)
+++ branches/gui_testing/generic_fns/pipes.py Wed Jul 13 12:56:06 2011
@@ -30,6 +30,7 @@
 # relax module imports.
 from data import Relax_data_store; ds = Relax_data_store()
 from dep_check import C_module_exp_fn, scipy_module
+from observer import Observer
 from relax_errors import RelaxError, RelaxNoPipeError, RelaxPipeError
 
 
@@ -140,6 +141,10 @@
             ds.current_pipe = None
             __builtin__.cdp = None
 
+            # Register the switch.
+            switch_obj = Pipe_switch_observer()
+            switch_obj.notify_observers()
+
 
 def display():
     """Print the details of all the data pipes."""
@@ -257,6 +262,10 @@
     ds.current_pipe = pipe_name
     __builtin__.cdp = get_pipe()
 
+    # Register the switch.
+    switch_obj = Pipe_switch_observer()
+    switch_obj.notify_observers()
+
 
 def test(pipe_name=None):
     """Function for testing the existence of the current or supplied data 
pipe.
@@ -280,3 +289,20 @@
     if pipe_name not in ds:
         raise RelaxNoPipeError(pipe_name)
 
+
+
+class Pipe_switch_observer(Observer):
+    """Observer and singleton object for pipe switches."""
+
+    # Class variable for storing the class instance.
+    instance = None
+
+    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




Related Messages


Powered by MHonArc, Updated Wed Jul 13 13:20:02 2011