[GRASS-SVN] r51398 - grass/trunk/gui/wxpython/gui_core

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Apr 12 12:56:04 EDT 2012


Author: martinl
Date: 2012-04-12 09:56:04 -0700 (Thu, 12 Apr 2012)
New Revision: 51398

Modified:
   grass/trunk/gui/wxpython/gui_core/forms.py
   grass/trunk/gui/wxpython/gui_core/gselect.py
Log:
wxGUI/forms: expand also dbname
             various minor formating issues


Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py	2012-04-12 16:44:00 UTC (rev 51397)
+++ grass/trunk/gui/wxpython/gui_core/forms.py	2012-04-12 16:56:04 UTC (rev 51398)
@@ -319,7 +319,7 @@
                     self.data[win.UpdateItems] = { 'dbase' : pDbase.get('value', ''),
                                                    'location' : pLocation.get('value', '')}
 
-            elif name ==  'ProjSelect':
+            elif name == 'ProjSelect':
                 pDbase = self.task.get_param('dbase', element = 'element', raiseError = False)
                 pLocation = self.task.get_param('location', element = 'element', raiseError = False)
                 pMapset = self.task.get_param('mapset', element = 'element', raiseError = False)
@@ -388,7 +388,7 @@
         self.layer    = layer
         self.task     = task_description
         self.parent   = parent            # LayerTree | Modeler | None | ...
-        if parent and parent.GetName() ==  'Modeler':
+        if parent and parent.GetName() == 'Modeler':
             self.modeler = self.parent
         else:
             self.modeler = None
@@ -525,7 +525,7 @@
         if self.parent and not self.modeler:
             addLayer = False
             for p in self.task.params:
-                if p.get('age', 'old') ==  'new' and \
+                if p.get('age', 'old') == 'new' and \
                    p.get('prompt', '') in ('raster', 'vector', '3d-raster'):
                     addLayer = True
             
@@ -540,7 +540,7 @@
         
         hasNew = False
         for p in self.task.params:
-            if p.get('age', 'old') ==  'new':
+            if p.get('age', 'old') == 'new':
                 hasNew = True
                 break
         
@@ -608,15 +608,15 @@
             event.Skip()
             return
         
-        if kc ==  'Q':
+        if kc == 'Q':
             self.OnCancel(None)
-        elif kc ==  'S':
+        elif kc == 'S':
             self.OnAbort(None)
-        elif kc ==  'H':
+        elif kc == 'H':
             self.OnHelp(None)
-        elif kc ==  'R':
+        elif kc == 'R':
             self.OnRun(None)
-        elif kc ==  'C':
+        elif kc == 'C':
             self.OnCopy(None)
         
         event.Skip()
@@ -632,7 +632,7 @@
         if self.parent.GetName() not in ('LayerTree', 'LayerManager'):
             return
         
-        if self.parent.GetName() ==  'LayerTree':
+        if self.parent.GetName() == 'LayerTree':
             display = self.parent.GetMapDisplay()
         else: # Layer Manager
             display = self.parent.GetLayerTree().GetMapDisplay()
@@ -782,7 +782,7 @@
         # Determine tab layout
         sections = []
         is_section = {}
-        not_hidden = [ p for p in self.task.params + self.task.flags if not p.get('hidden', False) ==  True ]
+        not_hidden = [ p for p in self.task.params + self.task.flags if not p.get('hidden', False) == True ]
 
         self.label_id = [] # wrap titles on resize
 
@@ -792,7 +792,7 @@
             if task.get('required', False):
                 # All required go into Main, even if they had defined another guisection
                 task['guisection'] = _('Required')
-            if task.get('guisection','') ==  '':
+            if task.get('guisection','') == '':
                 # Undefined guisections end up into Options
                 task['guisection'] = _('Optional')
             if task['guisection'] not in is_section:
@@ -827,7 +827,7 @@
 
         # are we running from command line?
         ### add 'command output' tab regardless standalone dialog
-        if self.parent.GetName() ==  "MainFrame" and self.parent.get_dcmd is None:
+        if self.parent.GetName() == "MainFrame" and self.parent.get_dcmd is None:
             from gui_core.goutput import GMConsole
             self.goutput = GMConsole(parent = self, margin = False)
             self.outpage = self.notebook.AddPage(page = self.goutput, text = _("Command output"), name = 'output')
@@ -848,7 +848,7 @@
         # flags
         #
         text_style = wx.FONTWEIGHT_NORMAL
-        visible_flags = [ f for f in self.task.flags if not f.get('hidden', False) ==  True ]
+        visible_flags = [ f for f in self.task.flags if not f.get('hidden', False) == True ]
         for f in visible_flags:
             which_sizer = tabsizer[ f['guisection'] ]
             which_panel = tab[ f['guisection'] ]
@@ -876,7 +876,7 @@
             f['wxId'] = [ chk.GetId(), ]
             chk.Bind(wx.EVT_CHECKBOX, self.OnSetValue)
             
-            if self.parent.GetName() ==  'MainFrame' and self.parent.modeler:
+            if self.parent.GetName() == 'MainFrame' and self.parent.modeler:
                 parChk = wx.CheckBox(parent = which_panel, id = wx.ID_ANY,
                                      label = _("Parameterized in model"))
                 parChk.SetName('ModelParam')
@@ -892,17 +892,17 @@
             if f['name'] in ('verbose', 'quiet'):
                 chk.Bind(wx.EVT_CHECKBOX, self.OnVerbosity)
                 vq = UserSettings.Get(group = 'cmd', key = 'verbosity', subkey = 'selection')
-                if f['name'] ==  vq:
+                if f['name'] == vq:
                     chk.SetValue(True)
                     f['value'] = True
-            elif f['name'] ==  'overwrite' and 'value' not in f:
+            elif f['name'] == 'overwrite' and 'value' not in f:
                 chk.SetValue(UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'))
                 f['value'] = UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled')
                 
         #
         # parameters
         #
-        visible_params = [ p for p in self.task.params if not p.get('hidden', False) ==  True ]
+        visible_params = [ p for p in self.task.params if not p.get('hidden', False) == True ]
         
         try:
             first_param = visible_params[0]
@@ -910,8 +910,8 @@
             first_param = None
         
         for p in visible_params:
-            which_sizer = tabsizer[ p['guisection'] ]
-            which_panel = tab[ p['guisection'] ]
+            which_sizer = tabsizer[p['guisection']]
+            which_panel = tab[p['guisection']]
             # if label is given -> label and description -> tooltip
             # otherwise description -> lavel
             if p.get('label','') !=  '':
@@ -921,7 +921,9 @@
                 title = text_beautify(p['description'])
                 tooltip = None
             txt = None
-
+            
+            prompt = p.get('prompt', '')
+            
             # text style (required -> bold)
             if not p.get('required', False):
                 text_style = wx.FONTWEIGHT_NORMAL
@@ -931,8 +933,8 @@
             # title sizer (description, name, type)
             if (len(p.get('values', [])) > 0) and \
                     p.get('multiple', False) and \
-                    p.get('gisprompt',False) ==  False and \
-                    p.get('type', '') ==  'string':
+                    p.get('gisprompt', False) == False and \
+                    p.get('type', '') == 'string':
                 title_txt = wx.StaticBox(parent = which_panel, id = wx.ID_ANY)
             else:
                 title_sizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -952,9 +954,9 @@
             self.label_id.append(title_txt.GetId())
 
             # title expansion
-            if p.get('multiple', False) and len(p.get('values','')) ==  0:
+            if p.get('multiple', False) and len(p.get('values','')) == 0:
                 title = _("[multiple]") + " " + title
-                if p.get('value','') ==   '' :
+                if p.get('value','') ==  '' :
                     p['value'] = p.get('default','')
 
             if (len(p.get('values', [])) > 0):
@@ -962,8 +964,8 @@
                 valuelist_desc = map(unicode, p.get('values_desc',[]))
 
                 if p.get('multiple', False) and \
-                        p.get('gisprompt',False) ==  False and \
-                        p.get('type', '') ==  'string':
+                        p.get('gisprompt',False) == False and \
+                        p.get('type', '') == 'string':
                     title_txt.SetLabel(" %s: (%s, %s) " % (title, p['name'], p['type']))
                     if valuelist_desc:
                         hSizer = wx.StaticBoxSizer(box = title_txt, orient = wx.VERTICAL)
@@ -971,7 +973,7 @@
                         hSizer = wx.StaticBoxSizer(box = title_txt, orient = wx.HORIZONTAL)
                     isEnabled = {}
                     # copy default values
-                    if p['value'] ==  '':
+                    if p['value'] == '':
                         p['value'] = p.get('default', '')
                         
                     for defval in p.get('value', '').split(','):
@@ -998,12 +1000,12 @@
                         
                     which_sizer.Add(item = hSizer, proportion = 0,
                                     flag = wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, border = 5)
-                elif p.get('gisprompt', False) ==  False:
-                    if len(valuelist) ==  1: # -> textctrl
+                elif p.get('gisprompt', False) == False:
+                    if len(valuelist) == 1: # -> textctrl
                         title_txt.SetLabel("%s (%s %s):" % (title, _('valid range'),
                                                             str(valuelist[0])))
                         
-                        if p.get('type', '') ==  'integer' and \
+                        if p.get('type', '') == 'integer' and \
                                 not p.get('multiple', False):
 
                             # for multiple integers use textctrl instead of spinsctrl
@@ -1024,7 +1026,7 @@
                         value = self._getValue(p)
                         # parameter previously set
                         if value:
-                            if txt2.GetName() ==  "SpinCtrl":
+                            if txt2.GetName() == "SpinCtrl":
                                 txt2.SetValue(int(value))
                             else:
                                 txt2.SetValue(value)
@@ -1070,13 +1072,13 @@
             
             # text entry
             if (p.get('type','string') in ('string','integer','float')
-                and len(p.get('values',[])) ==  0
-                and p.get('gisprompt',False) ==  False
+                and len(p.get('values',[])) == 0
+                and p.get('gisprompt',False) == False
                 and p.get('prompt','') !=  'color'):
 
                 title_txt.SetLabel(title + ':')
                 if p.get('multiple', False) or \
-                        p.get('type', 'string') ==  'string' or \
+                        p.get('type', 'string') == 'string' or \
                         len(p.get('key_desc', [])) > 1:
                     txt3 = wx.TextCtrl(parent = which_panel, value = p.get('default',''))
                     
@@ -1090,7 +1092,7 @@
                 else:
                     minValue = -1e9
                     maxValue = 1e9
-                    if p.get('type', '') ==  'integer':
+                    if p.get('type', '') == 'integer':
                         txt3 = wx.SpinCtrl(parent = which_panel, value = p.get('default',''),
                                            size = globalvar.DIALOG_SPIN_SIZE,
                                            min = minValue, max = maxValue)
@@ -1119,7 +1121,7 @@
             #
             # element selection tree combobox (maps, icons, regions, etc.)
             #
-            if p.get('gisprompt', False) ==  True:
+            if p.get('gisprompt', False):
                 title_txt.SetLabel(title + ':')
                 # GIS element entry
                 if p.get('prompt','') not in ('color',
@@ -1136,13 +1138,13 @@
                                               'dbase') and \
                                               p.get('element', '') not in ('file', 'dir'):
                     multiple = p.get('multiple', False)
-                    if p.get('age', '') ==  'new':
+                    if p.get('age', '') == 'new':
                         mapsets = [grass.gisenv()['MAPSET'],]
                     else:
                         mapsets = None
                     if self.task.name in ('r.proj', 'v.proj') \
-                            and p.get('name', '') ==  'input':
-                        if self.task.name ==  'r.proj':
+                            and p.get('name', '') == 'input':
+                        if self.task.name == 'r.proj':
                             isRaster = True
                         else:
                             isRaster = False
@@ -1170,10 +1172,10 @@
                         p['wxId'] = [ textWin.GetId(), ]
                         textWin.Bind(wx.EVT_TEXT, self.OnSetValue)
                     
-                    if p.get('prompt', '') ==  'vector':
+                    if prompt == 'vector':
                         selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
                         
-                        # if formatSelector and p.get('age', 'old') ==  'old':
+                        # if formatSelector and p.get('age', 'old') == 'old':
                         #     # OGR supported (read-only)
                         #     self.hsizer = wx.BoxSizer(wx.HORIZONTAL)
                             
@@ -1215,7 +1217,7 @@
                         which_sizer.Add(item = selection, proportion = 0,
                                         flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
                                         border = 5)
-                    elif p.get('prompt', '') ==  'group':
+                    elif prompt == 'group':
                         selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
                         which_sizer.Add(item = selection, proportion = 0,
                                         flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
@@ -1225,7 +1227,7 @@
                                         flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
                                         border = 5)
                 # subgroup
-                elif p.get('prompt', '') ==  'subgroup':
+                elif prompt == 'subgroup':
                     selection = gselect.SubGroupSelect(parent = which_panel)
                     p['wxId'] = [ selection.GetId() ]
                     selection.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
@@ -1235,29 +1237,28 @@
                                     border = 5)
 
                 # layer, dbdriver, dbname, dbcolumn, dbtable entry
-                elif p.get('prompt', '') in ('dbdriver',
-                                             'dbname',
-                                             'dbtable',
-                                             'dbcolumn',
-                                             'layer',
-                                             'layer_all',
-                                             'location',
-                                             'mapset',
-                                             'dbase'):
-                    if p.get('multiple', 'no') ==  'yes':
+                elif prompt in ('dbdriver',
+                                'dbname',
+                                'dbtable',
+                                'dbcolumn',
+                                'layer',
+                                'layer_all',
+                                'location',
+                                'mapset',
+                                'dbase'):
+                    if p.get('multiple', 'no') == 'yes':
                         win = wx.TextCtrl(parent = which_panel, value = p.get('default',''),
                                           size = globalvar.DIALOG_TEXTCTRL_SIZE)
                         win.Bind(wx.EVT_TEXT, self.OnSetValue)
                     else:
                         value = self._getValue(p)
                         
-                        if p.get('prompt', '') in ('layer',
-                                                   'layer_all'):
-                            if p.get('prompt', '') ==  'layer_all':
+                        if prompt in ('layer', 'layer_all'):
+                            if prompt == 'layer_all':
                                 all = True
                             else:
                                 all = False
-                            if p.get('age', 'old') ==  'old':
+                            if p.get('age', 'old') == 'old':
                                 win = gselect.LayerSelect(parent = which_panel,
                                                           all = all,
                                                           default = p['default'])
@@ -1272,19 +1273,19 @@
 
                             p['wxId'] = [ win.GetId() ]
 
-                        elif p.get('prompt', '') ==  'dbdriver':
+                        elif prompt == 'dbdriver':
                             win = gselect.DriverSelect(parent = which_panel,
                                                        choices = p.get('values', []),
                                                        value = value)
                             win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
                             win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
-                        elif p.get('prompt', '') ==  'dbname':
+                        elif prompt == 'dbname':
                             win = gselect.DatabaseSelect(parent = which_panel,
                                                          value = value)
                             win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
                             win.Bind(wx.EVT_TEXT, self.OnSetValue)
-                        elif p.get('prompt', '') ==  'dbtable':
-                            if p.get('age', 'old') ==  'old':
+                        elif prompt == 'dbtable':
+                            if p.get('age', 'old') == 'old':
                                 win = gselect.TableSelect(parent = which_panel)
                                 win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
                                 win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
@@ -1292,20 +1293,20 @@
                                 win = wx.TextCtrl(parent = which_panel, value = p.get('default',''),
                                                   size = globalvar.DIALOG_TEXTCTRL_SIZE)
                                 win.Bind(wx.EVT_TEXT, self.OnSetValue)
-                        elif p.get('prompt', '') ==  'dbcolumn':
+                        elif prompt == 'dbcolumn':
                             win = gselect.ColumnSelect(parent = which_panel,
                                                        value = value,
                                                        param = p)
                             win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
                             win.Bind(wx.EVT_TEXT,     self.OnSetValue)
 
-                        elif p.get('prompt', '') ==  'location':
+                        elif prompt == 'location':
                             win = gselect.LocationSelect(parent = which_panel,
                                                          value = value)
                             win.Bind(wx.EVT_COMBOBOX,     self.OnUpdateSelection)
                             win.Bind(wx.EVT_COMBOBOX,     self.OnSetValue)
                         
-                        elif p.get('prompt', '') == 'mapset':
+                        elif prompt == 'mapset':
                             if p.get('age', 'old') == 'old':
                                 new = False
                             else:
@@ -1316,7 +1317,7 @@
                             win.Bind(wx.EVT_COMBOBOX,     self.OnSetValue) 
                             win.Bind(wx.EVT_TEXT,         self.OnSetValue)
                             
-                        elif p.get('prompt', '') ==  'dbase':
+                        elif prompt == 'dbase':
                             win = gselect.DbaseSelect(parent = which_panel,
                                                       changeCallback = self.OnSetValue)
                             win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
@@ -1328,18 +1329,21 @@
                         except AttributeError:
                             pass
                     
+                    flags = wx.BOTTOM | wx.LEFT | wx.RIGHT
+                    if prompt == 'dbname':
+                        flags |= wx.EXPAND
                     which_sizer.Add(item = win, proportion = 0,
-                                    flag = wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT, border = 5)
+                                    flag = flags, border = 5)
                 # color entry
-                elif p.get('prompt', '') in ('color',
-                                             'color_none'):
+                elif prompt in ('color',
+                                'color_none'):
                     default_color = (200,200,200)
                     label_color = _("Select Color")
                     if p.get('default','') !=  '':
                         default_color, label_color = color_resolve(p['default'])
                     if p.get('value','') !=  '': # parameter previously set
                         default_color, label_color = color_resolve(p['value'])
-                    if p.get('prompt', '') ==  'color_none':
+                    if prompt == 'color_none':
                         this_sizer = wx.BoxSizer(orient = wx.HORIZONTAL)
                     else:
                         this_sizer = which_sizer
@@ -1352,9 +1356,9 @@
                     # the selector proper and either a "transparent" button or None
                     p['wxId'] = [btn_colour.GetId(),]
                     btn_colour.Bind(csel.EVT_COLOURSELECT,  self.OnColorChange)
-                    if p.get('prompt', '') ==  'color_none':
+                    if prompt == 'color_none':
                         none_check = wx.CheckBox(which_panel, wx.ID_ANY, _("Transparent"))
-                        if p.get('value','') !=  '' and p.get('value',[''])[0] ==  "none":
+                        if p.get('value','') !=  '' and p.get('value',[''])[0] == "none":
                             none_check.SetValue(True)
                         else:
                             none_check.SetValue(False)
@@ -1366,7 +1370,7 @@
                     else:
                         p['wxId'].append(None)
                 # file selector
-                elif p.get('prompt','') !=  'color' and p.get('element', '') ==  'file':
+                elif p.get('prompt','') !=  'color' and p.get('element', '') == 'file':
                     if p.get('age', 'new') == 'new':
                         fmode = wx.SAVE
                     else:
@@ -1426,7 +1430,7 @@
                         p['wxId'].append(btnSave.GetId())
                 
                 # directory selector
-                elif p.get('prompt','') != 'color' and p.get('element', '') ==  'dir':
+                elif p.get('prompt','') != 'color' and p.get('element', '') == 'dir':
                     fbb = filebrowse.DirBrowseButton(parent = which_panel, id = wx.ID_ANY,
                                                      size = globalvar.DIALOG_GSELECT_SIZE, labelText = '',
                                                      dialogTitle = _('Choose %s') % \
@@ -1465,14 +1469,14 @@
                         tooltip +=  2 * os.linesep
                     else:
                         tooltip = ''
-                    if len(p['values']) ==  len(p['values_desc']):
+                    if len(p['values']) == len(p['values_desc']):
                         for i in range(len(p['values'])):
                             tooltip +=  p['values'][i] + ': ' + p['values_desc'][i] + os.linesep
                     tooltip.strip(os.linesep)
                 if tooltip:
                     title_txt.SetToolTipString(tooltip)
 
-            if p ==  first_param:
+            if p == first_param:
                 if 'wxId' in p and len(p['wxId']) > 0:
                     win = self.FindWindowById(p['wxId'][0])
                     win.SetFocus()
@@ -1492,7 +1496,7 @@
         pLocation = None
         pMapset = None
         for p in self.task.params:
-            if p.get('gisprompt', False) ==  False:
+            if p.get('gisprompt', False) == False:
                 continue
             
             guidep = p.get('guidependency', '')
@@ -1513,25 +1517,25 @@
                 name = p.get('name', '')
                 if name in ('map', 'input'):
                     pMap = p
-            elif prompt ==  'layer':
+            elif prompt == 'layer':
                 pLayer.append(p)
-            elif prompt ==  'dbcolumn':
+            elif prompt == 'dbcolumn':
                 pColumn.append(p)
-            elif prompt ==  'dbdriver':
+            elif prompt == 'dbdriver':
                 pDriver = p
-            elif prompt ==  'dbname':
+            elif prompt == 'dbname':
                 pDatabase = p
-            elif prompt ==  'dbtable':
+            elif prompt == 'dbtable':
                 pTable = p
-            elif prompt ==  'group':
+            elif prompt == 'group':
                 pGroup = p
-            elif prompt ==  'subgroup':
+            elif prompt == 'subgroup':
                 pSubGroup = p
-            elif prompt ==  'dbase':
+            elif prompt == 'dbase':
                 pDbase = p
-            elif prompt ==  'location':
+            elif prompt == 'location':
                 pLocation = p
-            elif prompt ==  'mapset':
+            elif prompt == 'mapset':
                 pMapset = p
         
         # collect ids
@@ -1707,18 +1711,18 @@
         winNative = None
         winOgr = None
         for id in p['wxId']:
-            if id ==  idEvent:
+            if id == idEvent:
                 continue
             name = self.FindWindowById(id).GetName()
-            if name ==  'Select':
+            if name == 'Select':
                 winNative = self.FindWindowById(id + 1)  # fix the mystery (also in nviz_tools.py)
-            elif name ==  'OgrSelect':
+            elif name == 'OgrSelect':
                 winOgr = self.FindWindowById(id)
         
         # enable / disable widgets & update values
         rbox = self.FindWindowByName('VectorFormat')
         self.hsizer.Remove(rbox)
-        if sel ==  0:   # -> native
+        if sel == 0:   # -> native
             winOgr.Hide()
             self.hsizer.Remove(winOgr)
             
@@ -1728,7 +1732,7 @@
             winNative.Show()
             p['value'] = winNative.GetValue()
         
-        elif sel ==  1: # -> OGR
+        elif sel == 1: # -> OGR
             sizer = wx.BoxSizer(wx.VERTICAL)
             
             winNative.Hide()
@@ -1763,7 +1767,7 @@
         verbose = self.FindWindowById(self.task.get_flag('verbose')['wxId'][0])
         quiet = self.FindWindowById(self.task.get_flag('quiet')['wxId'][0])
         if event.IsChecked():
-            if event.GetId() ==  verbose.GetId():
+            if event.GetId() == verbose.GetId():
                 if quiet.IsChecked():
                     quiet.SetValue(False)
                     self.task.get_flag('quiet')['value'] = False
@@ -1781,7 +1785,7 @@
             sel = event.GetSelection()
         
         idx = self.notebook.GetPageIndexByName('manual')
-        if idx > -1 and sel ==  idx:
+        if idx > -1 and sel == idx:
             # calling LoadPage() is strangely time-consuming (only first call)
             # FIXME: move to helpPage.__init__()
             if not self.manual_tab.IsLoaded():
@@ -1795,7 +1799,7 @@
         for p in self.task.params:
             if 'wxId' in p and myId in p['wxId']:
                 has_button = p['wxId'][1] is not None
-                if has_button and wx.FindWindowById(p['wxId'][1]).GetValue() ==  True:
+                if has_button and wx.FindWindowById(p['wxId'][1]).GetValue() == True:
                     p[ 'value' ] = 'none'
                 else:
                     colorchooser = wx.FindWindowById(p['wxId'][0])
@@ -1874,9 +1878,9 @@
         if not found:
             return
         
-        if name ==  'GdalSelect':
+        if name == 'GdalSelect':
             porf['value'] = event.dsn
-        elif name ==  'ModelParam':
+        elif name == 'ModelParam':
             porf['parameterized'] = me.IsChecked()
         else:
             porf['value'] = me.GetValue()
@@ -2029,8 +2033,8 @@
             i = 0
             cmd_validated = [cmd[0]]
             for option in cmd[1:]:
-                if option[0] ==  '-': # flag
-                    if option[1] ==  '-':
+                if option[0] == '-': # flag
+                    if option[1] == '-':
                         self.grass_task.set_flag(option[2:], True)
                     else:
                         self.grass_task.set_flag(option[1], True)
@@ -2128,7 +2132,7 @@
                     age = p.get('age', '')
                     prompt = p.get('prompt', '')
                     element = p.get('element', '') 
-                    if age ==  'old' and \
+                    if age == 'old' and \
                             element in ('cell', 'grid3', 'vector') and \
                             prompt in ('raster', '3d-raster', 'vector'):
                         return p.get('name', None)
@@ -2155,11 +2159,11 @@
         
         return True
 
-if __name__ ==  "__main__":
+if __name__ == "__main__":
     import gettext
     gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
     
-    if len(sys.argv) ==  1:
+    if len(sys.argv) == 1:
         sys.exit(_("usage: %s <grass command>") % sys.argv[0])
     
     if sys.argv[1] !=  'test':
@@ -2177,7 +2181,7 @@
             task.get_flag('v')['value'] = True
             task.get_param('layer')['value'] = 1
             task.get_param('bcolor')['value'] = "red"
-            assert ' '.join(task.get_cmd()) ==  "d.vect -v map = map_name layer = 1 bcolor = red"
+            assert ' '.join(task.get_cmd()) == "d.vect -v map = map_name layer = 1 bcolor = red"
         # Test interface building with handmade grassTask,
         # possibly outside of a GRASS session.
         task = gtask.grassTask()

Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py	2012-04-12 16:44:00 UTC (rev 51397)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py	2012-04-12 16:56:04 UTC (rev 51398)
@@ -733,31 +733,25 @@
 class DatabaseSelect(wx.TextCtrl):
     """!Creates combo box for selecting database driver.
     """
-    def __init__(self, parent, value='',
-                 id=wx.ID_ANY, pos=wx.DefaultPosition,
-                 size=globalvar.DIALOG_TEXTCTRL_SIZE, **kargs):
-        
-        super(DatabaseSelect, self).__init__(parent, id, value, pos, size)
-                               
+    def __init__(self, parent, value = '', id = wx.ID_ANY, 
+                 size = globalvar.DIALOG_TEXTCTRL_SIZE, **kargs):
+        super(DatabaseSelect, self).__init__(parent, id, value, size = size, **kargs)
         self.SetName("DatabaseSelect")
-
+    
 class TableSelect(wx.ComboBox):
     """!Creates combo box for selecting attribute tables from the database
     """
     def __init__(self, parent,
-                 id=wx.ID_ANY, value='', pos=wx.DefaultPosition,
-                 size=globalvar.DIALOG_COMBOBOX_SIZE,
-                 choices=[]):
-
-        super(TableSelect, self).__init__(parent, id, value, pos, size, choices,
-                                          style=wx.CB_READONLY)
-
+                 id = wx.ID_ANY, value = '', 
+                 size = globalvar.DIALOG_COMBOBOX_SIZE, choices = [], **kargs):
+        super(TableSelect, self).__init__(parent, id, value, size = size, choices = choices,
+                                          style = wx.CB_READONLY, **kargs)
         self.SetName("TableSelect")
-
+        
         if not choices:
             self.InsertTables()
                 
-    def InsertTables(self, driver=None, database=None):
+    def InsertTables(self, driver = None, database = None):
         """!Insert attribute tables into combobox"""
         items = []
 
@@ -776,7 +770,7 @@
         if ret:
             for table in ret.splitlines():
                 items.append(table)
-            
+        
         self.SetItems(items)
         self.SetValue('')
         
@@ -794,7 +788,7 @@
     @param **kwags wx.ComboBox parameters
     """
     def __init__(self, parent, id = wx.ID_ANY, value = '', 
-                 size=globalvar.DIALOG_COMBOBOX_SIZE,
+                 size = globalvar.DIALOG_COMBOBOX_SIZE,
                  vector = None, layer = 1, param = None, **kwargs):
         self.defaultValue = value
         self.param = param
@@ -1404,12 +1398,23 @@
             return
         
         name = dlg.GetValue()
+        
+        # check if settings item already exists
+        if name in self._settings:
+            dlgOwt = wx.MessageDialog(self, message = _("Settings <%s> already exists. "
+                                                     "Do you want to overwrite the settings?") % name,
+                                   caption = _("Save settings"), style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
+            if dlgOwt.ShowModal() != wx.ID_YES:
+                dlgOwt.Destroy()
+                return
+
+        self._settings[name] = (self.dsnType, self.GetDsn(),
+                                self.format.GetStringSelection(),
+                                self.creationOpt.GetValue())
         try:
-            fd = open(self.settingsFile, 'a')
-            fd.write(name + ';' + self.dsnType + ';' +
-                     self.GetDsn() + ';' +
-                     self.format.GetStringSelection())
-            fd.write('\n')
+            fd = open(self.settingsFile, 'w')
+            for name, value in self._settings.iteritems():
+                fd.write('%s;%s;%s;%s\n' % (name, value[0], value[1], value[2]))
         except IOError:
             GError(parent = self,
                    message = _("Unable to save settings"))
@@ -1518,6 +1523,7 @@
             if sel == self.sourceMap['db-pg']:
                 if self.format.IsEnabled():
                     self.format.Enable(False)
+                self.creationOpt.Enable(True)
             else:
                 if not self.format.IsEnabled():
                     self.format.Enable(True)



More information about the grass-commit mailing list