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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 16 10:27:50 EDT 2008


Author: martinl
Date: 2008-03-16 10:27:50 -0400 (Sun, 16 Mar 2008)
New Revision: 30582

Added:
   grass/trunk/gui/wxpython/support/
Modified:
   grass/trunk/gui/wxpython/gui_modules/gselect.py
   grass/trunk/gui/wxpython/gui_modules/menuform.py
   grass/trunk/gui/wxpython/gui_modules/utils.py
   grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI: (menuform) use predefined widgets size
(gselect) SelectDialog class removed (unused)
(wxgui) reexec_python moved to 'utils' module 
Directory for support scripts added


Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py	2008-03-16 11:43:01 UTC (rev 30581)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py	2008-03-16 14:27:50 UTC (rev 30582)
@@ -25,45 +25,9 @@
 import gcmd
 from preferences import globalSettings as UserSettings
 
-class SelectDialog(wx.Dialog):
-    def __init__(self, parent, id=wx.ID_ANY, title='Select GIS element',
-                pos=wx.DefaultPosition, size=(-1,-1), type='cell', multiple=False,
-                style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER):
-        """
-        A dialog box for the GIS element selector control so that it can be launched
-        from a button or other control.
-        """
-
-        wx.Dialog.__init__(self, parent, id, title, pos, size, style)
-
-        self.selection = None
-
-        sizer = wx.BoxSizer(wx.VERTICAL)
-
-        self.selection = Select(self, id=wx.ID_ANY, size=(300,-1), type=type,
-                                multiple=multiple)
-        sizer.Add(self.selection, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
-
-        line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
-        sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
-
-        btnsizer = wx.StdDialogButtonSizer()
-
-        btn = wx.Button(self, wx.ID_OK)
-        btn.SetDefault()
-        btnsizer.AddButton(btn)
-
-        btn = wx.Button(self, wx.ID_CANCEL)
-        btnsizer.AddButton(btn)
-        btnsizer.Realize()
-
-        sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
-
-        self.SetSizer(sizer)
-        sizer.Fit(self)
-
 class Select(wx.combo.ComboCtrl):
-    def __init__(self, parent, id, size, type, multiple=False):
+    def __init__(self, parent, id, size,
+                 type, multiple=False, mapsets=None):
         """
         Custom control to create a ComboBox with a tree control
         to display and select GIS elements within acessible mapsets.
@@ -71,10 +35,11 @@
         argument multiple=True. Multiple selections are separated by commas.
         """
         wx.combo.ComboCtrl.__init__(self, parent=parent, id=id, size=size)
+
         self.tcp = TreeCtrlComboPopup()
         self.SetPopupControl(self.tcp)
         self.SetPopupExtents(0,100)
-        self.tcp.GetElementList(type)
+        self.tcp.GetElementList(type, mapsets)
         self.tcp.SetMultiple(multiple)
 
     def SetElementList(self, type):
@@ -151,17 +116,19 @@
     def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
         return wx.Size(minWidth, min(200, maxHeight))
 
-    def GetElementList(self, element):
+    def GetElementList(self, element, mapsets=None):
         """
         Get list of GIS elements in accessible mapsets and display as tree
         with all relevant elements displayed beneath each mapset branch
         """
-        #set environmental variables
+        # get current mapset
         cmdlist = ['g.gisenv', 'get=MAPSET']
         curr_mapset = gcmd.Command(cmdlist).ReadStdOutput()[0]
+        
+        # list of mapsets in current location
+        if mapsets is None:
+            mapsets = UserSettings.Get(group='general', key='mapsetPath', subkey='value', internal=True)
 
-        #mapsets in current location
-        mapsets = UserSettings.Get(group='general', key='mapsetPath', subkey='value', internal=True)
         # map element types to g.mlist types
         elementdict = {'cell':'rast',
                        'raster':'rast',
@@ -209,7 +176,7 @@
                        '3D view parameters':'3dview'}
 
         if element not in elementdict:
-            self.AddItem('Not selectable element')
+            self.AddItem(_('Not selectable element'))
             return
 
         # get directory tree nodes
@@ -218,6 +185,7 @@
             if i > 0 and mapsets[i] == curr_mapset:
                 mapsets[i] = mapsets[0]
                 mapsets[0] = curr_mapset
+
         for dir in mapsets:
             dir_node = self.AddItem('Mapset: '+dir)
             self.seltree.SetItemTextColour(dir_node,wx.Colour(50,50,200))

Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py	2008-03-16 11:43:01 UTC (rev 30581)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py	2008-03-16 14:27:50 UTC (rev 30582)
@@ -105,16 +105,19 @@
 
 ID_ABOUT_COMMAND = 102
 
-VSPACE = 4
-HSPACE = 4
-MENU_HEIGHT = 25
-STATUSBAR_HEIGHT = 30
-# ENTRY_HEIGHT = 25
-ENTRY_HEIGHT = -1
-STRING_ENTRY_WIDTH = 300
-BUTTON_HEIGHT = 44
-BUTTON_WIDTH = 100
+#
+# Widgets dimension
+#
+SPIN_SIZE = (150, -1)
+COMBOBOX_SIZE = (300, -1)
+GSELECT_SIZE = (400, -1)
+TEXTCTRL_SIZE = (400, -1)
 
+#
+# Global GRASS variables
+#
+CURR_MAPSET = grassenv.GetGRASSVariable('MAPSET')
+
 # From lib/gis/col_str.c, except purple which is mentioned
 # there but not given RGB values
 str2rgb = {'aqua': (100, 128, 255),
@@ -996,11 +999,11 @@
                             except ValueError:
                                 minValue = -1e6
                                 maxValue = 1e6
-                            txt2 = wx.SpinCtrl(parent=which_panel, id=wx.ID_ANY, size=(300, -1),
+                            txt2 = wx.SpinCtrl(parent=which_panel, id=wx.ID_ANY, size=SPIN_SIZE,
                                                min=minValue, max=maxValue)
                         else:
                             txt2 = wx.TextCtrl(parent=which_panel, value = p.get('default',''),
-                                               size = (STRING_ENTRY_WIDTH, ENTRY_HEIGHT))
+                                               size=TEXTCTRL_SIZE)
                         if p.get('value','') != '':
                             txt2.SetValue(p['value']) # parameter previously set
                         which_sizer.Add(item=txt2, proportion=0,
@@ -1014,7 +1017,7 @@
                         which_sizer.Add(item=txt, proportion=0,
                                         flag=wx.ADJUST_MINSIZE | wx.TOP | wx.RIGHT | wx.LEFT, border=5)
                         cb = wx.ComboBox(parent=which_panel, id=wx.ID_ANY, value=p.get('default',''),
-                                         size=wx.Size(STRING_ENTRY_WIDTH, -1),
+                                         size=COMBOBOX_SIZE,
                                          choices=valuelist, style=wx.CB_DROPDOWN)
                         if p.get('value','') != '':
                             cb.SetValue(p['value']) # parameter previously set
@@ -1036,13 +1039,13 @@
                 if p.get('multiple','yes') == 'yes' or \
                         p.get('type','string') == 'string':
                     txt3 = wx.TextCtrl(parent=which_panel, value = p.get('default',''),
-                                   size = (STRING_ENTRY_WIDTH, ENTRY_HEIGHT))
+                                   size=TEXTCTRL_SIZE)
                     txt3.Bind(wx.EVT_TEXT, self.OnSetValue)
                 else:
                     minValue = -1e9
                     maxValue = 1e9
                     txt3 = wx.SpinCtrl(parent=which_panel, value=p.get('default',''),
-                                       size = (STRING_ENTRY_WIDTH, ENTRY_HEIGHT),
+                                       size=SPIN_SIZE,
                                        min=minValue, max=maxValue)
                     txt3.Bind(wx.EVT_SPINCTRL, self.OnSetValue)
                     txt3.Bind(wx.EVT_TEXT, self.OnSetValue)
@@ -1063,8 +1066,13 @@
                         multiple = True
                     else:
                         multiple = False
-                    selection = gselect.Select(parent=which_panel, id=wx.ID_ANY, size=(400,-1),
-                                               type=p.get('element',''), multiple=multiple)
+                    if p.get('age','') == 'new':
+                        mapsets = [CURR_MAPSET,]
+                    else:
+                        mapsets = None
+
+                    selection = gselect.Select(parent=which_panel, id=wx.ID_ANY, size=GSELECT_SIZE,
+                                               type=p.get('element',''), multiple=multiple, mapsets=mapsets)
                     if p.get('value','') != '':
                         selection.SetValue(p['value']) # parameter previously set
 
@@ -1114,10 +1122,10 @@
                 # file selector
                 elif p.get('prompt','') != 'color' and p.get('element', '') == 'file':
                     fbb = filebrowse.FileBrowseButton(parent=which_panel, id=wx.ID_ANY, 
-                                                      size=(350, -1), labelText='',
-                                                      dialogTitle=_( 'Choose %s' ) % \
+                                                      size=GSELECT_SIZE, labelText='',
+                                                      dialogTitle=_('Choose %s') % \
                                                           p.get('description',_('File')),
-                                                      buttonText=_( 'Browse' ),
+                                                      buttonText=_('Browse'),
                                                       startDirectory=os.getcwd(), fileMode=0,
                                                       changeCallback=self.OnSetValue)
                     if p.get('value','') != '':
@@ -1378,7 +1386,7 @@
                     if self.grass_task.get_param(key)['element'] in ['cell', 'vector']:
                         # mapname -> mapname at mapset
                         if '@' not in value:
-                            value = value + '@' + grassenv.GetGRASSVariable('MAPSET')
+                            value = value + '@' + CURR_MAPSET
                     self.grass_task.set_param(key, value)
                     cmd_validated.append(key + '=' + value)
                     i = i + 1

Modified: grass/trunk/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/utils.py	2008-03-16 11:43:01 UTC (rev 30581)
+++ grass/trunk/gui/wxpython/gui_modules/utils.py	2008-03-16 14:27:50 UTC (rev 30582)
@@ -191,3 +191,10 @@
 def ListSortLower(list):
     """Sort list items (not case-sensitive)"""
     list.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
+
+def reexec_with_pythonw():
+    """Re-execute Python on Mac OS"""
+    if sys.platform == 'darwin' and \
+            not sys.executable.endswith('MacOS/Python'):
+        print >> sys.stderr, 're-executing using pythonw'
+        os.execvp('pythonw', ['pythonw', __file__] + sys.argv[1:])

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2008-03-16 11:43:01 UTC (rev 30581)
+++ grass/trunk/gui/wxpython/wxgui.py	2008-03-16 14:27:50 UTC (rev 30582)
@@ -1294,12 +1294,6 @@
 
         return True
 
-def reexec_with_pythonw():
-  if sys.platform == 'darwin' and \
-    not sys.executable.endswith('MacOS/Python'):
-    print >> sys.stderr, 're-executing using pythonw'
-    os.execvp('pythonw', ['pythonw', __file__] + sys.argv[1:])
-
 class Usage(Exception):
     def __init__(self, msg):
         self.msg = msg
@@ -1331,7 +1325,7 @@
     #
     # reexec for MacOS
     #
-    reexec_with_pythonw()
+    utils.reexec_with_pythonw()
 
     #
     # process command-line arguments



More information about the grass-commit mailing list