Author: bugman Date: Wed Jul 13 12:06:27 2011 New Revision: 13580 URL: http://svn.gna.org/viewcvs/relax?rev=13580&view=rev Log: The User_functions class now derives from the Observer base class. Modified: branches/gui_testing/gui/user_functions/__init__.py Modified: branches/gui_testing/gui/user_functions/__init__.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/user_functions/__init__.py?rev=13580&r1=13579&r2=13580&view=diff ============================================================================== --- branches/gui_testing/gui/user_functions/__init__.py (original) +++ branches/gui_testing/gui/user_functions/__init__.py Wed Jul 13 12:06:27 2011 @@ -24,6 +24,7 @@ """User function GUI elements.""" # relax module imports. +from observer import Observer from prompt.interpreter import Interpreter from relax_errors import RelaxError @@ -58,7 +59,7 @@ 'value'] -class User_functions: +class User_functions(Observer): """Container for all the user function GUI elements. This uses the observer design pattern to allow for GUI updates upon completion of a user function. @@ -69,6 +70,9 @@ # Store the args. self.gui = gui + + # Execute the observer base class module __init__() method. + super(User_functions, self).__init__() # Load the interpreter. self.interpreter = Interpreter(show_script=True, quit=False, raise_relax_error=True) @@ -89,9 +93,6 @@ self.structure = Structure(self.gui, self.interpreter) self.value = Value(self.gui, self.interpreter) - # The dictionary of callback methods. - self._callback = {} - def destroy(self): """Close all windows.""" @@ -108,43 +109,3 @@ self.spin.destroy() self.structure.destroy() self.value.destroy() - - - def notify_observers(self): - """Notify all observers that a user function has completed.""" - - # Loop over the callback methods and execute them. - for key in self._callback.keys(): - self._callback[key]() - - - def register_observer(self, key, method): - """Register a method to be called when all user functions complete. - - @param key: The key to identify the observer's method. - @type key: str - @param method: The observer's method to be called after completion of the user function. - @type method: method - """ - - # Already exists. - if key in self._callback.keys(): - raise RelaxError("The key '%s' already exists." % key) - - # Add the method to the dictionary of callbacks. - self._callback[key] = method - - - def unregister_observer(self, key): - """Unregister the method corresponding to the key. - - @param method: The observer's method to be called after completion of the user function. - @type method: method - """ - - # Does not exist. - if key not in self._callback.keys(): - raise RelaxError("The key '%s' does not exist." % key) - - # Remove the method from the dictionary of callbacks. - self._callback.pop(key)