mailr14084 - /branches/gui_testing/gui/controller.py


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

Header


Content

Posted by edward on August 03, 2011 - 12:06:
Author: bugman
Date: Wed Aug  3 12:06:22 2011
New Revision: 14084

URL: http://svn.gna.org/viewcvs/relax?rev=14084&view=rev
Log:
Shifted the writer thread into the log control, and Redirect_text handles 
both STDOUT and STDERR.

The Redirect_text class now is initialised twice, once for STDOUT and once 
for STDERR.  This allows
the two streams to be put on the FIFO with different flags.


Modified:
    branches/gui_testing/gui/controller.py

Modified: branches/gui_testing/gui/controller.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/controller.py?rev=14084&r1=14083&r2=14084&view=diff
==============================================================================
--- branches/gui_testing/gui/controller.py (original)
+++ branches/gui_testing/gui/controller.py Wed Aug  3 12:06:22 2011
@@ -88,14 +88,17 @@
         # Add the main execution gauge.
         self.main_gauge = self.add_gauge(self, sizer, "Execution status:")
 
+        # Initialise the FIFO.
+        self.fifo = Queue()
+
         # Add the log panel.
         self.add_log(sizer)
 
         # IO redirection.
         if not status.debug and not status.test_mode:
-            redir = Redirect_text(self.log_panel)
-            sys.stdout = redir
-            #sys.stderr = redir
+            # Redirect both stdout and stderr.
+            sys.stdout = Redirect_text(fifo=self.fifo, stream=0)
+            sys.stderr = Redirect_text(fifo=self.fifo, stream=1)
 
         # Initial update of the controller.
         self.update_controller()
@@ -155,7 +158,7 @@
         """
 
         # Log panel.
-        self.log_panel = LogCtrl(self, -1)
+        self.log_panel = LogCtrl(self, fifo=self.fifo, id=-1)
 
         # Add to the sizer.
         sizer.Add(self.log_panel, 1, wx.EXPAND|wx.ALL, 0)
@@ -490,11 +493,13 @@
 class LogCtrl(wx.stc.StyledTextCtrl):
     """A special control designed to display relax output messages."""
 
-    def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, 
size=wx.DefaultSize, style=wx.BORDER_SUNKEN, name=wx.stc.STCNameStr):
+    def __init__(self, parent, fifo=None, id=wx.ID_ANY, 
pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.BORDER_SUNKEN, 
name=wx.stc.STCNameStr):
         """Set up the log control.
 
         @param parent:          The parent wx window object.
         @type parent:           Window
+        @param fifo:            The FIFO object.
+        @type fifo:             Queue instance
         @keyword id:            The wx ID.
         @type id:               int
         @keyword pos:           The window position.
@@ -507,6 +512,9 @@
         @type name:             str
         """
 
+        # Store the args.
+        self.fifo = fifo
+
         # Initialise the base class.
         super(LogCtrl, self).__init__(parent, id=id, pos=pos, size=size, 
style=style, name=name)
 
@@ -515,6 +523,12 @@
 
         # Bind events.
         self.Bind(wx.EVT_KEY_DOWN, self.capture_keys)
+
+        # Flag for forcing the killing of the thread.
+        self.active = True
+
+        # Run the writer thread.
+        start_new_thread(self.writer_thread, ())
 
 
     def capture_keys(self, event):
@@ -577,7 +591,6 @@
             at_end = True
 
         # Add the text.
-        sys.__stdout__.write(string)
         self.AppendText(string)
 
         # Limit the scroll back.
@@ -591,27 +604,34 @@
         self.Thaw()
 
 
+    def writer_thread(self):
+        """Method run in a thread to read the FIFO and send text to the 
controller."""
+
+        # Infinite loop.
+        while self.active:
+            # Read from the FIFO (blocking as needed).
+            data = self.fifo.get()
+
+            # Append the text to the log control asynchronously.
+            wx.CallAfter(self.write, data[0])
+
+
+
 class Redirect_text(object):
     """The IO redirection to text control object."""
 
-    def __init__(self, control):
+    def __init__(self, fifo=None, stream=0):
         """Set up the text redirection object.
 
-        @param control:         The text control object to redirect IO to.
-        @type control:          wx.TextCtrl instance
+        @param fifo:        The FIFO object.
+        @type fifo:         Queue instance
+        @keyword stream:    The steam (0 = STDOUT, 1 = STDERR).
+        @type stream:       int
         """
 
         # Store the args.
-        self.control = control
-
-        # Flag for forcing the killing of the thread.
-        self.active = True
-
-        # Create a FIFO queue.
-        self.queue = Queue()
-
-        # Run the writer thread.
-        start_new_thread(self.writer_thread, ())
+        self.fifo = fifo
+        self.stream = stream
 
 
     def write(self, string):
@@ -621,17 +641,5 @@
         @type string:   str
         """
 
-        # Add the text to the queue, with a flag specifying stdout vs. 
stderr.
-        self.queue.put([string, 0])
-
-
-    def writer_thread(self):
-        """Method run in a thread to read the FIFO and send text to the 
controller."""
-
-        # Inifinite loop.
-        while self.active:
-            # Read from the FIFO (blocking as needed).
-            data = self.queue.get()
-
-            # Append the text to the controller asynchronously, with limited 
scroll back.
-            wx.CallAfter(self.control.write, data[0])
+        # Place STDOUT and STDERR in the queue with the flag specifying 
which is which.
+        self.fifo.put([string, self.stream])




Related Messages


Powered by MHonArc, Updated Wed Aug 03 14:20:02 2011