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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 20 19:39:12 EDT 2008


Author: martinl
Date: 2008-03-20 19:39:11 -0400 (Thu, 20 Mar 2008)
New Revision: 30664

Added:
   grass/trunk/gui/wxpython/gui_modules/gdialogs.py
Modified:
   grass/trunk/gui/wxpython/gui_modules/dbm.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/menudata.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI: (gdialogs) new module for common wxGUI dialogs
(digit) create new vector map layer from toolbar
Use common dialog for creating new vector map layer instead of v.edit directly


Modified: grass/trunk/gui/wxpython/gui_modules/dbm.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/dbm.py	2008-03-20 22:58:23 UTC (rev 30663)
+++ grass/trunk/gui/wxpython/gui_modules/dbm.py	2008-03-20 23:39:11 UTC (rev 30664)
@@ -20,7 +20,6 @@
  - DisplayAttributesDialog
  - VectorDBInfo
  - ModifyTableRecord
- - NewVectorDialog
 
 (C) 2007-2008 by the GRASS Development Team
 
@@ -53,6 +52,7 @@
 import grassenv
 import gcmd
 import utils
+import gdialogs
 from debug import Debug as Debug
 from preferences import globalSettings as UserSettings
 
@@ -1635,9 +1635,7 @@
             return False
         else:
             # dialog to get file name
-            # dlg = wx.TextEntryDialog(parent=self, caption=_('Extract selected'),
-            #                         message=_('Name of new vector map layer'))
-            dlg = NewVectorDialog(parent=self, id=wx.ID_ANY, title=_('Extract selected'))
+            dlg = gdialogs.NewVectorDialog(parent=self, id=wx.ID_ANY, title=_('Extract selected'))
 
             if dlg.ShowModal() == wx.ID_OK:
                 outmap, overwrite = dlg.GetName()
@@ -1653,7 +1651,7 @@
                 if overwrite is True:
                     cmd.append('--overwrite')
                     
-                p = gcmd.Command(cmd)
+                p = gcmd.Command(cmd, stderr=None)
         
                 if p.returncode == 0:
                     return True
@@ -3274,73 +3272,6 @@
                              
         return valueList
 
-class NewVectorDialog(wx.Dialog):
-    """Create new vector map layer"""
-    def __init__(self, parent, id, title, 
-                style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
-
-        wx.Dialog.__init__(self, parent, id, title, style=style)
-
-        self.panel = wx.Panel(parent=self, id=wx.ID_ANY)
-
-        self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
-        self.btnOK = wx.Button(self.panel, wx.ID_OK)
-        self.btnOK.SetDefault()
-        self.btnOK.Enable(False)
-
-        self.label = wx.StaticText(parent=self.panel, id=wx.ID_ANY,
-                                   label=_("Name for new vector map:"))
-        self.mapName = wx.TextCtrl(parent=self.panel, id=wx.ID_ANY,
-                                   value='', size=(250, -1),
-                                   style=wx.TE_PROCESS_ENTER)
-        self.mapName.Bind(wx.EVT_TEXT, self.OnMapName)
-
-        # TODO remove (see Preferences dialog)
-        self.overwrite = wx.CheckBox(parent=self.panel, id=wx.ID_ANY,
-                                     label=_("Allow output files to overwrite existing files"))
-
-        self.__Layout()
-
-        self.SetMinSize(self.GetSize())
-
-    def OnMapName(self, event):
-        """Name for vector map layer given"""
-        if len(event.GetString()) > 0:
-            self.btnOK.Enable(True)
-        else:
-            self.btnOK.Enable(False)
-
-    def __Layout(self):
-        """Do layout"""
-        sizer = wx.BoxSizer(wx.VERTICAL)
-
-        dataSizer = wx.BoxSizer(wx.VERTICAL)
-        dataSizer.Add(self.label, proportion=0,
-                      flag=wx.ALL, border=1)
-        dataSizer.Add(self.mapName, proportion=0,
-                      flag=wx.EXPAND | wx.ALL, border=1)
-        dataSizer.Add(self.overwrite, proportion=0,
-                      flag=wx.ALL, border=1)
-
-        # buttons
-        btnSizer = wx.StdDialogButtonSizer()
-        btnSizer.AddButton(self.btnCancel)
-        btnSizer.AddButton(self.btnOK)
-        btnSizer.Realize()
-
-        sizer.Add(item=dataSizer, proportion=1,
-                  flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
-
-        sizer.Add(item=btnSizer, proportion=0,
-                  flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
-       
-        self.panel.SetSizer(sizer)
-        sizer.Fit(self)
-
-    def GetName(self):
-        """Return (mapName, overwrite)"""
-        return (self.mapName.GetValue(), self.overwrite.IsChecked())
-
 def main(argv=None):
     if argv is None:
         argv = sys.argv

Added: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py	                        (rev 0)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2008-03-20 23:39:11 UTC (rev 30664)
@@ -0,0 +1,119 @@
+"""
+ at package gdialogs.py
+
+ at brief Common dialog used in wxGUI.
+
+List of classes:
+ - NewVectorDialog
+
+(C) 2008 by the GRASS Development Team
+
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author Martin Landa <landa.martin gmail.com>
+"""
+
+import wx
+
+import gcmd
+import grassenv
+from preferences import globalSettings as UserSettings
+
+class NewVectorDialog(wx.Dialog):
+    """Create new vector map layer"""
+    def __init__(self, parent, id, title, 
+                style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
+
+        wx.Dialog.__init__(self, parent, id, title, style=style)
+
+        self.panel = wx.Panel(parent=self, id=wx.ID_ANY)
+
+        self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
+        self.btnOK = wx.Button(self.panel, wx.ID_OK)
+        self.btnOK.SetDefault()
+        self.btnOK.Enable(False)
+
+        self.label = wx.StaticText(parent=self.panel, id=wx.ID_ANY,
+                                   label=_("Name for new vector map:"))
+        self.mapName = wx.TextCtrl(parent=self.panel, id=wx.ID_ANY,
+                                   value='', size=(250, -1),
+                                   style=wx.TE_PROCESS_ENTER)
+        self.mapName.Bind(wx.EVT_TEXT, self.OnMapName)
+
+        # TODO remove (see Preferences dialog)
+        self.overwrite = wx.CheckBox(parent=self.panel, id=wx.ID_ANY,
+                                     label=_("Allow output files to overwrite existing files"))
+        self.overwrite.SetValue(UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'))
+
+        self.__Layout()
+
+        self.SetMinSize(self.GetSize())
+
+    def OnMapName(self, event):
+        """Name for vector map layer given"""
+        if len(event.GetString()) > 0:
+            self.btnOK.Enable(True)
+        else:
+            self.btnOK.Enable(False)
+
+    def __Layout(self):
+        """Do layout"""
+        sizer = wx.BoxSizer(wx.VERTICAL)
+
+        dataSizer = wx.BoxSizer(wx.VERTICAL)
+        dataSizer.Add(self.label, proportion=0,
+                      flag=wx.ALL, border=1)
+        dataSizer.Add(self.mapName, proportion=0,
+                      flag=wx.EXPAND | wx.ALL, border=1)
+        dataSizer.Add(self.overwrite, proportion=0,
+                      flag=wx.ALL, border=1)
+
+        # buttons
+        btnSizer = wx.StdDialogButtonSizer()
+        btnSizer.AddButton(self.btnCancel)
+        btnSizer.AddButton(self.btnOK)
+        btnSizer.Realize()
+
+        sizer.Add(item=dataSizer, proportion=1,
+                  flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
+
+        sizer.Add(item=btnSizer, proportion=0,
+                  flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
+       
+        self.panel.SetSizer(sizer)
+        sizer.Fit(self)
+
+    def GetName(self):
+        """Return (mapName, overwrite)"""
+        return (self.mapName.GetValue() + '@' + grassenv.GetGRASSVariable('MAPSET'),
+                self.overwrite.IsChecked())
+
+
+def CreateNewVector(parent, title=_('Create new vector map')):
+    """Create new vector map layer
+
+    @return name of create vector map
+    @return None of failure
+    """
+    dlg = NewVectorDialog(parent=parent, id=wx.ID_ANY, title=title)
+    if dlg.ShowModal() == wx.ID_OK:
+        outmap, overwrite = dlg.GetName()
+        
+        if outmap == '': # should not happen
+            return False
+        
+        cmd = ["v.edit",
+               "map=%s" % outmap,
+               "tool=create"]
+                
+        if overwrite is True:
+            cmd.append('--overwrite')
+            
+        p = gcmd.Command(cmd)
+            
+    if p.returncode == 0:
+        return outmap
+
+    return None

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-03-20 22:58:23 UTC (rev 30663)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-03-20 23:39:11 UTC (rev 30664)
@@ -2323,7 +2323,7 @@
                               CloseButton(False).Layer(2))
 
         elif name == "digit":
-            self.digittoolbar = toolbars.DigitToolbar(self, self.Map)
+            self.digittoolbar = toolbars.DigitToolbar(self, self.Map, self.tree)
 
             for toolRow in range(0, self.digittoolbar.numOfRows):
                 self._mgr.AddPane(self.digittoolbar.toolbar[toolRow],

Modified: grass/trunk/gui/wxpython/gui_modules/menudata.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menudata.py	2008-03-20 22:58:23 UTC (rev 30663)
+++ grass/trunk/gui/wxpython/gui_modules/menudata.py	2008-03-20 23:39:11 UTC (rev 30664)
@@ -976,8 +976,8 @@
                         (_("Develop vector map"), (
                                 (_("Create new vector map"),
                                  _("Create new empty vector map"),
-                                 "self.OnMenuCmd",
-                                 "v.edit tool=create"),
+                                 "self.OnNewVector",
+                                 ""),
                                 #                                 (_("Digitize vector map"),
                                 #                                  _("Digitize/edit vector map"),
                                 #                                  "self.OnMenuCmd",

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-03-20 22:58:23 UTC (rev 30663)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-03-20 23:39:11 UTC (rev 30664)
@@ -24,6 +24,7 @@
 import gcmd
 import grassenv
 import digit
+import gdialogs
 from digit import DigitSettingsDialog as DigitSettingsDialog
 from debug import Debug as Debug
 from icon import Icons as Icons
@@ -237,9 +238,10 @@
     Toolbar for digitization
     """
 
-    def __init__(self, parent, map):
-        self.mapcontent    = map    # Map class instance
-        self.parent        = parent # MapFrame
+    def __init__(self, parent, map, layerTree=None):
+        self.mapcontent    = map       # Map class instance
+        self.parent        = parent    # MapFrame
+        self.layerTree     = layerTree # reference to layer tree associated to map display
 
         # selected map to digitize
         self.layerSelectedID  = None
@@ -612,15 +614,32 @@
         firstly terminated. The map layer is closed. After this the
         selected map layer activated for editing.
         """
+        if event.GetSelection() == 0: # create new vector map layer
+            mapName = gdialogs.CreateNewVector(self.parent)
+            if mapName:
+                # add layer to map layer tree
+                if self.layerTree:
+                    self.layerTree.AddLayer(ltype='vector',
+                                            lname=mapName,
+                                            lchecked=True,
+                                            lopacity=1.0,
+                                            lcmd=['d.vect', 'map=%s' % mapName])
+                    
+                    vectLayers = self.UpdateListOfLayers(updateTool=True)
+                    selection = vectLayers.index(mapName)
+                else:
+                    pass # TODO (no Layer Manager)
+        else:
+            selection = event.GetSelection() - 1 # first option is 'New vector map'
 
-        if self.layerSelectedID == event.GetSelection():
+        if self.layerSelectedID == selection:
             return False
 
         if self.layerSelectedID != None: # deactive map layer for editing
             self.StopEditing(self.layers[self.layerSelectedID])
 
         # select the given map layer for editing
-        self.layerSelectedID = event.GetSelection()
+        self.layerSelectedID = selection
         self.StartEditing(self.layers[self.layerSelectedID])
 
         event.Skip()
@@ -740,12 +759,12 @@
 
             if not self.comboid:
                 self.combo = wx.ComboBox(self.toolbar[self.numOfRows-1], id=wx.ID_ANY, value=value,
-                                         choices=layerNameList, size=(105, -1),
+                                         choices=[_('New vector map'), ] + layerNameList, size=(105, -1),
                                          style=wx.CB_READONLY)
                 self.comboid = self.toolbar[self.numOfRows-1].InsertControl(0, self.combo)
                 self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
             else:
-                self.combo.SetItems(layerNameList)
+                self.combo.SetItems([_('New vector map'), ] + layerNameList)
             
             # update layer index
             try:

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2008-03-20 22:58:23 UTC (rev 30663)
+++ grass/trunk/gui/wxpython/wxgui.py	2008-03-20 23:39:11 UTC (rev 30664)
@@ -84,6 +84,7 @@
 import gui_modules.dbm as dbm
 import gui_modules.workspace as workspace
 import gui_modules.goutput as goutput
+import gui_modules.gdialogs as gdialogs
 from   gui_modules.debug import Debug as Debug
 from   icons.icon import Icons as Icons
 
@@ -433,6 +434,10 @@
         cmd = self.GetMenuCmd(event)
         menuform.GUI().ParseCommand(cmd, parentframe=self)
 
+    def OnNewVector(self, event):
+        """Create new vector map layer"""
+        gdialogs.CreateNewVector(self)
+            
     def OnAboutGRASS(self, event):
         """Display 'About GRASS' dialog"""
         info = wx.AboutDialogInfo()



More information about the grass-commit mailing list