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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Aug 1 11:16:57 EDT 2011


Author: martinl
Date: 2011-08-01 08:16:57 -0700 (Mon, 01 Aug 2011)
New Revision: 47336

Modified:
   grass/trunk/gui/wxpython/gui_modules/dbm.py
   grass/trunk/gui/wxpython/gui_modules/gdialogs.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI: launch ATM when creating new vector map


Modified: grass/trunk/gui/wxpython/gui_modules/dbm.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/dbm.py	2011-08-01 12:05:37 UTC (rev 47335)
+++ grass/trunk/gui/wxpython/gui_modules/dbm.py	2011-08-01 15:16:57 UTC (rev 47336)
@@ -51,10 +51,10 @@
 import utils
 import gdialogs
 import dbm_base
-from debug import Debug
+from debug       import Debug
 from dbm_dialogs import ModifyTableRecord
 from preferences import globalSettings as UserSettings
-
+from menuform    import GNotebook
 class Log:
     """
     The log output is redirected to the status bar of the containing frame.
@@ -526,13 +526,20 @@
         return True
     
 class AttributeManager(wx.Frame):
-    """
-    GRASS Attribute manager main window
-    """
-    def __init__(self, parent, id=wx.ID_ANY,
-                 size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE,
-                 title=None, vectorName=None, item=None, log=None):
+    def __init__(self, parent, id = wx.ID_ANY,
+                 title = None, vectorName = None, item = None, log = None,
+                 selection = None, **kwargs):
+        """!GRASS Attribute Table Manager window
 
+        @param parent parent window
+        @parem id window id
+        @param title window title or None for default title
+        @param vetorName name of vector map
+        @param item item from Layer Tree
+        @param log log window
+        @param selection name of page to be selected
+        @param kwagrs other wx.Frame's arguments
+        """
         self.vectorName = vectorName
         self.parent     = parent # GMFrame
         self.treeItem   = item   # item in layer tree
@@ -549,9 +556,9 @@
         else:
             self.editable = False
         
-        self.cmdLog     = log    # self.parent.goutput
+        self.cmdLog = log    # self.parent.goutput
         
-        wx.Frame.__init__(self, parent, id, style=style)
+        wx.Frame.__init__(self, parent, id, *kwargs)
 
         # title
         if not title:
@@ -604,22 +611,7 @@
         ### {layer: list, widgets...}
         self.layerPage = {}
 
-        # auinotebook (browse, manage, settings)
-        #self.notebook = wx.aui.AuiNotebook(parent=self, id=wx.ID_ANY,
-        #                                   style=wx.aui.AUI_NB_BOTTOM)
-        # really needed (ML)
-        # self.notebook.SetFont(wx.Font(10, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.NORMAL, 0, ''))
-
-        if globalvar.hasAgw:
-            self.notebook = FN.FlatNotebook(parent = self.panel, id = wx.ID_ANY,
-                                            agwStyle = FN.FNB_BOTTOM |
-                                            FN.FNB_NO_NAV_BUTTONS |
-                                            FN.FNB_FANCY_TABS | FN.FNB_NO_X_BUTTON)
-        else:
-            self.notebook = FN.FlatNotebook(parent = self.panel, id = wx.ID_ANY,
-                                            style = FN.FNB_BOTTOM |
-                                            FN.FNB_NO_NAV_BUTTONS |
-                                            FN.FNB_FANCY_TABS | FN.FNB_NO_X_BUTTON)
+        self.notebook = GNotebook(self.panel, style = globalvar.FNPageDStyle)
         
         if globalvar.hasAgw:
             dbmStyle = { 'agwStyle' : globalvar.FNPageStyle }
@@ -628,22 +620,22 @@
         
         self.browsePage = FN.FlatNotebook(self.panel, id = wx.ID_ANY,
                                           **dbmStyle)
-        # self.notebook.AddPage(self.browsePage, caption=_("Browse data"))
-        self.notebook.AddPage(self.browsePage, text=_("Browse data")) # FN
+        self.notebook.AddPage(page = self.browsePage, text = _("Browse data"),
+                              name = 'browse')
         self.browsePage.SetTabAreaColour(globalvar.FNPageColor)
 
         self.manageTablePage = FN.FlatNotebook(self.panel, id = wx.ID_ANY,
                                                **dbmStyle)
-        #self.notebook.AddPage(self.manageTablePage, caption=_("Manage tables"))
-        self.notebook.AddPage(self.manageTablePage, text=_("Manage tables")) # FN
+        self.notebook.AddPage(page = self.manageTablePage, text = _("Manage tables"),
+                              name = 'table')
         if not self.editable:
             self.notebook.GetPage(self.notebook.GetPageCount()-1).Enable(False)
         self.manageTablePage.SetTabAreaColour(globalvar.FNPageColor)
 
         self.manageLayerPage = FN.FlatNotebook(self.panel, id = wx.ID_ANY,
                                                **dbmStyle)
-        #self.notebook.AddPage(self.manageLayerPage, caption=_("Manage layers"))
-        self.notebook.AddPage(self.manageLayerPage, text=_("Manage layers")) # FN
+        self.notebook.AddPage(page = self.manageLayerPage, text = _("Manage layers"),
+                              name = 'layers')
         self.manageLayerPage.SetTabAreaColour(globalvar.FNPageColor)
         if not self.editable:
             self.notebook.GetPage(self.notebook.GetPageCount()-1).Enable(False)
@@ -652,11 +644,10 @@
         self.__createManageTablePage()
         self.__createManageLayerPage()
 
-        self.notebook.SetSelection(0) # select browse tab
+        if selection:
+            wx.CallAfter(self.notebook.SetSelectionByName, selection) # select browse tab
 
-        #
         # buttons
-        #
         self.btnQuit   = wx.Button(parent=self.panel, id=wx.ID_EXIT)
         self.btnQuit.SetToolTipString(_("Close Attribute Table Manager"))
         self.btnReload = wx.Button(parent=self.panel, id=wx.ID_REFRESH)
@@ -2049,8 +2040,7 @@
         event.Skip()
 
     def OnExtractSelected(self, event):
-        """!
-        Extract vector objects selected in attribute browse window
+        """!Extract vector objects selected in attribute browse window
         to new vector map
         """
         list = self.FindWindowById(self.layerPage[self.layer]['data'])
@@ -2063,24 +2053,26 @@
             return
         else:
             # dialog to get file name
-            name, add = gdialogs.CreateNewVector(parent = self, title = _('Extract selected features'),
-                                                 log = self.cmdLog,
-                                                 cmd = (('v.extract',
-                                                         { 'input' : self.vectorName,
-                                                           'list' : utils.ListOfCatsToRange(cats) },
-                                                         'output')),
-                                                 disableTable = True)
-            if name and add:
+            dlg = gdialogs.CreateNewVector(parent = self, title = _('Extract selected features'),
+                                           log = self.cmdLog,
+                                           cmd = (('v.extract',
+                                                   { 'input' : self.vectorName,
+                                                     'list' : utils.ListOfCatsToRange(cats) },
+                                                   'output')),
+                                           disableTable = True)
+            if not dlg:
+                return
+            
+            if dlg.GetName() and dlg.IsChecked('add'):
+                name = dlg.GetName() + '@' + grass.gisenv()['MAPSET']
                 # add layer to map layer tree
-                self.parent.curr_page.maptree.AddLayer(ltype='vector',
-                                                       lname=name,
-                                                       lchecked=True,
-                                                       lopacity=1.0,
-                                                       lcmd=['d.vect', 'map=%s' % name])
+                self.parent.curr_page.maptree.AddLayer(ltype = 'vector',
+                                                       lname = name,
+                                                       lcmd = ['d.vect', 'map=%s' % name])
+            dlg.Destroy()
             
     def OnDeleteSelected(self, event):
-        """
-        Delete vector objects selected in attribute browse window
+        """!Delete vector objects selected in attribute browse window
         (attribures and geometry)
         """
         list = self.FindWindowById(self.layerPage[self.layer]['data'])
@@ -2128,9 +2120,7 @@
     
     def UpdateDialog(self, layer):
         """!Updates dialog layout for given layer"""
-        #
         # delete page
-        #
         if layer in self.mapDBInfo.layers.keys():
             # delete page
             # draging pages disallowed
@@ -2140,7 +2130,7 @@
             self.browsePage.DeletePage(self.mapDBInfo.layers.keys().index(layer))
             self.manageTablePage.DeletePage(self.mapDBInfo.layers.keys().index(layer))
             # set current page selection
-            self.notebook.SetSelection(2)
+            self.notebook.SetSelectionByName('layers')
             
         # fetch fresh db info
         self.mapDBInfo = dbm_base.VectorDBInfo(self.vectorName)    
@@ -2154,7 +2144,7 @@
             # 'manage tables' page
             self.__createManageTablePage(layer)
             # set current page selection
-            self.notebook.SetSelection(2)
+            self.notebook.SetSelectionByName('layers')
             
         #
         # 'manage layers' page

Modified: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2011-08-01 12:05:37 UTC (rev 47335)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2011-08-01 15:16:57 UTC (rev 47336)
@@ -216,14 +216,25 @@
         return self.GetElement()
     
 class NewVectorDialog(ElementDialog):
-    """!Dialog for creating new vector map"""
-    def __init__(self, parent, id, title, disableAdd=False, disableTable=False,
-                 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
+    def __init__(self, parent, id = wx.ID_ANY, title = _('Create new vector map'),
+                 disableAdd = False, disableTable = False,
+                 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, *kwargs):
+        """!Dialog for creating new vector map
+
+        @param parent parent window
+        @param id window id
+        @param title window title
+        @param disableAdd disable 'add layer' checkbox
+        @param disableTable disable 'create table' checkbox
+        @param style window style
+        @param kwargs other argumentes for ElementDialog
         
+        @return dialog instance       
+        """
         ElementDialog.__init__(self, parent, title, label = _("Name for new vector map:"))
         
-        self.element = gselect.Select(parent=self.panel, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE,
-                                      type='vector', mapsets=[grass.gisenv()['MAPSET'],])
+        self.element = gselect.Select(parent = self.panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
+                                      type = 'vector', mapsets = [grass.gisenv()['MAPSET'],])
         
         self.table = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
                                  label = _("Create attribute table"))
@@ -241,55 +252,76 @@
         
         self.PostInit()
         
-        self.__Layout()
+        self._layout()
         self.SetMinSize(self.GetSize())
         
     def OnMapName(self, event):
         """!Name for vector map layer given"""
         self.OnElement(event)
         
-    def __Layout(self):
+    def _layout(self):
         """!Do layout"""
-        self.dataSizer.Add(self.element, proportion=0,
-                      flag=wx.EXPAND | wx.ALL, border=1)
+        self.dataSizer.Add(self.element, proportion = 0,
+                      flag = wx.EXPAND | wx.ALL, border = 1)
         
-        self.dataSizer.Add(self.table, proportion=0,
-                      flag=wx.EXPAND | wx.ALL, border=1)
+        self.dataSizer.Add(self.table, proportion = 0,
+                      flag = wx.EXPAND | wx.ALL, border = 1)
         
         self.dataSizer.AddSpacer(5)
         
-        self.dataSizer.Add(item=self.addbox, proportion=0,
-                      flag=wx.EXPAND | wx.ALL, border=1)
+        self.dataSizer.Add(item = self.addbox, proportion = 0,
+                      flag = wx.EXPAND | wx.ALL, border = 1)
         
         self.panel.SetSizer(self.sizer)
         self.sizer.Fit(self)
 
     def GetName(self):
-        """!Return (mapName, overwrite)"""
+        """!Get name of vector map to be created"""
         return self.GetElement().split('@', 1)[0]
-            
-def CreateNewVector(parent, cmd, title=_('Create new vector map'),
-                    exceptMap=None, log=None, disableAdd=False, disableTable=False):
+
+    def IsChecked(self, key):
+        """!Get dialog properties
+
+        @param key window key ('add', 'table')
+
+        @return True/False
+        @return None on error
+        """
+        if key == 'add':
+            return self.addbox.IsChecked()
+        elif key == 'table':
+            return self.table.IsChecked()
+        
+        return None
+    
+def CreateNewVector(parent, cmd, title = _('Create new vector map'),
+                    exceptMap = None, log = None, disableAdd = False, disableTable = False):
     """!Create new vector map layer
+    
+    @param cmd (prog, **kwargs)
+    @param title window title
+    @param exceptMap list of maps to be excepted
+    @param log
+    @param disableAdd disable 'add layer' checkbox
+    @param disableTable disable 'create table' checkbox
 
-    @cmd cmd (prog, **kwargs)
+    @return dialog instance
+    @return None on error
+    """
+    dlg = NewVectorDialog(parent, title = title,
+                          disableAdd = disableAdd, disableTable = disableTable)
     
-    @return tuple (name of create vector map, add to layer tree)
-    @return None of failure
-    """
-    dlg = NewVectorDialog(parent, wx.ID_ANY, title,
-                          disableAdd, disableTable)
     if dlg.ShowModal() == wx.ID_OK:
         outmap = dlg.GetName()
         if outmap == exceptMap:
-            wx.MessageBox(parent=parent,
-                          message=_("Unable to create vector map <%s>.") % outmap,
-                          caption=_("Error"),
-                          style=wx.ID_OK | wx.ICON_ERROR | wx.CENTRE)
-            return (None, None)
+            gcmd.GError(parent = parent,
+                        message = _("Unable to create vector map <%s>.") % outmap)
+            dlg.Destroy()
+            return None
         
         if outmap == '': # should not happen
-            return (None, None)
+            dlg.Destroy()
+            return None
         
         cmd[1][cmd[2]] = outmap
         
@@ -299,20 +331,21 @@
             listOfVectors = []
         
         overwrite = False
-        if not UserSettings.Get(group='cmd', key='overwrite', subkey='enabled') and \
+        if not UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled') and \
                 outmap in listOfVectors:
-            dlgOw = wx.MessageDialog(parent, message=_("Vector map <%s> already exists "
-                                                       "in the current mapset. "
-                                                       "Do you want to overwrite it?") % outmap,
-                                     caption=_("Overwrite?"),
-                                     style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
+            dlgOw = wx.MessageDialog(parent, message = _("Vector map <%s> already exists "
+                                                         "in the current mapset. "
+                                                         "Do you want to overwrite it?") % outmap,
+                                     caption = _("Overwrite?"),
+                                     style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
             if dlgOw.ShowModal() == wx.ID_YES:
                 overwrite = True
             else:
                 dlgOw.Destroy()
-                return (None, None)
-
-        if UserSettings.Get(group='cmd', key='overwrite', subkey='enabled') is True:
+                dlg.Destroy()
+                return None
+        
+        if UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'):
             overwrite = True
         
         try:
@@ -322,13 +355,12 @@
         except gcmd.GException, e:
             gcmd.GError(parent = self,
                         message = e.value)
-            return (None, None)
+            dlg.Destroy()
+            return None
         
-        #
         # create attribute table
-        #
         if dlg.table.IsEnabled() and dlg.table.IsChecked():
-            key = UserSettings.Get(group='atm', key='keycolumn', subkey='value')
+            key = UserSettings.Get(group = 'atm', key = 'keycolumn', subkey = 'value')
             sql = 'CREATE TABLE %s (%s INTEGER)' % (outmap, key)
             
             gcmd.RunCommand('db.connect',
@@ -347,17 +379,17 @@
                             table = outmap,
                             key = key,
                             layer = '1')
-            
+        
         # return fully qualified map name
         if '@' not in outmap:
             outmap += '@' + grass.gisenv()['MAPSET']
-
+        
         if log:
             log.WriteLog(_("New vector map <%s> created") % outmap)
 
-        return (outmap, dlg.addbox.IsChecked())
+        return dlg
     
-    return (None, dlg.addbox.IsChecked())
+    return dlg
 
 class SavedRegion(wx.Dialog):
     def __init__(self, parent, id = wx.ID_ANY, title="", loadsave='load',

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-08-01 12:05:37 UTC (rev 47335)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-08-01 15:16:57 UTC (rev 47336)
@@ -966,34 +966,41 @@
                 openVectorMap = self.mapLayer.GetName(fullyQualified = False)['name']
             else:
                 openVectorMap = None
-            mapName = gdialogs.CreateNewVector(self.parent,
-                                               exceptMap = openVectorMap, log = self.log,
-                                               cmd = (('v.edit',
-                                                       { 'tool' : 'create' },
-                                                       'map')),
-                                               disableAdd = True)[0]
-            if mapName:
+            dlg = gdialogs.CreateNewVector(self.parent,
+                                           exceptMap = openVectorMap, log = self.log,
+                                           cmd = (('v.edit',
+                                                   { 'tool' : 'create' },
+                                                   'map')),
+                                           disableAdd = True)
+            
+            if dlg and dlg.GetName():
                 # add layer to map layer tree
                 if self.layerTree:
+                    mapName = dlg.GetName() + '@' + grass.gisenv()['MAPSET']
                     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)
+                
+                # create table ?
+                if dlg.IsChecked('table'):
+                    lmgr = self.parent.GetLayerManager()
+                    if lmgr:
+                        lmgr.OnShowAttributeTable(None, selection = 'table')
+                dlg.Destroy()
             else:
                 self.combo.SetValue(_('Select vector map'))
-                return 
+                if dlg:
+                    dlg.Destroy()
+                return
         else:
             selection = event.GetSelection() - 1 # first option is 'New vector map'
         
         # skip currently selected map
         if self.layers[selection] == self.mapLayer:
-            return False
+            return
         
         if self.mapLayer:
             # deactive map layer for editing
@@ -1003,9 +1010,7 @@
         self.StartEditing(self.layers[selection])
         
         event.Skip()
-
-        return True
-    
+        
     def StartEditing (self, mapLayer):
         """!Start editing selected vector map layer.
 
@@ -1127,7 +1132,7 @@
         Update list of available vector map layers.
         This list consists only editable layers (in the current mapset)
 
-        Optionally also update toolbar
+        @param updateTool True to update also toolbar
         """
         Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
                    updateTool)
@@ -1141,6 +1146,7 @@
         layerNameList = []
         self.layers = self.mapcontent.GetListOfLayers(l_type = "vector",
                                                       l_mapset = grass.gisenv()['MAPSET'])
+        
         for layer in self.layers:
             if not layer.name in layerNameList: # do not duplicate layer
                 layerNameList.append (layer.GetName())

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2011-08-01 12:05:37 UTC (rev 47335)
+++ grass/trunk/gui/wxpython/wxgui.py	2011-08-01 15:16:57 UTC (rev 47336)
@@ -1189,7 +1189,7 @@
                 
         dlg.Destroy()
         
-    def OnShowAttributeTable(self, event):
+    def OnShowAttributeTable(self, event, selection = None):
         """!Show attribute table of the given vector map layer
         """
         if not self.curr_page:
@@ -1226,7 +1226,8 @@
         
         dbmanager = dbm.AttributeManager(parent = self, id = wx.ID_ANY,
                                          size = wx.Size(500, 300),
-                                         item = layer, log = self.goutput)
+                                         item = layer, log = self.goutput,
+                                         selection = selection)
         
         busy.Destroy()
         



More information about the grass-commit mailing list