[GRASS-SVN] r40029 - in grass/branches/develbranch_6/gui/wxpython: . gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 16 15:20:53 EST 2009


Author: martinl
Date: 2009-12-16 15:20:53 -0500 (Wed, 16 Dec 2009)
New Revision: 40029

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/help.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/ogc_services.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/prompt.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py
   grass/branches/develbranch_6/gui/wxpython/wxgui.py
Log:
wxGUI: various fixes
      GPrompt in progress
      	      (merge r40027 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2009-12-16 20:13:31 UTC (rev 40028)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2009-12-16 20:20:53 UTC (rev 40029)
@@ -727,7 +727,7 @@
         # buttons
         #
         btnCancel = wx.Button(self, wx.ID_CANCEL)
-        btnOk = wx.Button(self, wx.ID_OK, _("Load") )
+        btnOk = wx.Button(self, wx.ID_OK, _("&Load") )
         btnOk.SetDefault()
         
         #

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2009-12-16 20:13:31 UTC (rev 40028)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2009-12-16 20:20:53 UTC (rev 40029)
@@ -624,23 +624,23 @@
                         mapTree = self.parent.parent.parent.curr_page.maptree
                     else: # GMConsole
                         mapTree = self.parent.parent.parent.parent.curr_page.maptree
+                    if not mapTree.GetMap().GetListOfLayers(l_name = name):
+                        if dialog.outputType == 'raster':
+                            lcmd = ['d.rast',
+                                    'map=%s' % name]
+                        else:
+                            lcmd = ['d.vect',
+                                    'map=%s' % name]
+                        mapTree.AddLayer(ltype=dialog.outputType,
+                                         lcmd=lcmd,
+                                         lname=name)
                     
-                    if dialog.outputType == 'raster':
-                        lcmd = ['d.rast',
-                                'map=%s' % name]
-                    else:
-                        lcmd = ['d.vect',
-                                'map=%s' % name]
-                    mapTree.AddLayer(ltype=dialog.outputType,
-                                     lcmd=lcmd,
-                                     lname=name)
-            
             if hasattr(dialog, "get_dcmd") and \
                     dialog.get_dcmd is None and \
                     dialog.closebox.IsChecked():
                 time.sleep(1)
                 dialog.Close()
-
+        
         event.Skip()
         
     def OnProcessPendingOutputWindowEvents(self, event):

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/help.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/help.py	2009-12-16 20:13:31 UTC (rev 40028)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/help.py	2009-12-16 20:20:53 UTC (rev 40029)
@@ -366,15 +366,18 @@
         wx.Frame.__init__(self, parent=parent, id=wx.ID_ANY, size=(550,400), 
                           title=_('About GRASS GIS'))
         
+        panel = wx.Panel(parent = self, id = wx.ID_ANY)
+        
         # icon
         self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
 
         # get version and web site
         version, svn_gis_h_rev, svn_gis_h_date = gcmd.RunCommand('g.version',
+                                                                 verbose = True, # -> svn revision
                                                                  flags = 'r',
                                                                  read = True).splitlines()
 
-        infoTxt = wx.Panel(parent = self, id = wx.ID_ANY)
+        infoTxt = wx.Panel(parent = panel, id = wx.ID_ANY)
         infoSizer = wx.BoxSizer(wx.VERTICAL)
         logo = os.path.join(globalvar.ETCDIR, "gui", "icons", "grass.ico")
         logoBitmap = wx.StaticBitmap(parent = infoTxt, id = wx.ID_ANY,
@@ -412,7 +415,7 @@
                 FN.FNB_NO_X_BUTTON | \
                 FN.FNB_NO_NAV_BUTTONS
                 
-        aboutNotebook = FN.FlatNotebook(self, id=wx.ID_ANY, style=nbstyle)
+        aboutNotebook = FN.FlatNotebook(panel, id=wx.ID_ANY, style=nbstyle)
         aboutNotebook.SetTabAreaColour(globalvar.FNPageColor)
         
         # make pages for About GRASS notebook
@@ -424,7 +427,7 @@
         pg5 = aboutNotebook.AddPage(transwin,     text=_("Translators"))
         
         # buttons
-        btnClose = wx.Button(parent = self, id = wx.ID_CLOSE)
+        btnClose = wx.Button(parent = panel, id = wx.ID_CLOSE)
         btnSizer = wx.BoxSizer(wx.HORIZONTAL)
         btnSizer.Add(item = btnClose, proportion = 1,
                      flag = wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT,
@@ -441,7 +444,7 @@
                   flag=wx.EXPAND | wx.ALL, border=1)
         sizer.Add(item=btnSizer, proportion=0,
                   flag=wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT, border=1)
-        self.SetSizer(sizer)
+        panel.SetSizer(sizer)
         self.Layout()
     
     def PageCopyright(self):

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/ogc_services.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/ogc_services.py	2009-12-16 20:13:31 UTC (rev 40028)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/ogc_services.py	2009-12-16 20:20:53 UTC (rev 40029)
@@ -1,9 +1,9 @@
-"""
+"""!
 @package ogc_services.py
 
 @brief Dialogs for OGC services
 
-Currently is implemeted only WMS.
+Currently only implemeted WMS.
 
 List of classes:
  - WMSDialog
@@ -279,20 +279,20 @@
 
     def GetSelectedLayers(self):
         """!Get selected layers/styles"""
-        layers = {}
+        layers = dict()
 
         for item in self.GetSelections():
             parent = self.GetItemParent(item)
             if parent == self.root: # -> layer
                 layer = self.GetItemText(item, 0)
-                layers[layer] = []
+                layers[layer] = list()
                 sitem, cookie = self.GetFirstChild(item)
                 while sitem:
                     layers[layer].append(self.GetItemText(sitem, 0))
                     sitem, cookie = self.GetNextChild(item, cookie)
             else: # -> style
                 layer = self.GetItemText(parent, 0)
-                layers[layer] = []
+                layers[layer] = list()
                 layers[layer].append(self.GetItemText(item, 0))
         
         return layers

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2009-12-16 20:13:31 UTC (rev 40028)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2009-12-16 20:20:53 UTC (rev 40029)
@@ -123,8 +123,9 @@
             #
             'projection' : {
                 'statusbar' : {
-                    'proj4'   : '',
-                    'epsg'    : '',
+                    'proj4'    : '',
+                    'epsg'     : '',
+                    'projFile' : utils.PathJoin(os.environ["GRASS_PROJSHARE"], 'epsg'),
                     },
                 'format' : {
                     'll'  : 'DMS',
@@ -206,7 +207,7 @@
                         },
                     },
                 'addNewLayer' : {
-                    'enabled' : False
+                    'enabled' : True,
                     },
                 },
             #
@@ -1496,7 +1497,7 @@
         label = wx.StaticText(parent=panel, id=wx.ID_ANY,
                               label=_("EPSG file:"))
         projFile = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
-                               value=utils.PathJoin(os.environ["GRASS_PROJSHARE"], 'epsg'),
+                               value = self.settings.Get(group='projection', key='statusbar', subkey='projFile'),
                                name="GetValue", size=(400, -1))
         self.winId['projection:statusbar:projFile'] = projFile.GetId()
         gridSizer.Add(item=label,

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/prompt.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/prompt.py	2009-12-16 20:13:31 UTC (rev 40028)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/prompt.py	2009-12-16 20:20:53 UTC (rev 40029)
@@ -1,7 +1,7 @@
 """!
 @package prompt.py
 
- at brief GRASS prompt
+ at brief wxGUI prompt
 
 Classes:
  - GPrompt
@@ -51,7 +51,7 @@
         # search
         #
         searchTxt = wx.StaticText(parent = cmdprompt, id = wx.ID_ANY,
-                                  label = _("Search:"))
+                                  label = _("Find module:"))
         
         self.searchBy = wx.Choice(parent = cmdprompt, id = wx.ID_ANY,
                              choices = [_("description"),
@@ -62,7 +62,7 @@
                              value = "", size = (-1, 25))
         
         label = wx.Button(parent = cmdprompt, id = wx.ID_ANY,
-                          label = _("Cmd >"), size = (-1, winHeight))
+                          label = _("&Cmd >"), size = (-1, winHeight))
         label.SetToolTipString(_("Click for erasing command prompt"))
 
         ### todo: fix TextCtrlAutoComplete to work also on Macs
@@ -95,6 +95,7 @@
         
         # layout
         sizer = wx.GridBagSizer(hgap=5, vgap=5)
+        sizer.AddGrowableRow(1)
         sizer.AddGrowableCol(2)
 
         sizer.Add(item = searchTxt,
@@ -344,43 +345,84 @@
         if toSel == -1:
             return
         self.dropdownlistbox.EnsureVisible(toSel)
+
+    def _setModule(self, name):
+        """!Set module's choices (flags, parameters)""" 
+        # get module's description
+        if name in self._choicesCmd and not self._module:
+            try:
+                self._module = menuform.GUI().ParseInterface(cmd = [name])
+            except IOError:
+                self._module = None
+             
+        # set choices (flags)
+        self._choicesMap['flag'] = self._module.get_list_flags()
+        for idx in range(len(self._choicesMap['flag'])):
+            item = self._choicesMap['flag'][idx]
+            desc = self._module.get_flag(item)['label']
+            if not desc:
+                desc = self._module.get_flag(item)['description']
+            
+            self._choicesMap['flag'][idx] = '%s (%s)' % (item, desc)
+        
+        # set choices (parameters)
+        self._choicesMap['param'] = self._module.get_list_params()
+        for idx in range(len(self._choicesMap['param'])):
+            item = self._choicesMap['param'][idx]
+            desc = self._module.get_param(item)['label']
+            if not desc:
+                desc = self._module.get_param(item)['description']
+            
+            self._choicesMap['param'][idx] = '%s (%s)' % (item, desc)
     
     def _setValueFromSelected(self):
          """!Sets the wx.TextCtrl value from the selected wx.ListCtrl item.
          Will do nothing if no item is selected in the wx.ListCtrl.
          """
          sel = self.dropdownlistbox.GetFirstSelected()
-         if sel > -1:
-            if self._colFetch != -1:
-                col = self._colFetch
-            else:
-                col = self._colSearch
-            itemtext = self.dropdownlistbox.GetItem(sel, col).GetText()
-            
-            cmd = shlex.split(str(self.GetValue()))
-            if len(cmd) > 1:
-                # -> append text (skip last item)
-                if self._choiceType == 'param':
-                    self.SetValue(' '.join(cmd[:-1]) + ' ' + itemtext + '=')
-                    optType = self._module.get_param(itemtext)['prompt']
-                    if optType in ('raster', 'vector'):
-                        # -> raster/vector map
-                        self.SetChoices(self._choicesMap[optType], optType)
-                elif self._choiceType == 'flag':
-                    if len(itemtext) > 1:
-                        prefix = '--'
-                    else:
-                        prefix = '-'
-                    self.SetValue(' '.join(cmd[:-1]) + ' ' + prefix + itemtext)
-                elif self._choiceType in ('raster', 'vector'):
-                    self.SetValue(' '.join(cmd[:-1]) + ' ' + cmd[-1].split('=', 1)[0] + '=' + itemtext)
-            else:
-                # -> reset text
-                self.SetValue(itemtext + ' ')
-            self.SetInsertionPointEnd()
-            
-            self._showDropDown(False)
+         if sel < 0:
+             return
          
+         if self._colFetch != -1:
+             col = self._colFetch
+         else:
+             col = self._colSearch
+         itemtext = self.dropdownlistbox.GetItem(sel, col).GetText()
+         
+         cmd = shlex.split(str(self.GetValue()))
+         if len(cmd) > 0 and cmd[0] in self._choicesCmd:
+             # -> append text (skip last item)
+             if self._choiceType == 'param':
+                 itemtext = itemtext.split(' ')[0]
+                 self.SetValue(' '.join(cmd) + ' ' + itemtext + '=')
+                 optType = self._module.get_param(itemtext)['prompt']
+                 if optType in ('raster', 'vector'):
+                     # -> raster/vector map
+                     self.SetChoices(self._choicesMap[optType], optType)
+             elif self._choiceType == 'flag':
+                 itemtext = itemtext.split(' ')[0]
+                 if len(itemtext) > 1:
+                     prefix = '--'
+                 else:
+                     prefix = '-'
+                 self.SetValue(' '.join(cmd[:-1]) + ' ' + prefix + itemtext)
+             elif self._choiceType in ('raster', 'vector'):
+                 self.SetValue(' '.join(cmd[:-1]) + ' ' + cmd[-1].split('=', 1)[0] + '=' + itemtext)
+         else:
+             # -> reset text
+             self.SetValue(itemtext + ' ')
+             
+             # define module
+             self._setModule(itemtext)
+             
+             # use parameters as default choices
+             self._choiceType = 'param'
+             self.SetChoices(self._choicesMap['param'], type = 'param')
+         
+         self.SetInsertionPointEnd()
+         
+         self._showDropDown(False)
+         
     def GetListCtrl(self):
         """!Method required by listmix.ColumnSorterMixin"""
         return self.dropdownlistbox
@@ -412,12 +454,15 @@
     def SetChoices(self, choices, type = 'module'):
         """!Sets the choices available in the popup wx.ListBox.
         The items will be sorted case insensitively.
+
+        @param choices list of choices
+        @param type type of choices (module, param, flag, raster, vector)
         """
         self._choices = choices
         self._choiceType = type
         
-        self.dropdownlistbox.SetWindowStyleFlag(wx.LC_REPORT | wx.LC_SINGLE_SEL | \
-                                                    wx.LC_SORT_ASCENDING | wx.LC_NO_HEADER)
+        self.dropdownlistbox.SetWindowStyleFlag(wx.LC_REPORT | wx.LC_SINGLE_SEL |
+                                                wx.LC_SORT_ASCENDING | wx.LC_NO_HEADER)
         if not isinstance(choices, list):
             self._choices = [ x for x in choices ]
         if self._choiceType not in ('raster', 'vector'):
@@ -452,6 +497,7 @@
         
     def OnCommandSelect(self, event):
         """!Command selected from history"""
+        self._historyItem = event.GetSelection() - len(self.GetItems())
         self.SetFocus()
         
     def OnListClick(self, evt):
@@ -496,26 +542,21 @@
         except ValueError, e:
             self.statusbar.SetStatusText(str(e))
             cmd = text.split(' ')
+        pattern = str(text)
         
-        pattern = str(text)
-        if len(cmd) > 1:
-            # search for module's options
-            if cmd[0] in self._choicesCmd and not self._module:
-                try:
-                    self._module = menuform.GUI().ParseInterface(cmd = cmd)
-                except IOError:
-                    self._module = None
-
+        if len(cmd) > 0 and cmd[0] in self._choicesCmd and not self._module:
+            self._setModule(cmd[0])
+        elif len(cmd) > 1 and cmd[0] in self._choicesCmd:
             if self._module:
                 if len(cmd[-1].split('=', 1)) == 1:
                     # new option
                     if cmd[-1][0] == '-':
                         # -> flags
-                        self.SetChoices(self._module.get_list_flags(), type = 'flag')
+                        self.SetChoices(self._choicesMap['flag'], type = 'flag')
                         pattern = cmd[-1].lstrip('-')
                     else:
                         # -> options
-                        self.SetChoices(self._module.get_list_params(), type = 'param')
+                        self.SetChoices(self._choicesMap['param'], type = 'param')
                         pattern = cmd[-1]
                 else:
                     # value
@@ -528,6 +569,8 @@
                 self._module = None
                 self._choiceType = None
         
+        self._choiceType
+        self._choicesMap
         found = False
         choices = self._choices
         for numCh, choice in enumerate(choices):
@@ -547,10 +590,10 @@
                 if self._module and '=' not in cmd[-1]:
                     message = ''
                     if cmd[-1][0] == '-': # flag
-                        message = "Warning: flag <%s> not found in '%s'" % \
+                        message = _("Warning: flag <%s> not found in '%s'") % \
                             (cmd[-1][1:], self._module.name)
                     else: # option
-                        message = "Warning: option <%s> not found in '%s'" % \
+                        message = _("Warning: option <%s> not found in '%s'") % \
                             (cmd[-1], self._module.name)
                     self.statusbar.SetStatusText(message)
         
@@ -572,13 +615,14 @@
         sel = self.dropdownlistbox.GetFirstSelected()
         visible = self.dropdown.IsShown()
         KC = event.GetKeyCode()
+        
         if KC == wx.WXK_RIGHT:
-            if len(self.GetValue()) < 1 and not visible:
-                if sel < (self.dropdownlistbox.GetItemCount() - 1):
-                    self.dropdownlistbox.Select(sel + 1)
-                    self._listItemVisible()
-                self._showDropDown()
-                skip = False
+            # right -> show choices
+            if sel < (self.dropdownlistbox.GetItemCount() - 1):
+                self.dropdownlistbox.Select(sel + 1)
+                self._listItemVisible()
+            self._showDropDown()
+            skip = False
         elif KC == wx.WXK_UP:
             if visible:
                 if sel > 0:

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py	2009-12-16 20:13:31 UTC (rev 40028)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py	2009-12-16 20:20:53 UTC (rev 40029)
@@ -195,7 +195,11 @@
         self.Bind(wx.EVT_KEY_UP,                self.OnKeyUp)
         # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
         self.Bind(wx.EVT_IDLE,                  self.OnIdle)
-                
+
+    def GetMap(self):
+        """!Get map instace"""
+        return self.Map
+    
     def OnIdle(self, event):
         """
         Only re-order and re-render a composite map image from GRASS during

Modified: grass/branches/develbranch_6/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/wxgui.py	2009-12-16 20:13:31 UTC (rev 40028)
+++ grass/branches/develbranch_6/gui/wxpython/wxgui.py	2009-12-16 20:20:53 UTC (rev 40029)
@@ -1,4 +1,4 @@
-"""
+"""!
 @package wxgui.py
 
 @brief Main Python app for GRASS wxPython GUI. Main menu, layer management
@@ -119,7 +119,6 @@
         self.disp_idx      = 0            # index value for map displays and layer trees
         self.curr_page     = ''           # currently selected page for layer tree notebook
         self.curr_pagenum  = ''           # currently selected page number for layer tree notebook
-        self.encoding      = 'ISO-8859-1' # default encoding for display fonts
         self.workspaceFile = workspace    # workspace file
         self.menucmd       = dict()       # menuId / cmd
         self.georectifying = None         # reference to GCP class or None
@@ -144,14 +143,11 @@
         self.SetMinSize((500, 400))
 
         # AUI stuff
-        #       self._auimgr.AddPane(self.toolbar, wx.aui.AuiPaneInfo().ToolbarPane().
-        #                              Top().Dockable(False).CloseButton(False).
-        #                              DestroyOnClose(True).Row(0).Layer(0))
         self._auimgr.AddPane(self.notebook, wx.aui.AuiPaneInfo().
                              Left().CentrePane().BestSize((-1,-1)).Dockable(False).
                              CloseButton(False).DestroyOnClose(True).Row(1).Layer(0))
         self._auimgr.AddPane(self.cmdprompt, wx.aui.AuiPaneInfo().
-                             Bottom().BestSize((-1, 65)).Dockable(False).
+                             Bottom().BestSize((-1, -1)).Dockable(False).
                              CloseButton(False).DestroyOnClose(True).
                              PaneBorder(False).Row(1).Layer(0).Position(0).
                              CaptionVisible(False))
@@ -552,7 +548,7 @@
     def OnAboutGRASS(self, event):
         """!Display 'About GRASS' dialog"""
         win = AboutWindow(self)
-        win.Centre()
+        win.CentreOnScreen()
         win.Show(True)  
         
     def OnWorkspace(self, event):
@@ -1545,18 +1541,20 @@
         event.Skip()
 
     def OnQuit(self, event):
-        """!Quit GRASS"""
+        """!Quit GRASS session (wxGUI and shell)"""
         # quit wxGUI session
         self.OnCloseWindow(event)
-
+        
         # quit GRASS shell
         try:
-            pid = os.environ['GRASS_SHELL_PID']
-        except KeyError:
+            pid = int(os.environ['GIS_LOCK'])
+        except (KeyError, ValueError):
+            sys.stderr.write('\n')
+            sys.stderr.write(_("WARNING: Unable to quit GRASS, uknown GIS_LOCK"))
             return
-
-        os.kill(int(pid), signal.SIGQUIT)
         
+        os.kill(pid, signal.SIGQUIT)
+        
     def OnCloseWindow(self, event):
         """!Cleanup when wxGUI is quit"""
         if not self.curr_page:



More information about the grass-commit mailing list