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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Sep 4 04:18:42 EDT 2008


Author: martinl
Date: 2008-09-04 04:18:41 -0400 (Thu, 04 Sep 2008)
New Revision: 33241

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
   grass/branches/develbranch_6/gui/wxpython/wxgui.py
Log:
wxGUI: new vector dialog optionally create also attribute table


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py	2008-09-04 08:11:53 UTC (rev 33240)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py	2008-09-04 08:18:41 UTC (rev 33241)
@@ -2122,6 +2122,7 @@
         #
         # list of table widgets
         #
+        keyCol = UserSettings.Get(group='atm', key='keycolumn', subkey='value')
         self.tableWidgets = {'table': (wx.StaticText(parent=self.addPanel, id=wx.ID_ANY,
                                                      label='%s:' % _("Table name")),
                                        wx.TextCtrl(parent=self.addPanel, id=wx.ID_ANY,
@@ -2130,7 +2131,7 @@
                              'key': (wx.StaticText(parent=self.addPanel, id=wx.ID_ANY,
                                                    label='%s:' % _("Key column")),
                                      wx.TextCtrl(parent=self.addPanel, id=wx.ID_ANY,
-                                                 value='cat',
+                                                 value=keyCol,
                                                  style=wx.TE_PROCESS_ENTER))}
         # events
         self.tableWidgets['table'][1].Bind(wx.EVT_TEXT_ENTER, self.OnCreateTable)

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2008-09-04 08:11:53 UTC (rev 33240)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2008-09-04 08:18:41 UTC (rev 33241)
@@ -42,7 +42,7 @@
 
 class NewVectorDialog(wx.Dialog):
     """Create new vector map layer"""
-    def __init__(self, parent, id, title, 
+    def __init__(self, parent, id, title, disableAdd=False, 
                 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
 
         wx.Dialog.__init__(self, parent, id, title, style=style)
@@ -58,7 +58,18 @@
                                    label=_("Name for new vector map:"))
         self.mapName = gselect.Select(parent=self.panel, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE,
                                       type='vector', mapsets=[grassenv.GetGRASSVariable('MAPSET'),])
+        self.table = wx.CheckBox(parent=self.panel, id=wx.ID_ANY,
+                                 label=_("Create attribute table"))
+        self.table.SetValue(True)
 
+        self.addbox = wx.CheckBox(parent=self.panel,
+                                  label=_('Add created map into layer tree'), style = wx.NO_BORDER)
+        if disableAdd:
+            self.addbox.SetValue(True)
+            self.addbox.Enable(False)
+        else:
+            self.addbox.SetValue(UserSettings.Get(group='cmd', key='addNewLayer', subkey='enabled'))
+        
         self.mapName.Bind(wx.EVT_TEXT, self.OnMapName)
         
         self.__Layout()
@@ -82,6 +93,14 @@
         dataSizer.Add(self.mapName, proportion=0,
                       flag=wx.EXPAND | wx.ALL, border=1)
         
+        dataSizer.Add(self.table, proportion=0,
+                      flag=wx.EXPAND | wx.ALL, border=1)
+
+        dataSizer.AddSpacer(5)
+        
+        dataSizer.Add(item=self.addbox, proportion=0,
+                      flag=wx.EXPAND | wx.ALL, border=1)
+                
         # buttons
         btnSizer = wx.StdDialogButtonSizer()
         btnSizer.AddButton(self.btnCancel)
@@ -104,16 +123,17 @@
         return mapName
     
 def CreateNewVector(parent, cmdDef, title=_('Create new vector map'),
-                    exceptMap=None, log=None):
+                    exceptMap=None, log=None, disableAdd=False):
     """Create new vector map layer
 
     @cmdList tuple/list (cmd list, output paramater)
     
-    @return name of create vector map
+    @return tuple (name of create vector map, add to layer tree)
     @return None of failure
     """
     cmd = cmdDef[0]
-    dlg = NewVectorDialog(parent=parent, id=wx.ID_ANY, title=title)
+    dlg = NewVectorDialog(parent, wx.ID_ANY, title,
+                          disableAdd)
     if dlg.ShowModal() == wx.ID_OK:
         outmap = dlg.GetName()
         if outmap == exceptMap:
@@ -155,6 +175,24 @@
             print >> sys.stderr, e
             return None
 
+        #
+        # create attribute table
+        #
+        if dlg.table.IsChecked():
+            key = UserSettings.Get(group='atm', key='keycolumn', subkey='value')
+            sql = 'CREATE TABLE %s (%s INTEGER)' % (outmap, key)
+            
+            gcmd.Command(['db.execute',
+                          '--q'],
+                         stdin=sql)
+
+            gcmd.Command(['v.db.connect',
+                          '--q',
+                          'map=%s' % outmap,
+                          'table=%s' % outmap,
+                          'key=%s' % key,
+                          'layer=1'])
+
         # return fully qualified map name
         if '@' not in outmap:
             outmap += '@' + grassenv.GetGRASSVariable('MAPSET')
@@ -162,9 +200,9 @@
         if log:
             log.WriteLog(_("New vector map <%s> created") % outmap)
 
-        return outmap
+        return (outmap, dlg.addbox.IsChecked())
 
-    return None
+    return (None, dlg.addbox.IsChecked())
 
 class SavedRegion(wx.Dialog):
     def __init__(self, parent, id, title="", pos=wx.DefaultPosition, size=wx.DefaultSize,

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2008-09-04 08:11:53 UTC (rev 33240)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2008-09-04 08:18:41 UTC (rev 33241)
@@ -128,6 +128,9 @@
                 'askOnDeleteRec' : {
                     'enabled' : True
                     },
+                'keycolumn' : {
+                    'value' : 'cat'
+                    },
             },
             #
             # Command
@@ -1253,6 +1256,36 @@
                       flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
                       border=3)
 
+        #
+        # create table
+        #
+        createTableBox = wx.StaticBox(parent=panel, id=wx.ID_ANY,
+                                    label=" %s " % _("Create table"))
+        createTableSizer = wx.StaticBoxSizer(createTableBox, wx.VERTICAL)
+
+        flexSizer = wx.FlexGridSizer (cols=2, hgap=5, vgap=5)
+        flexSizer.AddGrowableCol(0)
+
+        label = wx.StaticText(parent=panel, id=wx.ID_ANY,
+                              label=_("Key column"))
+        keyColumn = wx.TextCtrl(parent=panel, id=wx.ID_ANY,
+                                size=(250, -1))
+        keyColumn.SetValue(self.settings.Get(group='atm', key='keycolumn', subkey='value'))
+        self.winId['atm:keycolumn:value'] = keyColumn.GetId()
+        
+        flexSizer.Add(label, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
+        flexSizer.Add(keyColumn, proportion=0, flag=wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
+
+        createTableSizer.Add(item=flexSizer,
+                             proportion=0,
+                             flag=wx.ALL | wx.EXPAND,
+                             border=5)
+
+        pageSizer.Add(item=createTableSizer,
+                      proportion=0,
+                      flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
+                      border=3)
+        
         panel.SetSizer(pageSizer)
 
         return panel
@@ -1438,15 +1471,15 @@
 
     def OnSave(self, event):
         """Button 'Save' pressed"""
-        self.__UpdateSettings()
-        file = self.settings.SaveToFile()
-        self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % file)
-        self.Close()
+        if self.__UpdateSettings():
+            file = self.settings.SaveToFile()
+            self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % file)
+            self.Close()
 
     def OnApply(self, event):
         """Button 'Apply' pressed"""
-        self.__UpdateSettings()
-        self.Close()
+        if self.__UpdateSettings():
+            self.Close()
 
     def OnCancel(self, event):
         """Button 'Cancel' pressed"""
@@ -1474,7 +1507,6 @@
             else:
                 value = win.SetValue(value)
 
-
     def __UpdateSettings(self):
         """Update user settings"""
         for item in self.winId.keys():
@@ -1498,7 +1530,14 @@
                 value = tuple(win.GetValue())
             else:
                 value = win.GetValue()
-            
+
+            if key == 'keycolumn' and value == '':
+                wx.MessageBox(parent=self,
+                              message=_("Key column cannot be empty string."),
+                              caption=_("Error"), style=wx.OK | wx.ICON_ERROR)
+                win.SetValue(self.settings.Get(group='atm', key='keycolumn', subkey='value'))
+                return False
+
             if subkey1:
                 self.settings.Set(group, value, key, [subkey, subkey1])
             else:
@@ -1524,6 +1563,8 @@
         else:
             self.settings.Set(group='general', key='defWindowPos', subkey='dim', value='')
 
+        return True
+
 class SetDefaultFont(wx.Dialog):
     """
     Opens a file selection dialog to select default font

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2008-09-04 08:11:53 UTC (rev 33240)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2008-09-04 08:18:41 UTC (rev 33241)
@@ -980,7 +980,8 @@
                 openVectorMap = None
             mapName = gdialogs.CreateNewVector(self.parent,
                                                exceptMap=openVectorMap, log=self.log,
-                                               cmdDef=(['v.edit', 'tool=create'], "map"))
+                                               cmdDef=(['v.edit', 'tool=create'], "map"),
+                                               disableAdd=True)[0]
             if mapName:
                 # add layer to map layer tree
                 if self.layerTree:

Modified: grass/branches/develbranch_6/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/wxgui.py	2008-09-04 08:11:53 UTC (rev 33240)
+++ grass/branches/develbranch_6/gui/wxpython/wxgui.py	2008-09-04 08:18:41 UTC (rev 33241)
@@ -465,8 +465,16 @@
 
     def OnNewVector(self, event):
         """Create new vector map layer"""
-        name = gdialogs.CreateNewVector(self, log=self.goutput,
-                                        cmdDef=(['v.edit', 'tool=create'], "map"))
+        name, add = gdialogs.CreateNewVector(self, log=self.goutput,
+                                             cmdDef=(['v.edit', 'tool=create'], "map"))
+
+        if name and add:
+            # add layer to map layer tree
+            self.curr_page.maptree.AddLayer(ltype='vector',
+                                            lname=name,
+                                            lchecked=True,
+                                            lopacity=1.0,
+                                            lcmd=['d.vect', 'map=%s' % name])
             
     def OnAboutGRASS(self, event):
         """Display 'About GRASS' dialog"""



More information about the grass-commit mailing list