Просмотр исходного кода

Make GMConsole working outside of wxGUI
(merge from devbr6, https://trac.osgeo.org/grass/changeset/38416)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@38417 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 16 лет назад
Родитель
Сommit
9330faa22e
1 измененных файлов с 24 добавлено и 19 удалено
  1. 24 19
      gui/wxpython/gui_modules/goutput.py

+ 24 - 19
gui/wxpython/gui_modules/goutput.py

@@ -112,19 +112,22 @@ class CmdThread(threading.Thread):
         self.requestCmd.abort()
     
 class GMConsole(wx.Panel):
-    """
-    Create and manage output console for commands entered on the
-    GIS Manager command line.
+    """!Create and manage output console for commands run by GUI.
     """
     def __init__(self, parent, id=wx.ID_ANY, margin=False, pageid=0,
-                 pos=wx.DefaultPosition, size=wx.DefaultSize,
-                 style=wx.TAB_TRAVERSAL | wx.FULL_REPAINT_ON_RESIZE):
-        wx.Panel.__init__(self, parent, id, pos, size, style)
+                 notebook = None,
+                 style=wx.TAB_TRAVERSAL | wx.FULL_REPAINT_ON_RESIZE,
+                 **kwargs):
+        wx.Panel.__init__(self, parent, id, style = style, *kwargs)
         self.SetName("GMConsole")
         
         # initialize variables
         self.Map             = None
-        self.parent          = parent # GMFrame | CmdPanel
+        self.parent          = parent # GMFrame | CmdPanel | ?
+        if notebook:
+            self._notebook = notebook
+        else:
+            self._notebook = self.parent.notebook
         self.lineWidth       = 80
         self.pageid          = pageid
         # remember position of line begining (used for '\r')
@@ -240,8 +243,8 @@ class GMConsole(wx.Panel):
         @param stdout write to stdout or stderr
         """
         if switchPage and \
-                self.parent.notebook.GetSelection() != self.parent.goutput.pageid:
-            self.parent.notebook.SetSelection(self.parent.goutput.pageid)
+                self._notebook.GetSelection() != self.parent.goutput.pageid:
+            self._notebook.SetSelection(self.parent.goutput.pageid)
         
         if not style:
             style = self.cmd_output.StyleDefault
@@ -376,8 +379,8 @@ class GMConsole(wx.Panel):
                 
                 # switch to 'Command output'
                 if switchPage:
-                    if self.parent.notebook.GetSelection() != self.parent.goutput.pageid:
-                        self.parent.notebook.SetSelection(self.parent.goutput.pageid)
+                    if self._notebook.GetSelection() != self.parent.goutput.pageid:
+                        self._notebook.SetSelection(self.parent.goutput.pageid)
                     
                     self.parent.SetFocus() # -> set focus
                     self.parent.Raise()
@@ -464,12 +467,12 @@ class GMConsole(wx.Panel):
         """!Print command output"""
         message = event.text
         type  = event.type
-        if self.parent.notebook.GetSelection() != self.parent.goutput.pageid:
-            textP = self.parent.notebook.GetPageText(self.parent.goutput.pageid)
+        if self._notebook.GetSelection() != self.parent.goutput.pageid:
+            textP = self._notebook.GetPageText(self.parent.goutput.pageid)
             if textP[-1] != ')':
                 textP += ' (...)'
-            self.parent.notebook.SetPageText(self.parent.goutput.pageid,
-                                             textP)
+            self._notebook.SetPageText(self.parent.goutput.pageid,
+                                       textP)
         
         # message prefix
         if type == 'warning':
@@ -583,8 +586,9 @@ class GMConsole(wx.Panel):
             if hasattr(self.parent.parent, "btn_help"):
                 dialog.btn_help.Enable(True)
 
-            dialog.btn_run.Enable(True)
-
+            if hasattr(self.parent.parent, "btn_run"):
+                dialog.btn_run.Enable(True)
+            
             if event.returncode == 0 and \
                     not event.aborted and hasattr(dialog, "addbox") and \
                     dialog.addbox.IsChecked():
@@ -609,8 +613,9 @@ class GMConsole(wx.Panel):
                                      lcmd=lcmd,
                                      lname=name)
             
-            if dialog.get_dcmd is None and \
-                   dialog.closebox.IsChecked():
+            if hasattr(dialog, "get_dcmd") and \
+                    dialog.get_dcmd is None and \
+                    dialog.closebox.IsChecked():
                 time.sleep(1)
                 dialog.Close()