mailr13582 - /branches/gui_testing/gui/analyses/__init__.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 - 13:11:
Author: bugman
Date: Wed Jul 13 13:11:28 2011
New Revision: 13582

URL: http://svn.gna.org/viewcvs/relax?rev=13582&view=rev
Log:
Created the page_switch() method and registered it for pipe switches.

The new page_switch() method is registered with the Pipe_switch_observer 
singleton and observer
object so that pipe switches cause the notebook to switch pages.  The 
switch_page() method has also
been created to abstract the switching of pages in the notebook.


Modified:
    branches/gui_testing/gui/analyses/__init__.py

Modified: branches/gui_testing/gui/analyses/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/analyses/__init__.py?rev=13582&r1=13581&r2=13582&view=diff
==============================================================================
--- branches/gui_testing/gui/analyses/__init__.py (original)
+++ branches/gui_testing/gui/analyses/__init__.py Wed Jul 13 13:11:28 2011
@@ -80,6 +80,11 @@
         # Create a container in the status singleton for the analyses.
         status.analyses = Status_container()
 
+        # Register the page switch method for pipe switches.
+        switch_obj = pipes.Pipe_switch_observer()
+        self.name = 'notebook page switcher'
+        switch_obj.register_observer(self.name, self.pipe_switch)
+
 
     def analysis_data_loop(self):
         """Loop over the analyses, yielding the data objects.
@@ -157,16 +162,12 @@
 
         # The current page has been deleted, so switch one back (if 
possible).
         if index == self._current and self._current != 0:
-            # Decrement.
-            self._current -= 1
-
-            # Switch to that page.
-            self.notebook.SetSelection(self._current)
-
+            self.switch_page(self._current-1)
 
         # No more analyses, so in the initial state.
         if self._num_analyses == 0:
             self.set_init_state()
+
 
     def get_page_from_name(self, name):
         """Return the page corresponding to the given name.
@@ -340,11 +341,8 @@
         # Increment the number of analyses.
         self._num_analyses += 1
 
-        # Set this new analysis to the current one.
-        self._current = self._num_analyses - 1
-
         # Switch to the new page.
-        self.notebook.SetSelection(self._current)
+        self.switch(self._num_analyses-1)
 
         # Set the initialisation flag.
         self.init_state = False
@@ -373,6 +371,33 @@
         event.Skip()
 
 
+    def pipe_switch(self, pipe=None):
+        """Switch the page to the given or current data pipe.
+
+        @keyword pipe:  The pipe associated with the page to switch to.  If 
not supplied, the current data pipe will be used.
+        @type pipe:     str or None
+        """
+
+        # The data pipe.
+        if pipe == None:
+            pipe = pipes.cdp_name()
+
+        # Find the page.
+        index = None
+        for i in range(self._num_analyses):
+            # Matching page.
+            if ds.relax_gui.analyses[i].pipe_name == pipe:
+                index = i
+                break
+
+        # No matching page.
+        if index == None:
+            return
+
+        # Switch to the page.
+        self.switch_page(i)
+
+
     def set_init_state(self):
         """Revert to the initial state."""
 
@@ -403,6 +428,19 @@
         self.results_viewer.Show()
 
 
+    def switch_page(self, index):
+        """Switch to the given page.
+
+        @param index:   The index of the page to switch to.
+        @type index:    int
+        """
+
+        # Set the current page number.
+        self._current = index
+
+        # Switch to the page.
+        self.notebook.SetSelection(self._current)
+
 
 class Status_container(ListType):
     """The status container object."""




Related Messages


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