[GRASS-SVN] r59388 - in grass/trunk/gui/wxpython: core lmgr

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Mar 26 19:18:07 PDT 2014


Author: wenzeslaus
Date: 2014-03-26 19:18:06 -0700 (Wed, 26 Mar 2014)
New Revision: 59388

Modified:
   grass/trunk/gui/wxpython/core/gconsole.py
   grass/trunk/gui/wxpython/lmgr/frame.py
Log:
wxGUI/lmgr: implement cd command for wxGUI Command console, possibility to ignore any commands in gconsole, printing cd log for cd from menu

Modified: grass/trunk/gui/wxpython/core/gconsole.py
===================================================================
--- grass/trunk/gui/wxpython/core/gconsole.py	2014-03-26 23:13:57 UTC (rev 59387)
+++ grass/trunk/gui/wxpython/core/gconsole.py	2014-03-27 02:18:06 UTC (rev 59388)
@@ -524,6 +524,14 @@
             #
             # Check if the script has an interface (avoid double-launching
             # of the script)
+
+            # check if we ignore the command (similar to grass commands part)
+            if self._ignoredCmdPattern and \
+               re.compile(self._ignoredCmdPattern).search(' '.join(command)):
+                event = gIgnoredCmdRun(cmd=command)
+                wx.PostEvent(self, event)
+                return
+
             skipInterface = True
             if os.path.splitext(command[0])[1] in ('.py', '.sh'):
                 try:

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2014-03-26 23:13:57 UTC (rev 59387)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2014-03-27 02:18:06 UTC (rev 59388)
@@ -291,7 +291,8 @@
         self._gconsole = GConsole(guiparent = self, giface = self._giface,
                                   ignoredCmdPattern = '^d\..*|^r[3]?\.mapcalc$|^i.group$|^r.in.gdal$|'
                                                       '^r.external$|^r.external.out$|'
-                                                      '^v.in.ogr$|^v.external$|^v.external.out$')
+                                                      '^v.in.ogr$|^v.external$|^v.external.out$|'
+                                                      '^cd$|^cd .*')
         self.goutput = GConsoleWindow(parent = self, gconsole = self._gconsole,
                                       menuModel=self._moduleTreeBuilder.GetModel(),
                                       gcstyle = GC_PROMPT)
@@ -621,7 +622,8 @@
             self.OnLinkOgrLayers(event = None, cmd = command)
         elif command[0] == 'v.external.out':
              self.OnVectorOutputFormat(event = None)
-
+        elif command[0] == 'cd':
+             self.OnChangeCWD(event=None, cmd=command)
         else:
             raise ValueError('Layer Manager special command (%s)'
                              ' not supported.' % ' '.join(command))
@@ -945,15 +947,54 @@
                     display.SetTitle(dispId) # TODO: signal ?
                     dispId += 1 
         
-    def OnChangeCWD(self, event):
+    def OnChangeCWD(self, event=None, cmd=None):
         """!Change current working directory
+
+        @param event to be able to serve as a handler of wx event
+        @param command cd command as a list (must start with 'cd')
         """
-        dlg = wx.DirDialog(parent = self, message = _("Choose a working directory"),
-                            defaultPath = os.getcwd(), style = wx.DD_CHANGE_DIR)
+        # local functions
+        def write_beginning(directory):
+            self._giface.WriteCmdLog('cd "' + directory + '"')
 
-        if dlg.ShowModal() == wx.ID_OK:
-            self.cwdPath = dlg.GetPath() # is saved in the workspace
+        def write_changed():
+            self._giface.WriteLog(_("Working directory changed to:\n\"%s\"")
+                                  % os.getcwd())
 
+        def write_end():
+            self._giface.WriteCmdLog(' ')
+
+        # check correctness of cmd
+        if cmd and (cmd[0] != 'cd' or len(cmd) > 2):
+            raise ValueError("OnChangeCWD cmd parameter must be list with"
+                             " lenght 1 or 2 and 'cd' as a first item")
+        # use chdir or dialog
+        if cmd and len(cmd) == 2:
+            write_beginning(cmd[1])
+            if cmd[1] in ['-h', '--h', '--help']:
+                self._giface.WriteLog(_("Changes current working directory"
+                                        " for this GUI."))
+                self._giface.WriteLog(_("Usage: cd [directory]"))
+                write_end()
+                return
+            try:
+                os.chdir(cmd[1])
+                write_changed()
+            except OSError as error:
+                self._giface.WriteError(str(error))
+            write_end()
+        else:
+            # style wx.DD_CHANGE_DIR changes the directory
+            dlg = wx.DirDialog(parent=self,
+                               message=_("Choose a working directory"),
+                               defaultPath=os.getcwd(), style=wx.DD_CHANGE_DIR)
+
+            if dlg.ShowModal() == wx.ID_OK:
+                self.cwdPath = dlg.GetPath()  # is saved in the workspace
+                write_beginning(self.cwdPath)
+                write_changed()
+                write_end()
+
     def GetCwdPath(self):
         """!Get current working directory or None"""
         return self.cwdPath



More information about the grass-commit mailing list