Browse Source

wxGUI/GConsole: new event, removing notebook dependecy and related NotebookControler changes (co-author: annakrat)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@53921 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 12 years ago
parent
commit
fc9a38a683

+ 1 - 0
gui/wxpython/core/events.py

@@ -20,5 +20,6 @@ from wx.lib.newevent import NewCommandEvent
 
 
 
 
 # Notification event intended to update statusbar.
 # Notification event intended to update statusbar.
+# The message attribute contains the text of the message (plain text)
 gShowNotification, EVT_SHOW_NOTIFICATION = NewCommandEvent()
 gShowNotification, EVT_SHOW_NOTIFICATION = NewCommandEvent()
 
 

+ 36 - 24
gui/wxpython/gui_core/goutput.py

@@ -199,12 +199,23 @@ class CmdThread(threading.Thread):
         self.requestCmd.abort()
         self.requestCmd.abort()
         if self.requestQ.empty():
         if self.requestQ.empty():
             self._want_abort_all = False
             self._want_abort_all = False
-        
+
+
+# Occurs event when some new text appears.
+# Text priority is specified by priority attribute.
+# Priority is 1 (lowest), 2, 3 (highest);
+# value 0 is currently not used and probably will not be used.
+# In theory, it can be used when text is completely uninteresting.
+# It is similar to wx.EVT_TEXT.
+# However, the new text or the whole text are not event attributes.
+gOutputText, EVT_OUTPUT_TEXT = NewEvent()
+
+
 class GConsole(wx.SplitterWindow):
 class GConsole(wx.SplitterWindow):
     """!Create and manage output console for commands run by GUI.
     """!Create and manage output console for commands run by GUI.
     """
     """
     def __init__(self, parent, id = wx.ID_ANY, margin = False,
     def __init__(self, parent, id = wx.ID_ANY, margin = False,
-                 frame = None, notebook = None,
+                 frame = None,
                  style = wx.TAB_TRAVERSAL | wx.FULL_REPAINT_ON_RESIZE,
                  style = wx.TAB_TRAVERSAL | wx.FULL_REPAINT_ON_RESIZE,
                  gcstyle = GC_EMPTY,
                  gcstyle = GC_EMPTY,
                  **kwargs):
                  **kwargs):
@@ -220,11 +231,6 @@ class GConsole(wx.SplitterWindow):
             self.frame = frame
             self.frame = frame
         else:
         else:
             self.frame = parent
             self.frame = parent
-        
-        if notebook:
-            self._notebook = notebook
-        else:
-            self._notebook = self.parent.notebook
 
 
         self._gcstyle = gcstyle
         self._gcstyle = gcstyle
         self.lineWidth       = 80
         self.lineWidth       = 80
@@ -453,8 +459,14 @@ class GConsole(wx.SplitterWindow):
 
 
         self.cmdOutput.SetStyle()
         self.cmdOutput.SetStyle()
 
 
+        # documenting old behavior/implementation:
+        # switch notebook if required
         if switchPage:
         if switchPage:
-            self._notebook.SetSelectionByName('output')
+            priority = 2
+        else:
+            priority = 1
+        event = gOutputText(priority = priority)
+        wx.PostEvent(self, event)
         
         
         if not style:
         if not style:
             style = self.cmdOutput.StyleDefault
             style = self.cmdOutput.StyleDefault
@@ -622,14 +634,15 @@ class GConsole(wx.SplitterWindow):
                     except GException, e:
                     except GException, e:
                         print >> sys.stderr, e
                         print >> sys.stderr, e
                     return
                     return
-                
-                # switch to 'Command output' if required
+
+                # documenting old behavior/implementation:
+                # switch and focus if required
+                # TODO: this probably should be run command event
                 if switchPage:
                 if switchPage:
-                    self._notebook.SetSelectionByName('output')
-                    
-                    self.frame.SetFocus()
-                    self.frame.Raise()
-                
+                    priority = 3
+                    event = gOutputText(priority = priority)
+                    wx.PostEvent(self, event)
+
                 # activate computational region (set with g.region)
                 # activate computational region (set with g.region)
                 # for all non-display commands.
                 # for all non-display commands.
                 if compReg:
                 if compReg:
@@ -739,16 +752,14 @@ class GConsole(wx.SplitterWindow):
         """!Print command output"""
         """!Print command output"""
         message = event.text
         message = event.text
         type  = event.type
         type  = event.type
+
         self.cmdOutput.AddStyledMessage(message, type)
         self.cmdOutput.AddStyledMessage(message, type)
 
 
-        if self._notebook.GetSelection() != self._notebook.GetPageIndexByName('output'):
-            page = self._notebook.GetPageIndexByName('output')
-            textP = self._notebook.GetPageText(page)
-            if textP[-1] != ')':
-                textP += ' (...)'
-            self._notebook.SetPageText(page, textP)
-        
-        
+        # documenting old behavior/implementation:
+        # add elipses if not active
+        event = gOutputText(priority = 1)
+        wx.PostEvent(self, event)
+
     def OnCmdProgress(self, event):
     def OnCmdProgress(self, event):
         """!Update progress message info"""
         """!Update progress message info"""
         self.progressbar.SetValue(event.value)
         self.progressbar.SetValue(event.value)
@@ -1091,6 +1102,7 @@ class GStc(stc.StyledTextCtrl):
 
 
         # remember position of line begining (used for '\r')
         # remember position of line begining (used for '\r')
         self.linePos         = -1
         self.linePos         = -1
+
         #
         #
         # styles
         # styles
         #                
         #                
@@ -1220,7 +1232,7 @@ class GStc(stc.StyledTextCtrl):
 
 
         # reset output window to read only
         # reset output window to read only
         self.SetReadOnly(True)
         self.SetReadOnly(True)
-    
+
     def AddStyledMessage(self, message, style = None):
     def AddStyledMessage(self, message, style = None):
         """!Add message to text area.
         """!Add message to text area.
 
 

+ 27 - 7
gui/wxpython/gui_core/widgets.py

@@ -65,9 +65,15 @@ class NotebookController:
     and other methods can be delegated by @c __getattr__.
     and other methods can be delegated by @c __getattr__.
     """
     """
     def __init__(self, classObject, widget):
     def __init__(self, classObject, widget):
+        """!        
+        @param classObject notebook class name (object, i.e. FlatNotebook)
+        @param widget notebook instance
+        """
         self.notebookPages = {}
         self.notebookPages = {}
         self.classObject = classObject
         self.classObject = classObject
         self.widget = widget
         self.widget = widget
+        # TODO: (...) should be only once in wxGUI
+        self.highlightedTextEnd = _(" (...)")
 
 
     def AddPage(self, **kwargs):
     def AddPage(self, **kwargs):
         """!Add a new page
         """!Add a new page
@@ -117,13 +123,20 @@ class NotebookController:
             return False
             return False
 
 
     def SetSelectionByName(self, page):
     def SetSelectionByName(self, page):
-        """!Set notebook
-        
-        @param page names, eg. 'layers', 'output', 'search', 'pyshell', 'nviz'
+        """!Set active notebook page.
+
+        @param page name, eg. 'layers', 'output', 'search', 'pyshell', 'nviz'
+        (depends on concrete notebook instance)
         """
         """
         idx = self.GetPageIndexByName(page)
         idx = self.GetPageIndexByName(page)
         if self.classObject.GetSelection(self.widget) != idx:
         if self.classObject.GetSelection(self.widget) != idx:
             self.classObject.SetSelection(self.widget, idx)
             self.classObject.SetSelection(self.widget, idx)
+            # FIXME: this code was not explicitly tested
+            # FIXME: remove this from function lmgr.frame.Frame.OnPageChanged
+            text = self.classObject.GetPageText(self.widget, idx)
+            if text.endswith(self.highlightedTextEnd):
+                text.replace(self.highlightedTextEnd, '')
+                self.classObject.SetPageText(self.widget, idx, text)
 
 
     def GetPageIndexByName(self, page):
     def GetPageIndexByName(self, page):
         """!Get notebook page index
         """!Get notebook page index
@@ -137,6 +150,17 @@ class NotebookController:
                 break
                 break
         return pageIndex
         return pageIndex
 
 
+    def HighlightPageByName(self, page):
+        pageIndex = self.GetPageIndexByName(page)
+        self.HighlightPage(pageIndex)
+        
+    def HighlightPage(self, index):
+        if self.classObject.GetSelection(self.widget) != index:
+            text = self.classObject.GetPageText(self.widget, index)
+            if not text.endswith(self.highlightedTextEnd):
+                text += self.highlightedTextEnd
+            self.classObject.SetPageText(self.widget, index, text)
+
     def SetPageImage(self, page, index):
     def SetPageImage(self, page, index):
         """!Sets image index for page
         """!Sets image index for page
 
 
@@ -194,10 +218,6 @@ class GNotebook(FN.FlatNotebook):
         return self.controller.RemovePage(page)
         return self.controller.RemovePage(page)
 
 
     def SetPageImage(self, page, index):
     def SetPageImage(self, page, index):
-        """! @copydoc NotebookController::SetPageImage()"""
-        return self.controller.SetPageImage(page, index)
-
-    def SetPageImage(self, page, index):
         """!Does nothing because we don't want images for this style"""
         """!Does nothing because we don't want images for this style"""
         pass
         pass
 
 

+ 12 - 1
gui/wxpython/lmgr/frame.py

@@ -50,7 +50,7 @@ from gui_core.widgets      import GNotebook
 from modules.mcalc_builder import MapCalcFrame
 from modules.mcalc_builder import MapCalcFrame
 from dbmgr.manager         import AttributeManager
 from dbmgr.manager         import AttributeManager
 from core.workspace        import ProcessWorkspaceFile, ProcessGrcFile, WriteWorkspaceFile
 from core.workspace        import ProcessWorkspaceFile, ProcessGrcFile, WriteWorkspaceFile
-from gui_core.goutput      import GConsole, GC_SEARCH, GC_PROMPT
+from gui_core.goutput      import GConsole, GC_SEARCH, GC_PROMPT, EVT_OUTPUT_TEXT
 from gui_core.dialogs      import GdalOutputDialog, DxfImportDialog, GdalImportDialog, MapLayersDialog
 from gui_core.dialogs      import GdalOutputDialog, DxfImportDialog, GdalImportDialog, MapLayersDialog
 from gui_core.dialogs      import EVT_APPLY_MAP_LAYERS
 from gui_core.dialogs      import EVT_APPLY_MAP_LAYERS
 from gui_core.dialogs      import LocationDialog, MapsetDialog, CreateNewVector, GroupDialog
 from gui_core.dialogs      import LocationDialog, MapsetDialog, CreateNewVector, GroupDialog
@@ -261,6 +261,7 @@ class GMFrame(wx.Frame):
         self.goutput = GConsole(self, frame = self,
         self.goutput = GConsole(self, frame = self,
                                 gcstyle = GC_SEARCH | GC_PROMPT)
                                 gcstyle = GC_SEARCH | GC_PROMPT)
         self.notebook.AddPage(page = self.goutput, text = _("Command console"), name = 'output')
         self.notebook.AddPage(page = self.goutput, text = _("Command console"), name = 'output')
+        self.goutput.Bind(EVT_OUTPUT_TEXT, self.OnOutputText)
         self._setCopyingOfSelectedText()
         self._setCopyingOfSelectedText()
         
         
         # create 'search module' notebook page
         # create 'search module' notebook page
@@ -523,6 +524,16 @@ class GMFrame(wx.Frame):
 
 
         event.Skip()
         event.Skip()
 
 
+    def OnOutputText(self, event):
+        """!Manages @c 'output' notebook page according to event priority."""
+        if event.priority == 1:
+            self.notebook.HighlightPageByName('output')
+        if event.priority >= 2:
+            self.notebook.SetSelectionByName('output')
+        if event.priority >= 3:
+            self.SetFocus()
+            self.Raise()
+
     def GetLayerNotebook(self):
     def GetLayerNotebook(self):
         """!Get Layers Notebook"""
         """!Get Layers Notebook"""
         return self.notebookLayers
         return self.notebookLayers