[GRASS-SVN] r37373 - in grass/trunk/gui/wxpython: . gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 22 11:32:17 EDT 2009


Author: martinl
Date: 2009-05-22 11:32:17 -0400 (Fri, 22 May 2009)
New Revision: 37373

Added:
   grass/trunk/gui/wxpython/gui_modules/prompt.py
Modified:
   grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI prompt in separate module


Added: grass/trunk/gui/wxpython/gui_modules/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/prompt.py	                        (rev 0)
+++ grass/trunk/gui/wxpython/gui_modules/prompt.py	2009-05-22 15:32:17 UTC (rev 37373)
@@ -0,0 +1,96 @@
+"""
+ at package prompt.py
+
+ at brief GRASS prompt
+
+Classes:
+ - GPrompt
+
+(C) 2009 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author Martin Landa <landa.martin gmail.com>
+"""
+
+import wx
+
+class GPrompt:
+    """Interactive GRASS prompt"""
+    def __init__(self, parent):
+        self.parent = parent
+                
+        self.panel, self.input = self.__create()
+        
+    def __create(self):
+        """Create widget"""
+        cmdprompt = wx.Panel(self.parent)
+        
+        label = wx.Button(parent = cmdprompt, id = wx.ID_ANY,
+                          label = _("Cmd >"), size = (-1, 25))
+        label.SetToolTipString(_("Click for erasing command prompt"))
+        
+        cmdinput = wx.TextCtrl(parent = cmdprompt, id = wx.ID_ANY,
+                               value = "",
+                               style = wx.TE_LINEWRAP | wx.TE_PROCESS_ENTER,
+                               size = (-1, 25))
+        
+        cmdinput.SetFont(wx.Font(10, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.NORMAL, 0, ''))
+        
+        wx.CallAfter(cmdinput.SetInsertionPoint, 0)
+        
+        label.Bind(wx.EVT_BUTTON,        self.OnCmdErase)
+        cmdinput.Bind(wx.EVT_TEXT_ENTER, self.OnRunCmd)
+        cmdinput.Bind(wx.EVT_TEXT,       self.OnUpdateStatusBar)
+        
+        # layout
+        sizer = wx.BoxSizer(wx.HORIZONTAL)
+        sizer.Add(item = label, proportion = 0,
+                  flag = wx.EXPAND | wx.LEFT | wx.RIGHT |
+                  wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER,
+                  border = 3)
+        sizer.Add(item = cmdinput, proportion = 1,
+                  flag = wx.EXPAND | wx.ALL,
+                  border = 1)
+        
+        cmdprompt.SetSizer(sizer)
+        sizer.Fit(cmdprompt)
+        cmdprompt.Layout()
+        
+        return cmdprompt, cmdinput
+
+    def GetPanel(self):
+        """Get main widget panel"""
+        return self.panel
+    
+    def OnCmdErase(self, event):
+        """Erase command prompt"""
+        self.input.SetValue('')
+        
+    def OnRunCmd(self, event):
+        """Run command"""
+        cmd = event.GetString()
+        
+        if self.parent.GetName() != "LayerManager":
+            return
+
+        if cmd[:2] == 'd.' and not self.parent.curr_page:
+            self.parent.NewDisplay(show=True)
+            
+        if len(cmd.split(' ')) > 1:
+            self.parent.goutput.RunCmd(cmd, switchPage = True)
+        else:
+            self.parent.goutput.RunCmd(cmd, switchPage = False)
+        
+        self.OnUpdateStatusBar(None)
+        
+    def OnUpdateStatusBar(self, event):
+        """Update Layer Manager status bar"""
+        if self.parent.GetName() != "LayerManager":
+            return
+        
+        if event is None:
+            self.parent.statusbar.SetStatusText("")
+        else:
+            self.parent.statusbar.SetStatusText(_("Type GRASS command and run by pressing ENTER"))

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2009-05-22 15:12:37 UTC (rev 37372)
+++ grass/trunk/gui/wxpython/wxgui.py	2009-05-22 15:32:17 UTC (rev 37373)
@@ -86,6 +86,7 @@
 import gui_modules.gdialogs as gdialogs
 import gui_modules.colorrules as colorrules
 import gui_modules.ogc_services as ogc_services
+import gui_modules.prompt as prompt
 from   gui_modules.debug import Debug as Debug
 from   icons.icon import Icons as Icons
 
@@ -189,58 +190,11 @@
         # start with layer manager on top
         self.curr_page.maptree.mapdisplay.Raise()
         self.Raise()
-
-    def __doLayout(self):
-        """Do Layout (unused bacause of aui manager...)"""
-        # self.panel = wx.Panel(self,-1, style= wx.EXPAND)
-        # sizer= wx.BoxSizer(wx.VERTICAL)
-        # self.cmdsizer = wx.BoxSizer(wx.HORIZONTAL)
-
-        # item, proportion, flag, border, userData
-        # self.sizer.Add(self.notebook, proportion=1, flag=wx.EXPAND, border=1)
-        # self.sizer.Add(self.cmdinput, proportion=0, flag=wx.EXPAND, border=1)
-        # self.SetSizer(self.sizer)
-
-        # self.sizer.Fit(self)
-        # self.Layout()
-
+        
     def __createCommandPrompt(self):
         """Creates command-line input area"""
-        self.cmdprompt = wx.Panel(self)
-
-        label = wx.Button(parent=self.cmdprompt, id=wx.ID_ANY,
-                          label=_("Cmd >"), size=(-1, 25))
-        label.SetToolTipString(_("Click for erasing command prompt"))
-
-        self.cmdinput = wx.TextCtrl(parent=self.cmdprompt, id=wx.ID_ANY,
-                                    value="",
-                                    style=wx.TE_LINEWRAP | wx.TE_PROCESS_ENTER,
-                                    size=(-1, 25))
-
-        self.cmdinput.SetFont(wx.Font(10, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.NORMAL, 0, ''))
-
-        wx.CallAfter(self.cmdinput.SetInsertionPoint, 0)
-        
-        label.Bind(wx.EVT_BUTTON,    self.OnCmdErase)
-        self.Bind(wx.EVT_TEXT_ENTER, self.OnRunCmd,          self.cmdinput)
-        self.Bind(wx.EVT_TEXT,       self.OnUpdateStatusBar, self.cmdinput)
-
-        # layout
-        sizer = wx.BoxSizer(wx.HORIZONTAL)
-        sizer.Add(item=label, proportion=0,
-                  flag=wx.EXPAND | wx.LEFT | wx.RIGHT | \
-                      wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER,
-                  border=3)
-        sizer.Add(item=self.cmdinput, proportion=1,
-                  flag=wx.EXPAND | wx.ALL,
-                  border=1)
-
-        self.cmdprompt.SetSizer(sizer)
-        sizer.Fit(self.cmdprompt)
-        self.cmdprompt.Layout()
-
-        return self.cmdprompt
-
+        return prompt.GPrompt(self).GetPanel()
+    
     def __createMenuBar(self):
         """Creates menubar"""
 
@@ -452,35 +406,11 @@
         self.curr_page = None
         
         event.Skip()
-
-    def OnRunCmd(self, event):
-        """Run command"""
-        cmd = event.GetString()
-
-        if cmd[:2] == 'd.' and not self.curr_page:
-            self.NewDisplay(show=True)
         
-        if len(cmd.split(' ')) > 1:
-            self.goutput.RunCmd(cmd, switchPage=True)
-        else:
-            self.goutput.RunCmd(cmd, switchPage=False)
-        
-        self.OnUpdateStatusBar(None)
-
-    def OnCmdErase(self, event):
-        """Erase command prompt"""
-        self.cmdinput.SetValue('')
-        
     def GetLogWindow(self):
         """Get widget for command output"""
         return self.goutput
-
-    def OnUpdateStatusBar(self, event):
-        if event is None:
-            self.statusbar.SetStatusText("")
-        else:
-            self.statusbar.SetStatusText(_("Type GRASS command and run by pressing ENTER"))
-
+    
     def GetMenuCmd(self, event):
         """Get GRASS command from menu item
 



More information about the grass-commit mailing list