[GRASS-SVN] r41529 - grass-addons/gui/wxpython/data_catalog
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Mar 23 08:56:35 EDT 2010
Author: rashadkm
Date: 2010-03-23 08:56:28 -0400 (Tue, 23 Mar 2010)
New Revision: 41529
Added:
grass-addons/gui/wxpython/data_catalog/right.py
grass-addons/gui/wxpython/data_catalog/toolbars.py
grass-addons/gui/wxpython/data_catalog/wxgui.py
Modified:
grass-addons/gui/wxpython/data_catalog/catalog.py
Log:
minor updates only;
Modified: grass-addons/gui/wxpython/data_catalog/catalog.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/catalog.py 2010-03-22 18:49:44 UTC (rev 41528)
+++ grass-addons/gui/wxpython/data_catalog/catalog.py 2010-03-23 12:56:28 UTC (rev 41529)
@@ -365,15 +365,69 @@
self.Bind(wx.EVT_MENU, rhandler, menuItem)
- def OnXTerm(self):
- print "asdf1"
- def OnRunScript(self):
- print "asdf2"
- def OnQuit(self):
- print "asdf3"
+
+ def OnXTermNoXMon(self, event):
+ """!
+ Run commands that need xterm
+ """
+ self.OnXTerm(event, need_xmon = False)
+
+ def OnXTerm(self, event, need_xmon = True):
+ """!
+ Run commands that need interactive xmon
+
+ @param need_xmon True to start X monitor
+ """
+ # unset display mode
+ del os.environ['GRASS_RENDER_IMMEDIATE']
+
+ if need_xmon:
+ # open next available xmon
+ xmonlist = []
+
+ # make list of xmons that are not running
+ ret = gcmd.RunCommand('d.mon',
+ flags = 'L',
+ read = True)
+
+ for line in ret.split('\n'):
+ line = line.strip()
+ if line.startswith('x') and 'not running' in line:
+ xmonlist.append(line[0:2])
+
+ # find available xmon
+ xmon = xmonlist[0]
+
+ # bring up the xmon
+ cmdlist = ['d.mon', xmon]
+ p = gcmd.Command(cmdlist, wait=False)
+
+ # run the command
+ command = self.GetMenuCmd(event)
+ command = ' '.join(command)
+
+ gisbase = os.environ['GISBASE']
+
+ if sys.platform == "win32":
+ runbat = os.path.join(gisbase,'etc','grass-run.bat')
+ cmdlist = ["start", runbat, runbat, command]
+ else:
+ if sys.platform == "darwin":
+ xtermwrapper = os.path.join(gisbase,'etc','grass-xterm-mac')
+ else:
+ xtermwrapper = os.path.join(gisbase,'etc','grass-xterm-wrapper')
+
+ grassrun = os.path.join(gisbase,'etc','grass-run.sh')
+ cmdlist = [xtermwrapper, '-e', grassrun, command]
+
+ p = gcmd.Command(cmdlist, wait=False)
+
+ # reset display mode
+ os.environ['GRASS_RENDER_IMMEDIATE'] = 'TRUE'
+
def OnRunCmd(self, event):
"""Run command"""
cmdString = event.GetString()
Added: grass-addons/gui/wxpython/data_catalog/right.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/right.py (rev 0)
+++ grass-addons/gui/wxpython/data_catalog/right.py 2010-03-23 12:56:28 UTC (rev 41529)
@@ -0,0 +1,39 @@
+import wx
+import wx_utils as wx_utils
+
+class RightTree(wx.TreeCtrl):
+
+ def __init__(self, parent, id,
+ pos = wx.DefaultPosition,
+ size = wx.DefaultSize,
+ style= wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS):
+
+ wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
+ self.itemFont2 = wx.Font(pointSize=9,weight=0, family=wx.FONTFAMILY_DEFAULT ,style=wx.FONTSTYLE_ITALIC)
+
+
+ def PopulateDisplay(self):
+ root1 = self.AddRoot('root')
+ node_raster2 = self.AppendItem(root1, "Display 0")
+ node_vector2 = self.AppendItem(root1, "Display 1")
+ node_dbf2 = self.AppendItem(root1, "Display 2")
+ treeNodes2 = [node_raster2,node_vector2,node_dbf2]
+ #Nodes with no children are given an italic type font
+ for node in treeNodes2:
+ if not self.ItemHasChildren(node):
+ if self.GetItemText(node) == 'Display 0':
+ tmp_item2 = self.AppendItem(node, "No raster maps found.")
+ elif self.GetItemText(node) == 'Display 1':
+ tmp_item2 = self.AppendItem(node, "No vector maps found.")
+ elif self.GetItemText(node) == 'Display 2':
+ tmp_item2 = self.AppendItem(node, "No DBF files found.")
+ self.SetItemFont(tmp_item2,self.itemFont2)
+
+ #self.pg_panel = wx.Panel(self.gm_cb, id=wx.ID_ANY, style= wx.EXPAND)
+ #self.gm_cb.AddPage(self.pg_panel, text="Display "+ str(self.disp_idx + 1), select = True)
+ #self.curr_page = self.gm_cb.GetCurrentPage()
+
+
+ # create layer tree (tree control for managing GIS layers) and put on new notebook page
+
+
Added: grass-addons/gui/wxpython/data_catalog/toolbars.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/toolbars.py (rev 0)
+++ grass-addons/gui/wxpython/data_catalog/toolbars.py 2010-03-23 12:56:28 UTC (rev 41529)
@@ -0,0 +1,1380 @@
+"""
+ at package toolbar
+
+ at brief Toolbars for Map Display window
+
+Classes:
+ - AbstractToolbar
+ - MapToolbar
+ - GRToolbar
+ - GCPToolbar
+ - VDigitToolbar
+ - ProfileToolbar
+ - NvizToolbar
+
+(C) 2007-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 Michael Barton
+ at author Jachym Cepicky
+ at author Martin Landa <landa.martin gmail.com>
+"""
+
+import wx
+import os, sys
+import platform
+
+import globalvar
+import gcmd
+version = os.getenv("GRASS_VERSION")
+if version == "6.4.0svn":
+ import grassenv
+
+import gdialogs
+import vdigit
+from vdigit import VDigitSettingsDialog as VDigitSettingsDialog
+from debug import Debug as Debug
+from icon import Icons as Icons
+from preferences import globalSettings as UserSettings
+
+gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
+sys.path.append(gmpath)
+
+class AbstractToolbar(object):
+ """Abstract toolbar class"""
+ def __init__(self):
+ pass
+
+ def InitToolbar(self, parent, toolbar, toolData):
+ """Initialize toolbar, i.e. add tools to the toolbar
+
+ @return list of ids (of added tools)
+ """
+
+ for tool in toolData:
+ self.CreateTool(parent, toolbar, *tool)
+
+ self._toolbar = toolbar
+ self._data = toolData
+
+ self.parent = parent
+
+ def ToolbarData(self):
+ """Toolbar data"""
+ return None
+
+ def CreateTool(self, parent, toolbar, tool, label, bitmap, kind,
+ shortHelp, longHelp, handler):
+ """Add tool to the toolbar
+
+ @return id of tool
+ """
+
+ bmpDisabled=wx.NullBitmap
+
+ if label:
+ Debug.msg(3, "CreateTool(): tool=%d, label=%s bitmap=%s" % \
+ (tool, label, bitmap))
+ toolWin = toolbar.AddLabelTool(tool, label, bitmap,
+ bmpDisabled, kind,
+ shortHelp, longHelp)
+ parent.Bind(wx.EVT_TOOL, handler, toolWin)
+ else: # add separator
+ toolbar.AddSeparator()
+
+ return tool
+
+ def GetToolbar(self):
+ """Get toolbar widget reference"""
+ return self._toolbar
+
+ def EnableLongHelp(self, enable=True):
+ """Enable/disable long help
+
+ @param enable True for enable otherwise disable
+ """
+ for tool in self._data:
+ if tool[0] == '': # separator
+ continue
+
+ if enable:
+ self._toolbar.SetToolLongHelp(tool[0], tool[5])
+ else:
+ self._toolbar.SetToolLongHelp(tool[0], "")
+
+ def OnTool(self, event):
+ """Tool selected"""
+ if self.parent.toolbars['vdigit']:
+ # update vdigit toolbar (unselect currently selected tool)
+ id = self.parent.toolbars['vdigit'].GetAction(type='id')
+ self.parent.toolbars['vdigit'].GetToolbar().ToggleTool(id, False)
+
+ if event:
+ # deselect previously selected tool
+ id = self.action.get('id', -1)
+ if id != event.GetId():
+ self._toolbar.ToggleTool(self.action['id'], False)
+ else:
+ self._toolbar.ToggleTool(self.action['id'], True)
+
+ self.action['id'] = event.GetId()
+
+ event.Skip()
+ else:
+ # initialize toolbar
+ self._toolbar.ToggleTool(self.action['id'], True)
+
+ def GetAction(self, type='desc'):
+ """Get current action info"""
+ return self.action.get(type, '')
+
+ def SelectDefault(self, event):
+ """Select default tool"""
+ self._toolbar.ToggleTool(self.defaultAction['id'], True)
+ self.defaultAction['bind'](event)
+ self.action = { 'id' : self.defaultAction['id'],
+ 'desc' : self.defaultAction.get('desc', '') }
+
+ def FixSize(self, width):
+ """Fix toolbar width on Windows
+
+ @todo Determine why combobox causes problems here
+ """
+ if platform.system() == 'Windows':
+ size = self._toolbar.GetBestSize()
+ self._toolbar.SetSize((size[0] + width, size[1]))
+
+class MapToolbar(AbstractToolbar):
+ """
+ Main Map Display toolbar
+ """
+
+ def __init__(self, mapdisplay, map):
+ AbstractToolbar.__init__(self)
+
+ self.mapcontent = map
+ self.mapdisplay = mapdisplay
+
+ self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
+ self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
+
+ self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
+
+ # optional tools
+ self.combo = wx.ComboBox(parent=self.toolbar, id=wx.ID_ANY, value=_('2D view'),
+ choices=[_('2D view'), _('3D view'), _('Digitize')],
+ style=wx.CB_READONLY, size=(90, -1))
+
+ self.comboid = self.toolbar.AddControl(self.combo)
+ self.mapdisplay.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
+
+ # realize the toolbar
+ self.toolbar.Realize()
+
+ # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
+ self.combo.Hide()
+ self.combo.Show()
+
+ # default action
+ self.action = { 'id' : self.pointer }
+ self.defaultAction = { 'id' : self.pointer,
+ 'bind' : self.mapdisplay.OnPointer }
+ self.OnTool(None)
+
+ self.FixSize(width = 90)
+
+ def ToolbarData(self):
+ """Toolbar data"""
+
+ self.displaymap = wx.NewId()
+ self.rendermap = wx.NewId()
+ self.erase = wx.NewId()
+ self.pointer = wx.NewId()
+ self.query = wx.NewId()
+ self.pan = wx.NewId()
+ self.zoomin = wx.NewId()
+ self.zoomout = wx.NewId()
+ self.zoomback = wx.NewId()
+ self.zoommenu = wx.NewId()
+ self.analyze = wx.NewId()
+ self.dec = wx.NewId()
+ self.savefile = wx.NewId()
+ self.printmap = wx.NewId()
+
+ # tool, label, bitmap, kind, shortHelp, longHelp, handler
+ return (
+ (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
+ self.mapdisplay.OnDraw),
+ (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
+ self.mapdisplay.OnRender),
+ (self.erase, "erase", Icons["erase"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
+ self.mapdisplay.OnErase),
+ ("", "", "", "", "", "", ""),
+ (self.pointer, "pointer", Icons["pointer"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["pointer"].GetLabel(), Icons["pointer"].GetDesc(),
+ self.mapdisplay.OnPointer),
+ (self.query, "query", Icons["query"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["query"].GetLabel(), Icons["query"].GetDesc(),
+ self.mapdisplay.OnQuery),
+ (self.pan, "pan", Icons["pan"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
+ self.mapdisplay.OnPan),
+ (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
+ self.mapdisplay.OnZoomIn),
+ (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
+ self.mapdisplay.OnZoomOut),
+ (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
+ self.mapdisplay.OnZoomBack),
+ (self.zoommenu, "zoommenu", Icons["zoommenu"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["zoommenu"].GetLabel(), Icons["zoommenu"].GetDesc(),
+ self.mapdisplay.OnZoomMenu),
+ ("", "", "", "", "", "", ""),
+ (self.analyze, "analyze", Icons["analyze"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["analyze"].GetLabel(), Icons["analyze"].GetDesc(),
+ self.mapdisplay.OnAnalyze),
+ ("", "", "", "", "", "", ""),
+ (self.dec, "overlay", Icons["overlay"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["overlay"].GetLabel(), Icons["overlay"].GetDesc(),
+ self.mapdisplay.OnDecoration),
+ ("", "", "", "", "", "", ""),
+ (self.savefile, "savefile", Icons["savefile"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
+ self.mapdisplay.SaveToFile),
+ (self.printmap, "printmap", Icons["printmap"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
+ self.mapdisplay.PrintMenu),
+ ("", "", "", "", "", "", "")
+ )
+
+ def OnSelectTool(self, event):
+ """
+ Select / enable tool available in tools list
+ """
+ tool = event.GetSelection()
+
+ if tool == 0:
+ self.ExitToolbars()
+ self.Enable2D(True)
+
+ elif tool == 1 and not self.mapdisplay.toolbars['nviz']:
+ self.ExitToolbars()
+ self.mapdisplay.AddToolbar("nviz")
+
+ elif tool == 2 and not self.mapdisplay.toolbars['vdigit']:
+ self.ExitToolbars()
+ self.mapdisplay.AddToolbar("vdigit")
+
+ def ExitToolbars(self):
+ if self.mapdisplay.toolbars['vdigit']:
+ self.mapdisplay.toolbars['vdigit'].OnExit()
+ if self.mapdisplay.toolbars['nviz']:
+ self.mapdisplay.toolbars['nviz'].OnExit()
+
+ def Enable2D(self, enabled):
+ """Enable/Disable 2D display mode specific tools"""
+ for tool in (self.pointer,
+ self.query,
+ self.pan,
+ self.zoomin,
+ self.zoomout,
+ self.zoomback,
+ self.zoommenu,
+ self.analyze,
+ self.dec,
+ self.savefile,
+ self.printmap):
+ self.toolbar.EnableTool(tool, enabled)
+
+class GRToolbar(AbstractToolbar):
+ """
+ Georectification Display toolbar
+ """
+
+ def __init__(self, mapdisplay, map):
+ self.mapcontent = map
+ self.mapdisplay = mapdisplay
+
+ self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
+
+ # self.SetToolBar(self.toolbar)
+ self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
+
+ self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
+
+ # realize the toolbar
+ self.toolbar.Realize()
+
+ def ToolbarData(self):
+ """Toolbar data"""
+
+ self.displaymap = wx.NewId()
+ self.rendermap = wx.NewId()
+ self.erase = wx.NewId()
+ self.gcpset = wx.NewId()
+ self.pan = wx.NewId()
+ self.zoomin = wx.NewId()
+ self.zoomout = wx.NewId()
+ self.zoomback = wx.NewId()
+ self.zoomtomap = wx.NewId()
+
+ # tool, label, bitmap, kind, shortHelp, longHelp, handler
+ return (
+ (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
+ self.mapdisplay.OnDraw),
+ (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
+ self.mapdisplay.OnRender),
+ (self.erase, "erase", Icons["erase"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
+ self.mapdisplay.OnErase),
+ ("", "", "", "", "", "", ""),
+ (self.gcpset, "grGcpSet", Icons["grGcpSet"].GetBitmap(),
+ wx.ITEM_RADIO, Icons["grGcpSet"].GetLabel(), Icons["grGcpSet"].GetDesc(),
+ self.mapdisplay.OnPointer),
+ (self.pan, "pan", Icons["pan"].GetBitmap(),
+ wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
+ self.mapdisplay.OnPan),
+ (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
+ wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
+ self.mapdisplay.OnZoomIn),
+ (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
+ wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
+ self.mapdisplay.OnZoomOut),
+ (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
+ self.mapdisplay.OnZoomBack),
+ (self.zoomtomap, "zoomtomap", Icons["zoommenu"].GetBitmap(),
+ wx.ITEM_NORMAL, _("Zoom to map"), _("Zoom to displayed map"),
+ self.OnZoomMap),
+ ("", "", "", "", "", "", ""),
+ )
+
+ def OnZoomMap(self, event):
+ """Zoom to selected map"""
+ layer = self.mapcontent.GetListOfLayers()[0]
+
+ self.mapdisplay.MapWindow.ZoomToMap(layer=layer)
+
+ event.Skip()
+
+class GCPToolbar(AbstractToolbar):
+ """
+ Toolbar for managing ground control points during georectification
+ """
+ def __init__(self, parent, tbframe):
+ self.parent = parent # GCP
+ self.tbframe = tbframe
+
+ self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
+
+ # self.SetToolBar(self.toolbar)
+ self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
+
+ self.InitToolbar(self.tbframe, self.toolbar, self.ToolbarData())
+
+ # realize the toolbar
+ self.toolbar.Realize()
+
+ def ToolbarData(self):
+
+ self.gcpSave = wx.NewId()
+ self.gcpAdd = wx.NewId()
+ self.gcpDelete = wx.NewId()
+ self.gcpClear = wx.NewId()
+ self.gcpReload = wx.NewId()
+ self.rms = wx.NewId()
+ self.georect = wx.NewId()
+ self.settings = wx.NewId()
+ self.quit = wx.NewId()
+
+ return (
+ (self.gcpSave, 'grGcpSave', Icons["grGcpSave"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["grGcpSave"].GetLabel(), Icons["grGcpSave"].GetDesc(),
+ self.parent.SaveGCPs),
+ (self.gcpAdd, 'grGrGcpAdd', Icons["grGcpAdd"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["grGcpAdd"].GetLabel(), Icons["grGcpAdd"].GetDesc(),
+ self.parent.AddGCP),
+ (self.gcpDelete, 'grGrGcpDelete', Icons["grGcpDelete"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["grGcpDelete"].GetLabel(), Icons["grGcpDelete"].GetDesc(),
+ self.parent.DeleteGCP),
+ (self.gcpClear, 'grGcpClear', Icons["grGcpClear"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["grGcpClear"].GetLabel(), Icons["grGcpClear"].GetDesc(),
+ self.parent.ClearGCP),
+ (self.gcpReload, 'grGcpReload', Icons["grGcpReload"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["grGcpReload"].GetLabel(), Icons["grGcpReload"].GetDesc(),
+ self.parent.ReloadGCPs),
+
+ ("", "", "", "", "", "", ""),
+ (self.rms, 'grGcpRms', Icons["grGcpRms"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["grGcpRms"].GetLabel(), Icons["grGcpRms"].GetDesc(),
+ self.parent.OnRMS),
+ (self.georect, 'grGeorect', Icons["grGeorect"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["grGeorect"].GetLabel(), Icons["grGeorect"].GetDesc(),
+ self.parent.OnGeorect),
+ ("", "", "", "", "", "", ""),
+ (self.settings, 'grSettings', Icons["grSettings"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["grSettings"].GetLabel(), Icons["grSettings"].GetDesc(),
+ self.parent.OnSettings),
+ (self.quit, 'grGcpQuit', Icons["grGcpQuit"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["grGcpQuit"].GetLabel(), Icons["grGcpQuit"].GetDesc(),
+ self.parent.OnQuit)
+ )
+
+class VDigitToolbar(AbstractToolbar):
+ """
+ Toolbar for digitization
+ """
+
+ def __init__(self, parent, map, layerTree=None, log=None):
+ self.mapcontent = map # Map class instance
+ self.parent = parent # MapFrame
+ self.layerTree = layerTree # reference to layer tree associated to map display
+ self.log = log # log area
+
+ # currently selected map layer for editing (reference to MapLayer instance)
+ self.mapLayer = None
+ # list of vector layers from Layer Manager (only in the current mapset)
+ self.layers = []
+
+ self.comboid = None
+
+ # only one dialog can be open
+ self.settingsDialog = None
+
+ # create toolbars (two rows optionally)
+ self.toolbar = []
+ self.numOfRows = 1 # number of rows for toolbar
+ for row in range(0, self.numOfRows):
+ self.toolbar.append(wx.ToolBar(parent=self.parent, id=wx.ID_ANY))
+ self.toolbar[row].SetToolBitmapSize(globalvar.toolbarSize)
+ self.toolbar[row].Bind(wx.EVT_TOOL, self.OnTool)
+
+ # create toolbar
+ if self.numOfRows == 1:
+ rowdata=None
+ else:
+ rowdata = row
+ self.InitToolbar(self.parent, self.toolbar[row], self.ToolbarData(rowdata))
+
+ # default action (digitize new point, line, etc.)
+ self.action = { 'desc' : 'addLine',
+ 'type' : 'point',
+ 'id' : self.addPoint }
+
+ # list of available vector maps
+ self.UpdateListOfLayers(updateTool=True)
+
+ # realize toolbar
+ for row in range(0, self.numOfRows):
+ self.toolbar[row].Realize()
+ # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
+ self.combo.Hide()
+ self.combo.Show()
+
+
+ # disable undo/redo
+ self.toolbar[0].EnableTool(self.undo, False)
+
+ # toogle to pointer by default
+ self.OnTool(None)
+
+ self.FixSize(width = 105)
+
+ def ToolbarData(self, row=None):
+ """
+ Toolbar data
+ """
+ data = []
+ if row is None or row == 0:
+ self.addPoint = wx.NewId()
+ self.addLine = wx.NewId()
+ self.addBoundary = wx.NewId()
+ self.addCentroid = wx.NewId()
+ self.moveVertex = wx.NewId()
+ self.addVertex = wx.NewId()
+ self.removeVertex = wx.NewId()
+ self.splitLine = wx.NewId()
+ self.editLine = wx.NewId()
+ self.moveLine = wx.NewId()
+ self.deleteLine = wx.NewId()
+ self.additionalTools = wx.NewId()
+ self.displayCats = wx.NewId()
+ self.displayAttr = wx.NewId()
+ self.copyCats = wx.NewId()
+
+ data = [("", "", "", "", "", "", ""),
+ (self.addPoint, "digAddPoint", Icons["digAddPoint"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digAddPoint"].GetLabel(), Icons["digAddPoint"].GetDesc(),
+ self.OnAddPoint),
+ (self.addLine, "digAddLine", Icons["digAddLine"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digAddLine"].GetLabel(), Icons["digAddLine"].GetDesc(),
+ self.OnAddLine),
+ (self.addBoundary, "digAddBoundary", Icons["digAddBoundary"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digAddBoundary"].GetLabel(), Icons["digAddBoundary"].GetDesc(),
+ self.OnAddBoundary),
+ (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
+ self.OnAddCentroid),
+ (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
+ self.OnMoveVertex),
+ (self.addVertex, "digAddVertex", Icons["digAddVertex"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digAddVertex"].GetLabel(), Icons["digAddVertex"].GetDesc(),
+ self.OnAddVertex),
+ (self.removeVertex, "digRemoveVertex", Icons["digRemoveVertex"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digRemoveVertex"].GetLabel(), Icons["digRemoveVertex"].GetDesc(),
+ self.OnRemoveVertex),
+ (self.splitLine, "digSplitLine", Icons["digSplitLine"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digSplitLine"].GetLabel(), Icons["digSplitLine"].GetDesc(),
+ self.OnSplitLine),
+ (self.editLine, "digEditLine", Icons["digEditLine"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digEditLine"].GetLabel(), Icons["digEditLine"].GetDesc(),
+ self.OnEditLine),
+ (self.moveLine, "digMoveLine", Icons["digMoveLine"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digMoveLine"].GetLabel(), Icons["digMoveLine"].GetDesc(),
+ self.OnMoveLine),
+ (self.deleteLine, "digDeleteLine", Icons["digDeleteLine"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digDeleteLine"].GetLabel(), Icons["digDeleteLine"].GetDesc(),
+ self.OnDeleteLine),
+ (self.displayCats, "digDispCats", Icons["digDispCats"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digDispCats"].GetLabel(), Icons["digDispCats"].GetDesc(),
+ self.OnDisplayCats),
+ (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
+ self.OnCopyCA),
+ (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
+ self.OnDisplayAttr),
+ (self.additionalTools, "digAdditionalTools", Icons["digAdditionalTools"].GetBitmap(),
+ wx.ITEM_CHECK, Icons["digAdditionalTools"].GetLabel(),
+ Icons["digAdditionalTools"].GetDesc(),
+ self.OnAdditionalToolMenu)]
+
+ if row is None or row == 1:
+ self.undo = wx.NewId()
+ self.settings = wx.NewId()
+ self.exit = wx.NewId()
+
+ data.append(("", "", "", "", "", "", ""))
+ data.append((self.undo, "digUndo", Icons["digUndo"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["digUndo"].GetLabel(), Icons["digUndo"].GetDesc(),
+ self.OnUndo))
+ # data.append((self.undo, "digRedo", Icons["digRedo"].GetBitmap(),
+ # wx.ITEM_NORMAL, Icons["digRedo"].GetLabel(), Icons["digRedo"].GetDesc(),
+ # self.OnRedo))
+ data.append((self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
+ self.OnSettings))
+ data.append((self.exit, "digExit", Icons["quit"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
+ self.OnExit))
+
+ return data
+
+ def OnTool(self, event):
+ """Tool selected -> disable selected tool in map toolbar"""
+ # update map toolbar (unselect currently selected tool)
+ id = self.parent.toolbars['map'].GetAction(type='id')
+ self.parent.toolbars['map'].toolbar.ToggleTool(id, False)
+
+ # set cursor
+ cursor = self.parent.cursors["cross"]
+ self.parent.MapWindow.SetCursor(cursor)
+
+ # pointer
+ self.parent.OnPointer(None)
+
+ if event:
+ # deselect previously selected tool
+ id = self.action.get('id', -1)
+ if id != event.GetId():
+ self.toolbar[0].ToggleTool(self.action['id'], False)
+ else:
+ self.toolbar[0].ToggleTool(self.action['id'], True)
+
+ self.action['id'] = event.GetId()
+ event.Skip()
+ else:
+ # initialize toolbar
+ self.toolbar[0].ToggleTool(self.action['id'], True)
+
+ # clear tmp canvas
+ if self.action['id'] != id:
+ self.parent.MapWindow.ClearLines(pdc=self.parent.MapWindow.pdcTmp)
+ if self.parent.digit and \
+ len(self.parent.digit.driver.GetSelected()) > 0:
+ # cancel action
+ self.parent.MapWindow.OnMiddleDown(None)
+
+ def OnAddPoint(self, event):
+ """Add point to the vector map Laier"""
+ Debug.msg (2, "VDigitToolbar.OnAddPoint()")
+ self.action = { 'desc' : "addLine",
+ 'type' : "point",
+ 'id' : self.addPoint }
+ self.parent.MapWindow.mouse['box'] = 'point'
+
+ def OnAddLine(self, event):
+ """Add line to the vector map layer"""
+ Debug.msg (2, "VDigitToolbar.OnAddLine()")
+ self.action = { 'desc' : "addLine",
+ 'type' : "line",
+ 'id' : self.addLine }
+ self.parent.MapWindow.mouse['box'] = 'line'
+ ### self.parent.MapWindow.polycoords = [] # reset temp line
+
+ def OnAddBoundary(self, event):
+ """Add boundary to the vector map layer"""
+ Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
+ if self.action['desc'] != 'addLine' or \
+ self.action['type'] != 'boundary':
+ self.parent.MapWindow.polycoords = [] # reset temp line
+ self.action = { 'desc' : "addLine",
+ 'type' : "boundary",
+ 'id' : self.addBoundary }
+ self.parent.MapWindow.mouse['box'] = 'line'
+
+ def OnAddCentroid(self, event):
+ """Add centroid to the vector map layer"""
+ Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
+ self.action = { 'desc' : "addLine",
+ 'type' : "centroid",
+ 'id' : self.addCentroid }
+ self.parent.MapWindow.mouse['box'] = 'point'
+
+ def OnExit (self, event=None):
+ """Quit digitization tool"""
+ # stop editing of the currently selected map layer
+ if self.mapLayer:
+ self.StopEditing()
+
+ # close dialogs if still open
+ if self.settingsDialog:
+ self.settingsDialog.OnCancel(None)
+
+ # disable the toolbar
+ self.parent.RemoveToolbar ("vdigit")
+
+ # set default mouse settings
+ self.parent.MapWindow.mouse['use'] = "pointer"
+ self.parent.MapWindow.mouse['box'] = "point"
+ self.parent.MapWindow.polycoords = []
+
+ def OnMoveVertex(self, event):
+ """Move line vertex"""
+ Debug.msg(2, "Digittoolbar.OnMoveVertex():")
+ self.action = { 'desc' : "moveVertex",
+ 'id' : self.moveVertex }
+ self.parent.MapWindow.mouse['box'] = 'point'
+
+ def OnAddVertex(self, event):
+ """Add line vertex"""
+ Debug.msg(2, "Digittoolbar.OnAddVertex():")
+ self.action = { 'desc' : "addVertex",
+ 'id' : self.addVertex }
+ self.parent.MapWindow.mouse['box'] = 'point'
+
+
+ def OnRemoveVertex(self, event):
+ """Remove line vertex"""
+ Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
+ self.action = { 'desc' : "removeVertex",
+ 'id' : self.removeVertex }
+ self.parent.MapWindow.mouse['box'] = 'point'
+
+
+ def OnSplitLine(self, event):
+ """Split line"""
+ Debug.msg(2, "Digittoolbar.OnSplitLine():")
+ self.action = { 'desc' : "splitLine",
+ 'id' : self.splitLine }
+ self.parent.MapWindow.mouse['box'] = 'point'
+
+ def OnEditLine(self, event):
+ """Edit line"""
+ Debug.msg(2, "Digittoolbar.OnEditLine():")
+ self.action = { 'desc' : "editLine",
+ 'id' : self.editLine }
+ self.parent.MapWindow.mouse['box'] = 'line'
+
+ def OnMoveLine(self, event):
+ """Move line"""
+ Debug.msg(2, "Digittoolbar.OnMoveLine():")
+ self.action = { 'desc' : "moveLine",
+ 'id' : self.moveLine }
+ self.parent.MapWindow.mouse['box'] = 'box'
+
+ def OnDeleteLine(self, event):
+ """Delete line"""
+ Debug.msg(2, "Digittoolbar.OnDeleteLine():")
+ self.action = { 'desc' : "deleteLine",
+ 'id' : self.deleteLine }
+ self.parent.MapWindow.mouse['box'] = 'box'
+
+ def OnDisplayCats(self, event):
+ """Display/update categories"""
+ Debug.msg(2, "Digittoolbar.OnDisplayCats():")
+ self.action = { 'desc' : "displayCats",
+ 'id' : self.displayCats }
+ self.parent.MapWindow.mouse['box'] = 'point'
+
+ def OnDisplayAttr(self, event):
+ """Display/update attributes"""
+ Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
+ self.action = { 'desc' : "displayAttrs",
+ 'id' : self.displayAttr }
+ self.parent.MapWindow.mouse['box'] = 'point'
+
+ def OnCopyCA(self, event):
+ """Copy categories/attributes menu"""
+ point = wx.GetMousePosition()
+ toolMenu = wx.Menu()
+ # Add items to the menu
+ cats = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=_('Copy categories'),
+ kind=wx.ITEM_CHECK)
+ toolMenu.AppendItem(cats)
+ self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
+ if self.action['desc'] == "copyCats":
+ cats.Check(True)
+
+ attrb = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=_('Duplicate attributes'),
+ kind=wx.ITEM_CHECK)
+ toolMenu.AppendItem(attrb)
+ self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
+ if self.action['desc'] == "copyAttrs":
+ attrb.Check(True)
+
+ # Popup the menu. If an item is selected then its handler
+ # will be called before PopupMenu returns.
+ self.parent.MapWindow.PopupMenu(toolMenu)
+ toolMenu.Destroy()
+
+ if self.action['desc'] == "addPoint":
+ self.toolbar[0].ToggleTool(self.copyCats, False)
+
+ def OnCopyCats(self, event):
+ """Copy categories"""
+ if self.action['desc'] == 'copyCats': # select previous action
+ self.toolbar[0].ToggleTool(self.addPoint, True)
+ self.toolbar[0].ToggleTool(self.copyCats, False)
+ self.OnAddPoint(event)
+ return
+
+ Debug.msg(2, "Digittoolbar.OnCopyCats():")
+ self.action = { 'desc' : "copyCats",
+ 'id' : self.copyCats }
+ self.parent.MapWindow.mouse['box'] = 'point'
+
+ def OnCopyAttrb(self, event):
+ if self.action['desc'] == 'copyAttrs': # select previous action
+ self.toolbar[0].ToggleTool(self.addPoint, True)
+ self.toolbar[0].ToggleTool(self.copyCats, False)
+ self.OnAddPoint(event)
+ return
+
+ Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
+ self.action = { 'desc' : "copyAttrs",
+ 'id' : self.copyCats }
+ self.parent.MapWindow.mouse['box'] = 'point'
+
+ def OnUndo(self, event):
+ """Undo previous changes"""
+ self.parent.digit.Undo()
+
+ event.Skip()
+
+ def EnableUndo(self, enable=True):
+ """Enable 'Undo' in toolbar
+
+ @param enable False for disable
+ """
+ if enable:
+ if self.toolbar[0].GetToolEnabled(self.undo) is False:
+ self.toolbar[0].EnableTool(self.undo, True)
+ else:
+ if self.toolbar[0].GetToolEnabled(self.undo) is True:
+ self.toolbar[0].EnableTool(self.undo, False)
+
+ def OnSettings(self, event):
+ """Show settings dialog"""
+
+ if self.parent.digit is None:
+ reload(vdigit)
+ from vdigit import Digit as Digit
+ self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
+
+ if not self.settingsDialog:
+ self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
+ style=wx.DEFAULT_DIALOG_STYLE)
+ self.settingsDialog.Show()
+
+ def OnAdditionalToolMenu(self, event):
+ """Menu for additional tools"""
+ point = wx.GetMousePosition()
+ toolMenu = wx.Menu()
+ # Add items to the menu
+ copy = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=_('Copy features from (background) vector map'),
+ kind=wx.ITEM_CHECK)
+ toolMenu.AppendItem(copy)
+ self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
+ if self.action['desc'] == "copyLine":
+ copy.Check(True)
+
+ flip = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=_('Flip selected lines/boundaries'),
+ kind=wx.ITEM_CHECK)
+ toolMenu.AppendItem(flip)
+ self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
+ if self.action['desc'] == "flipLine":
+ flip.Check(True)
+
+ merge = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=_('Merge selected lines/boundaries'),
+ kind=wx.ITEM_CHECK)
+ toolMenu.AppendItem(merge)
+ self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
+ if self.action['desc'] == "mergeLine":
+ merge.Check(True)
+
+ breakL = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=_('Break selected lines/boundaries at intersection'),
+ kind=wx.ITEM_CHECK)
+ toolMenu.AppendItem(breakL)
+ self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
+ if self.action['desc'] == "breakLine":
+ breakL.Check(True)
+
+ snap = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=_('Snap selected lines/boundaries (only to nodes)'),
+ kind=wx.ITEM_CHECK)
+ toolMenu.AppendItem(snap)
+ self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
+ if self.action['desc'] == "snapLine":
+ snap.Check(True)
+
+ connect = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=_('Connect selected lines/boundaries'),
+ kind=wx.ITEM_CHECK)
+ toolMenu.AppendItem(connect)
+ self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
+ if self.action['desc'] == "connectLine":
+ connect.Check(True)
+
+ query = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=_('Query features'),
+ kind=wx.ITEM_CHECK)
+ toolMenu.AppendItem(query)
+ self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
+ if self.action['desc'] == "queryLine":
+ query.Check(True)
+
+ zbulk = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=_('Z bulk-labeling of 3D lines'),
+ kind=wx.ITEM_CHECK)
+ toolMenu.AppendItem(zbulk)
+ self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
+ if self.action['desc'] == "zbulkLine":
+ zbulk.Check(True)
+
+ typeconv = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=_('Feature type conversion'),
+ kind=wx.ITEM_CHECK)
+ toolMenu.AppendItem(typeconv)
+ self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
+ if self.action['desc'] == "typeConv":
+ typeconv.Check(True)
+
+ # Popup the menu. If an item is selected then its handler
+ # will be called before PopupMenu returns.
+ self.parent.MapWindow.PopupMenu(toolMenu)
+ toolMenu.Destroy()
+
+ if self.action['desc'] == 'addPoint':
+ self.toolbar[0].ToggleTool(self.additionalTools, False)
+
+ def OnCopy(self, event):
+ """Copy selected features from (background) vector map"""
+ if self.action['desc'] == 'copyLine': # select previous action
+ self.toolbar[0].ToggleTool(self.addPoint, True)
+ self.toolbar[0].ToggleTool(self.additionalTools, False)
+ self.OnAddPoint(event)
+ return
+
+ Debug.msg(2, "Digittoolbar.OnCopy():")
+ self.action = { 'desc' : "copyLine",
+ 'id' : self.additionalTools }
+ self.parent.MapWindow.mouse['box'] = 'box'
+
+ def OnFlip(self, event):
+ """Flip selected lines/boundaries"""
+ if self.action['desc'] == 'flipLine': # select previous action
+ self.toolbar[0].ToggleTool(self.addPoint, True)
+ self.toolbar[0].ToggleTool(self.additionalTools, False)
+ self.OnAddPoint(event)
+ return
+
+ Debug.msg(2, "Digittoolbar.OnFlip():")
+ self.action = { 'desc' : "flipLine",
+ 'id' : self.additionalTools }
+ self.parent.MapWindow.mouse['box'] = 'box'
+
+ def OnMerge(self, event):
+ """Merge selected lines/boundaries"""
+ if self.action['desc'] == 'mergeLine': # select previous action
+ self.toolbar[0].ToggleTool(self.addPoint, True)
+ self.toolbar[0].ToggleTool(self.additionalTools, False)
+ self.OnAddPoint(event)
+ return
+
+ Debug.msg(2, "Digittoolbar.OnMerge():")
+ self.action = { 'desc' : "mergeLine",
+ 'id' : self.additionalTools }
+ self.parent.MapWindow.mouse['box'] = 'box'
+
+ def OnBreak(self, event):
+ """Break selected lines/boundaries"""
+ if self.action['desc'] == 'breakLine': # select previous action
+ self.toolbar[0].ToggleTool(self.addPoint, True)
+ self.toolbar[0].ToggleTool(self.additionalTools, False)
+ self.OnAddPoint(event)
+ return
+
+ Debug.msg(2, "Digittoolbar.OnBreak():")
+ self.action = { 'desc' : "breakLine",
+ 'id' : self.additionalTools }
+ self.parent.MapWindow.mouse['box'] = 'box'
+
+ def OnSnap(self, event):
+ """Snap selected features"""
+ if self.action['desc'] == 'snapLine': # select previous action
+ self.toolbar[0].ToggleTool(self.addPoint, True)
+ self.toolbar[0].ToggleTool(self.additionalTools, False)
+ self.OnAddPoint(event)
+ return
+
+ Debug.msg(2, "Digittoolbar.OnSnap():")
+ self.action = { 'desc' : "snapLine",
+ 'id' : self.additionalTools }
+ self.parent.MapWindow.mouse['box'] = 'box'
+
+ def OnConnect(self, event):
+ """Connect selected lines/boundaries"""
+ if self.action['desc'] == 'connectLine': # select previous action
+ self.toolbar[0].ToggleTool(self.addPoint, True)
+ self.toolbar[0].ToggleTool(self.additionalTools, False)
+ self.OnAddPoint(event)
+ return
+
+ Debug.msg(2, "Digittoolbar.OnConnect():")
+ self.action = { 'desc' : "connectLine",
+ 'id' : self.additionalTools }
+ self.parent.MapWindow.mouse['box'] = 'box'
+
+ def OnQuery(self, event):
+ """Query selected lines/boundaries"""
+ if self.action['desc'] == 'queryLine': # select previous action
+ self.toolbar[0].ToggleTool(self.addPoint, True)
+ self.toolbar[0].ToggleTool(self.additionalTools, False)
+ self.OnAddPoint(event)
+ return
+
+ Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
+ UserSettings.Get(group='vdigit', key='query', subkey='selection'))
+ self.action = { 'desc' : "queryLine",
+ 'id' : self.additionalTools }
+ self.parent.MapWindow.mouse['box'] = 'box'
+
+ def OnZBulk(self, event):
+ """Z bulk-labeling selected lines/boundaries"""
+ if not self.parent.digit.driver.Is3D():
+ wx.MessageBox(parent=self.parent,
+ message=_("Vector map is not 3D. Operation canceled."),
+ caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+ return
+
+ if self.action['desc'] == 'zbulkLine': # select previous action
+ self.toolbar[0].ToggleTool(self.addPoint, True)
+ self.toolbar[0].ToggleTool(self.additionalTools, False)
+ self.OnAddPoint(event)
+ return
+
+ Debug.msg(2, "Digittoolbar.OnZBulk():")
+ self.action = { 'desc' : "zbulkLine",
+ 'id' : self.additionalTools }
+ self.parent.MapWindow.mouse['box'] = 'line'
+
+ def OnTypeConversion(self, event):
+ """Feature type conversion
+
+ Supported conversions:
+ - point <-> centroid
+ - line <-> boundary
+ """
+ if self.action['desc'] == 'typeConv': # select previous action
+ self.toolbar[0].ToggleTool(self.addPoint, True)
+ self.toolbar[0].ToggleTool(self.additionalTools, False)
+ self.OnAddPoint(event)
+ return
+
+ Debug.msg(2, "Digittoolbar.OnTypeConversion():")
+ self.action = { 'desc' : "typeConv",
+ 'id' : self.additionalTools }
+ self.parent.MapWindow.mouse['box'] = 'box'
+
+ def OnSelectMap (self, event):
+ """
+ Select vector map layer for editing
+
+ If there is a vector map layer already edited, this action is
+ 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
+ if self.mapLayer:
+ openVectorMap = self.mapLayer.GetName(fullyQualified=False)['name']
+ else:
+ openVectorMap = None
+ mapName = gdialogs.CreateNewVector(self.parent,
+ exceptMap=openVectorMap, log=self.log,
+ cmdDef=(['v.edit', 'tool=create'], "map"),
+ disableAdd=True)[0]
+ 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:
+ self.combo.SetValue(_('Select vector map'))
+ return
+ else:
+ selection = event.GetSelection() - 1 # first option is 'New vector map'
+
+ # skip currently selected map
+ if self.layers[selection] == self.mapLayer:
+ return False
+
+ if self.mapLayer:
+ # deactive map layer for editing
+ self.StopEditing()
+
+ # select the given map layer for editing
+ self.StartEditing(self.layers[selection])
+
+ event.Skip()
+
+ return True
+
+ def StartEditing (self, mapLayer):
+ """
+ Start editing selected vector map layer.
+
+ @param mapLayer reference to MapLayer instance
+ """
+ # deactive layer
+ self.mapcontent.ChangeLayerActive(mapLayer, False)
+
+ # clean map canvas
+ ### self.parent.MapWindow.EraseMap()
+
+ # unset background map if needed
+ if UserSettings.Get(group='vdigit', key='bgmap',
+ subkey='value', internal=True) == mapLayer.GetName():
+ UserSettings.Set(group='vdigit', key='bgmap',
+ subkey='value', value='', internal=True)
+
+ self.parent.statusbar.SetStatusText(_("Please wait, "
+ "opening vector map <%s> for editing...") % \
+ mapLayer.GetName(),
+ 0)
+
+ # reload vdigit module
+ reload(vdigit)
+ from vdigit import Digit as Digit
+ self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
+
+ self.mapLayer = mapLayer
+
+ # open vector map
+ try:
+ self.parent.digit.SetMapName(mapLayer.GetName())
+ except gcmd.DigitError, e:
+ self.mapLayer = None
+ print >> sys.stderr, e # wxMessageBox
+ return False
+
+ # update toolbar
+ self.combo.SetValue(mapLayer.GetName())
+ self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
+
+ Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
+
+ # change cursor
+ if self.parent.MapWindow.mouse['use'] == 'pointer':
+ self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
+
+ # create pseudoDC for drawing the map
+ self.parent.MapWindow.pdcVector = vdigit.PseudoDC()
+ self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
+
+ if not self.parent.MapWindow.resize:
+ self.parent.MapWindow.UpdateMap(render=True)
+
+ opacity = mapLayer.GetOpacity(float=True)
+ if opacity < 1.0:
+ alpha = int(opacity * 255)
+ self.parent.digit.driver.UpdateSettings(alpha)
+
+ return True
+
+ def StopEditing (self):
+ """Stop editing of selected vector map layer.
+
+ @return True on success
+ @return False on failure
+ """
+ if not self.mapLayer:
+ return False
+
+ Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
+ self.combo.SetValue (_('Select vector map'))
+
+ # save changes
+ if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
+ if self.parent.digit.GetUndoLevel() > 0:
+ dlg = wx.MessageDialog(parent=self.parent,
+ message=_("Do you want to save changes "
+ "in vector map <%s>?") % self.mapLayer.GetName(),
+ caption=_("Save changes?"),
+ style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
+ if dlg.ShowModal() == wx.ID_NO:
+ # revert changes
+ self.parent.digit.Undo(0)
+ dlg.Destroy()
+
+ self.parent.statusbar.SetStatusText(_("Please wait, "
+ "closing and rebuilding topology of "
+ "vector map <%s>...") % self.mapLayer.GetName(),
+ 0)
+
+ self.parent.digit.SetMapName(None) # -> close map
+
+ # re-active layer
+ item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
+ if item and self.parent.tree.IsItemChecked(item):
+ self.mapcontent.ChangeLayerActive(self.mapLayer, True)
+
+ # change cursor
+ self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
+
+ # disable pseudodc for vector map layer
+ self.parent.MapWindow.pdcVector = None
+ self.parent.digit.driver.SetDevice(None)
+
+ # close dialogs
+ for dialog in ('attributes', 'category'):
+ if self.parent.dialogs[dialog]:
+ self.parent.dialogs[dialog].Close()
+ self.parent.dialogs[dialog] = None
+
+ self.parent.digit.__del__() # FIXME: destructor is not called here (del)
+ self.parent.digit = None
+
+ self.mapLayer = None
+
+ self.parent.MapWindow.redrawAll = True
+
+ return True
+
+ def UpdateListOfLayers (self, updateTool=False):
+ """
+ Update list of available vector map layers.
+ This list consists only editable layers (in the current mapset)
+
+ Optionally also update toolbar
+ """
+
+ Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
+ updateTool)
+
+ layerNameSelected = None
+ # name of currently selected layer
+ if self.mapLayer:
+ layerNameSelected = self.mapLayer.GetName()
+
+ # select vector map layer in the current mapset
+ layerNameList = []
+ self.layers = self.mapcontent.GetListOfLayers(l_type="vector",
+ l_mapset=grassenv.GetGRASSVariable('MAPSET'))
+ for layer in self.layers:
+ if not layer.name in layerNameList: # do not duplicate layer
+ layerNameList.append (layer.GetName())
+
+ if updateTool: # update toolbar
+ if not self.mapLayer:
+ value = _('Select vector map')
+ else:
+ value = layerNameSelected
+
+ if not self.comboid:
+ self.combo = wx.ComboBox(self.toolbar[self.numOfRows-1], id=wx.ID_ANY, value=value,
+ choices=[_('New vector map'), ] + layerNameList, size=(85, -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([_('New vector map'), ] + layerNameList)
+
+ self.toolbar[self.numOfRows-1].Realize()
+
+ return layerNameList
+
+ def GetLayer(self):
+ """Get selected layer for editing -- MapLayer instance"""
+ return self.mapLayer
+
+class ProfileToolbar(AbstractToolbar):
+ """
+ Toolbar for profiling raster map
+ """
+ def __init__(self, parent, tbframe):
+ self.parent = parent # GCP
+ self.tbframe = tbframe
+
+ self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
+
+ # self.SetToolBar(self.toolbar)
+ self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
+
+ self.InitToolbar(self.tbframe, self.toolbar, self.ToolbarData())
+
+ # realize the toolbar
+ self.toolbar.Realize()
+
+ def ToolbarData(self):
+ """Toolbar data"""
+
+ self.transect = wx.NewId()
+ self.addraster = wx.NewId()
+ self.draw = wx.NewId()
+ self.options = wx.NewId()
+ self.drag = wx.NewId()
+ self.zoom = wx.NewId()
+ self.unzoom = wx.NewId()
+ self.erase = wx.NewId()
+ self.save = wx.NewId()
+ self.printer = wx.NewId()
+ self.quit = wx.NewId()
+
+ # tool, label, bitmap, kind, shortHelp, longHelp, handler
+ return (
+ (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
+ self.parent.OnSelectRaster),
+ (self.transect, 'transect', Icons["transect"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
+ self.parent.OnDrawTransect),
+ (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
+ self.parent.OnCreateProfile),
+ (self.options, 'options', Icons["profileopt"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
+ self.parent.ProfileOptionsMenu),
+ (self.drag, 'drag', Icons['pan'].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
+ self.parent.OnDrag),
+ (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
+ self.parent.OnZoom),
+ (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
+ self.parent.OnRedraw),
+ (self.erase, 'erase', Icons["erase"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
+ self.parent.OnErase),
+ ("", "", "", "", "", "", ""),
+ (self.save, 'save', Icons["savefile"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
+ self.parent.SaveToFile),
+ (self.printer, 'print', Icons["printmap"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
+ self.parent.PrintMenu),
+ (self.quit, 'quit', Icons["quit"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
+ self.parent.OnQuit),
+ )
+
+class NvizToolbar(AbstractToolbar):
+ """
+ Nviz toolbar
+ """
+ def __init__(self, parent, map):
+ self.parent = parent
+ self.mapcontent = map
+
+ self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
+
+ # self.SetToolBar(self.toolbar)
+ self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
+
+ self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
+
+ # realize the toolbar
+ self.toolbar.Realize()
+
+ def ToolbarData(self):
+ """Toolbar data"""
+
+ self.settings = wx.NewId()
+ self.quit = wx.NewId()
+
+ # tool, label, bitmap, kind, shortHelp, longHelp, handler
+ return (
+ (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
+ self.OnSettings),
+ (self.quit, 'quit', Icons["quit"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
+ self.OnExit),
+ )
+
+ def OnSettings(self, event):
+ win = self.parent.nvizToolWin
+ if not win.IsShown():
+ self.parent.nvizToolWin.Show()
+ else:
+ self.parent.nvizToolWin.Hide()
+
+ def OnExit (self, event=None):
+ """Quit nviz tool (swith to 2D mode)"""
+
+ # hide dialogs if still open
+ if self.parent.nvizToolWin:
+ self.parent.nvizToolWin.Hide()
+
+ # disable the toolbar
+ self.parent.RemoveToolbar ("nviz")
+
+ # set default mouse settings
+ self.parent.MapWindow.mouse['use'] = "pointer"
+ self.parent.MapWindow.mouse['box'] = "point"
+ self.parent.MapWindow.polycoords = []
+
Added: grass-addons/gui/wxpython/data_catalog/wxgui.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/wxgui.py (rev 0)
+++ grass-addons/gui/wxpython/data_catalog/wxgui.py 2010-03-23 12:56:28 UTC (rev 41529)
@@ -0,0 +1,1464 @@
+"""
+ at package wxgui.py
+
+ at brief Main Python app for GRASS wxPython GUI. Main menu, layer management
+toolbar, notebook control for display management and access to
+command console.
+
+Classes:
+ - GMFrame
+ - GMApp
+
+(C) 2006-2009 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 Michael Barton (Arizona State University)
+ at author Jachym Cepicky (Mendel University of Agriculture)
+ at author Martin Landa <landa.martin gmail.com>
+"""
+
+import sys
+import os
+import time
+import traceback
+import re
+import string
+import getopt
+import platform
+
+### XML
+try:
+ import xml.etree.ElementTree as etree
+except ImportError:
+ import elementtree.ElementTree as etree # Python <= 2.4
+
+### i18N
+import gettext
+gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+
+pypath = "/usr/local/grass-7.0.svn/etc/wxpython"
+sys.path.append(pypath)
+
+import gui_modules
+gmpath = gui_modules.__path__[0]
+sys.path.append(gmpath)
+
+import images
+imagepath = images.__path__[0]
+sys.path.append(imagepath)
+
+import icons
+gmpath = icons.__path__[0]
+sys.path.append(gmpath)
+
+import gui_modules.globalvar as globalvar
+if not os.getenv("GRASS_WXBUNDLED"):
+ globalvar.CheckForWx()
+
+import wx
+import wx.aui
+import wx.combo
+import wx.html
+import wx.stc
+import wx.lib.customtreectrl as CT
+import wx.lib.flatnotebook as FN
+
+grassPath = os.path.join(globalvar.ETCDIR, "python")
+sys.path.append(grassPath)
+from grass.script import core as grass
+
+import gui_modules.utils as utils
+import gui_modules.preferences as preferences
+import gui_modules.wxgui_utils as wxgui_utils
+import mapdisplay as mapdisp
+import gui_modules.menudata as menudata
+import gui_modules.menuform as menuform
+import gui_modules.histogram as histogram
+import gui_modules.profile as profile
+import gui_modules.rules as rules
+import gui_modules.mcalc_builder as mapcalculator
+import gui_modules.gcmd as gcmd
+import gui_modules.georect as georect
+import gui_modules.dbm as dbm
+import gui_modules.workspace as workspace
+import gui_modules.goutput as goutput
+import gui_modules.gdialogs as gdialogs
+import gui_modules.colorrules as colorrules
+import gui_modules.ogc_services as ogc_services
+import gui_modules.prompt as prompt
+from gui_modules.debug import Debug
+from gui_modules.help import MenuTreeWindow
+from gui_modules.help import AboutWindow
+from icons.icon import Icons
+
+import glob
+import render
+#from mapwindow import BufferedWindow
+from right import RightTree
+import LayerTree
+
+UserSettings = preferences.globalSettings
+
+class GMFrame(wx.Panel):
+ """
+ GIS Manager frame with notebook widget for controlling
+ GRASS GIS. Includes command console page for typing GRASS
+ (and other) commands, tree widget page for managing GIS map layers.
+ """
+ def __init__(self, parent, id=wx.ID_ANY, title=_("GRASS GIS Layer Manager"),
+ workspace=None,frame=None):
+ self.parent = parent
+ self.baseTitle = title
+ self.iconsize = (16, 16)
+
+ wx.Panel.__init__(self, parent=parent, id=id, size=(550, 450),
+ style=wx.DEFAULT_FRAME_STYLE)
+
+ #self.SetTitle(self.baseTitle)
+ #self.SetName("LayerManager")
+
+ #self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
+
+ #self._auimgr = wx.aui.AuiManager(self)
+ self.frame = frame
+
+ # initialize variables
+ self.disp_idx = 0 # index value for map displays and layer trees
+ self.curr_page = '' # currently selected page for layer tree notebook
+ self.curr_pagenum = '' # currently selected page number for layer tree notebook
+ self.encoding = 'ISO-8859-1' # default encoding for display fonts
+ self.workspaceFile = workspace # workspace file
+ self.menucmd = dict() # menuId / cmd
+ self.georectifying = None # reference to GCP class or None
+ # list of open dialogs
+ self.dialogs = dict()
+ self.dialogs['preferences'] = None
+ self.dialogs['atm'] = list()
+
+
+
+
+
+
+ # creating widgets
+ # -> self.notebook, self.goutput, self.outpage
+ #self.notebook = self.__createNoteBook()
+ self.menubar, self.menudata = self.__createMenuBar()
+ #self.statusbar = self.CreateStatusBar(number=1)
+ #self.cmdprompt, self.cmdinput = self.__createCommandPrompt()
+ self.toolbar = self.__createToolBar()
+
+ # bindings
+ self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
+ self.Bind(wx.EVT_KEY_UP, self.OnKey)
+
+ # minimal frame size
+ #self.SetMinSize((500, 400))
+
+ # AUI stuff
+ # self._auimgr.AddPane(self.toolbar, wx.aui.AuiPaneInfo().ToolbarPane().
+ # Top().Dockable(False).CloseButton(False).
+ # DestroyOnClose(True).Row(0).Layer(0))
+ #self._auimgr.AddPane(self.notebook, wx.aui.AuiPaneInfo().
+ # Left().CentrePane().BestSize((-1,-1)).Dockable(False).
+ # CloseButton(False).DestroyOnClose(True).Row(1).Layer(0))
+ #self._auimgr.AddPane(self.cmdprompt, wx.aui.AuiPaneInfo().
+ # Bottom().BestSize((-1, 65)).Dockable(False).
+ # CloseButton(False).DestroyOnClose(True).
+ # PaneBorder(False).Row(1).Layer(0).Position(0).
+ # CaptionVisible(False))
+
+ #self._auimgr.Update()
+
+ #wx.CallAfter(self.notebook.SetSelection, 0)
+ #wx.CallAfter(self.cmdinput.SetFocus)
+
+ # use default window layout ?
+ if UserSettings.Get(group='general', key='defWindowPos', subkey='enabled') is True:
+ dim = UserSettings.Get(group='general', key='defWindowPos', subkey='dim')
+ try:
+ x, y = map(int, dim.split(',')[0:2])
+ w, h = map(int, dim.split(',')[2:4])
+ self.SetPosition((x, y))
+ self.SetSize((w, h))
+ except:
+ pass
+
+
+
+
+ def OnMapsetChange(self,event):
+ """
+ Create the tree nodes based on selected location and mapset.
+ Also update gisrc and grassrc files.
+ """
+ self.tree.DeleteAllItems()
+ self.AddTreeNodes(self.cmbLocation.GetValue(),self.cmbMapset.GetValue())
+ self.gisrc['LOCATION_NAME'] = str(self.cmbLocation.GetValue())
+ self.gisrc['MAPSET'] = str(self.cmbMapset.GetValue())
+ self.update_grassrc(self.gisrc)
+ #gcmd.RunCommand("g.gisenv", set = "MAPSET=%s" % str(self.cmbMapset.GetValue()))
+
+
+ def OnLocationChange(self,event):
+ """
+ Populate mapset combobox with selected location.
+ """
+
+ self.cmbMapset.Clear()
+ self.cmbMapset.SetValue("Select Mapset")
+ self.tree.DeleteAllItems()
+
+ maplists = self.GetMapsets(self.cmbLocation.GetValue())
+ for mapsets in maplists:
+ self.cmbMapset.Append(str(mapsets))
+
+
+
+ def GetMapsets(self,location):
+ """
+ Read and returns all mapset int GRASS data directory.
+ """
+
+ maplist = []
+ for mapset in glob.glob(os.path.join(self.gisdbase, location, "*")):
+ if os.path.isdir(mapset) and os.path.isfile(os.path.join(self.gisdbase, location, mapset, "WIND")):
+ maplist.append(os.path.basename(mapset))
+ return maplist
+
+
+
+
+ def __createMenuBar(self):
+ """!Creates menubar"""
+
+ self.menubar = wx.MenuBar()
+ self.menudata = menudata.Data()
+ for eachMenuData in self.menudata.GetMenu():
+ for eachHeading in eachMenuData:
+ menuLabel = eachHeading[0]
+ menuItems = eachHeading[1]
+ self.menubar.Append(self.__createMenu(menuItems), menuLabel)
+
+ self.frame.SetMenuBar(self.menubar)
+
+ return (self.menubar, self.menudata)
+
+ def __createMenu(self, menuData):
+ """!Creates menu"""
+
+ menu = wx.Menu()
+ for eachItem in menuData:
+ if len(eachItem) == 2:
+ label = eachItem[0]
+ subMenu = self.__createMenu(eachItem[1])
+ menu.AppendMenu(wx.ID_ANY, label, subMenu)
+ else:
+ self.__createMenuItem(menu, *eachItem)
+ self.Bind(wx.EVT_MENU_HIGHLIGHT_ALL, self.OnMenuHighlight)
+ return menu
+
+ def __createMenuItem(self, menu, label, help, handler, gcmd, keywords, shortcut = '', kind = wx.ITEM_NORMAL):
+ """!Creates menu items"""
+
+ if not label:
+ menu.AppendSeparator()
+ return
+
+ if len(gcmd) > 0:
+ helpString = gcmd + ' -- ' + help
+ else:
+ helpString = help
+
+ if shortcut:
+ label += '\t' + shortcut
+
+ menuItem = menu.Append(wx.ID_ANY, label, helpString, kind)
+
+ self.menucmd[menuItem.GetId()] = gcmd
+
+ if len(gcmd) > 0 and \
+ gcmd.split()[0] not in globalvar.grassCmd['all']:
+ menuItem.Enable (False)
+
+ rhandler = eval(handler)
+
+ self.Bind(wx.EVT_MENU, rhandler, menuItem)
+
+
+
+ def __createToolBar(self):
+ """!Creates toolbar"""
+
+ self.toolbar = self.frame.CreateToolBar()
+ self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
+
+ for each in self.ToolbarData():
+ self.AddToolbarButton(self.toolbar, *each)
+ self.toolbar.Realize()
+
+ return self.toolbar
+
+ def OnMenuHighlight(self, event):
+ """
+ Default menu help handler
+ """
+ # Show how to get menu item info from this event handler
+ id = event.GetMenuId()
+ item = self.GetMenuBar().FindItemById(id)
+ if item:
+ text = item.GetText()
+ help = item.GetHelp()
+
+ # but in this case just call Skip so the default is done
+ event.Skip()
+
+ def OnGeorectify(self, event):
+ """
+ Launch georectifier module
+ """
+ georect.GeorectWizard(self)
+
+ def OnMapsets(self, event):
+ """
+ Launch mapset access dialog
+ """
+ dlg = preferences.MapsetAccess(parent=self, id=wx.ID_ANY)
+ dlg.CenterOnScreen()
+
+ # if OK is pressed...
+ if dlg.ShowModal() == wx.ID_OK:
+ ms = dlg.GetMapsets()
+ # run g.mapsets with string of accessible mapsets
+ gcmd.RunCommand('g.mapsets',
+ parent = self,
+ mapset = '%s' % ','.join(ms))
+
+ def OnRDigit(self, event):
+ """
+ Launch raster digitizing module
+ """
+ pass
+
+ def OnCBPageChanged(self, event):
+ """!Page in notebook (display) changed"""
+ old_pgnum = event.GetOldSelection()
+ new_pgnum = event.GetSelection()
+
+ self.curr_page = self.gm_cb.GetCurrentPage()
+ self.curr_pagenum = self.gm_cb.GetSelection()
+
+ try:
+ self.curr_page.maptree.mapdisplay.SetFocus()
+ self.curr_page.maptree.mapdisplay.Raise()
+ except:
+ pass
+
+ event.Skip()
+
+ def OnPageChanged(self, event):
+ """!Page in notebook changed"""
+ page = event.GetSelection()
+ if page == self.goutput.pageid:
+ # remove '(...)'
+ self.notebook.SetPageText(page, _("Command output"))
+
+ event.Skip()
+
+ def OnCBPageClosed(self, event):
+ """
+ Page of notebook closed
+ Also close associated map display
+ """
+ if UserSettings.Get(group='manager', key='askOnQuit', subkey='enabled'):
+ maptree = self.curr_page.maptree
+
+ if self.workspaceFile:
+ message = _("Do you want to save changes in the workspace?")
+ else:
+ message = _("Do you want to store current settings "
+ "to workspace file?")
+
+ # ask user to save current settings
+ if maptree.GetCount() > 0:
+ dlg = wx.MessageDialog(self,
+ message=message,
+ caption=_("Close Map Display %d") % (self.curr_pagenum + 1),
+ style=wx.YES_NO | wx.YES_DEFAULT |
+ wx.CANCEL | wx.ICON_QUESTION | wx.CENTRE)
+ ret = dlg.ShowModal()
+ if ret == wx.ID_YES:
+ if not self.workspaceFile:
+ self.OnWorkspaceSaveAs()
+ else:
+ self.SaveToWorkspaceFile(self.workspaceFile)
+ elif ret == wx.ID_CANCEL:
+ event.Veto()
+ dlg.Destroy()
+ return
+ dlg.Destroy()
+
+ self.gm_cb.GetPage(event.GetSelection()).maptree.Map.Clean()
+ self.gm_cb.GetPage(event.GetSelection()).maptree.Close(True)
+
+ self.curr_page = None
+
+ event.Skip()
+
+ def GetLogWindow(self):
+ """!Get widget for command output"""
+ return self.goutput
+
+ def GetMenuCmd(self, event):
+ """!Get GRASS command from menu item
+
+ Return command as a list"""
+ layer = None
+
+ if event:
+ cmd = self.menucmd[event.GetId()]
+
+ try:
+ cmdlist = cmd.split(' ')
+ except: # already list?
+ cmdlist = cmd
+
+ # check list of dummy commands for GUI modules that do not have GRASS
+ # bin modules or scripts.
+ if cmd in ['vcolors']:
+ return cmdlist
+
+ try:
+ layer = self.curr_page.maptree.layer_selected
+ name = self.curr_page.maptree.GetPyData(layer)[0]['maplayer'].name
+ type = self.curr_page.maptree.GetPyData(layer)[0]['type']
+ except:
+ layer = None
+ if layer and len(cmdlist) == 1: # only if no paramaters given
+ if (type == 'raster' and cmdlist[0][0] == 'r' and cmdlist[0][1] != '3') or \
+ (type == 'vector' and cmdlist[0][0] == 'v'):
+ input = menuform.GUI().GetCommandInputMapParamKey(cmdlist[0])
+ if input:
+ cmdlist.append("%s=%s" % (input, name))
+
+ return cmdlist
+
+ def RunMenuCmd(self, event):
+ """!Run command selected from menu"""
+ cmd = self.GetMenuCmd(event)
+ self.goutput.RunCmd(cmd, switchPage=True)
+
+ def OnMenuCmd(self, event, cmd = ''):
+ """!Parse command selected from menu"""
+ if event:
+ cmd = self.GetMenuCmd(event)
+ menuform.GUI().ParseCommand(cmd, parentframe=self)
+
+ def OnChangeLocation(self, event):
+ """Change current location"""
+ dlg = gdialogs.LocationDialog(parent = self)
+ if dlg.ShowModal() == wx.ID_OK:
+ location, mapset = dlg.GetValues()
+ if location and mapset:
+ ret = gcmd.RunCommand("g.gisenv",
+ set = "LOCATION_NAME=%s" % location)
+ ret += gcmd.RunCommand("g.gisenv",
+ set = "MAPSET=%s" % mapset)
+ if ret > 0:
+ wx.MessageBox(parent = self,
+ message = _("Unable to switch to location <%(loc)s> mapset <%(mapset)s>.") % \
+ { 'loc' : location, 'mapset' : mapset },
+ caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
+ else:
+ # close workspace
+ self.OnWorkspaceClose()
+ self.OnWorkspaceNew()
+ wx.MessageBox(parent = self,
+ message = _("Current location is <%(loc)s>.\n"
+ "Current mapset is <%(mapset)s>.") % \
+ { 'loc' : location, 'mapset' : mapset },
+ caption = _("Info"), style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
+
+ def OnChangeMapset(self, event):
+ """Change current mapset"""
+ dlg = gdialogs.MapsetDialog(parent = self)
+ if dlg.ShowModal() == wx.ID_OK:
+ mapset = dlg.GetMapset()
+ if mapset:
+ if gcmd.RunCommand("g.gisenv",
+ set = "MAPSET=%s" % mapset) != 0:
+ wx.MessageBox(parent = self,
+ message = _("Unable to switch to mapset <%s>.") % mapset,
+ caption = _("Error"), style = wx.OK | wx.ICON_ERROR | wx.CENTRE)
+ else:
+ wx.MessageBox(parent = self,
+ message = _("Current mapset is <%s>.") % mapset,
+ caption = _("Info"), style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
+
+ def OnNewVector(self, event):
+ """!Create new vector map layer"""
+ name, add = gdialogs.CreateNewVector(self, log = self.goutput,
+ cmd = (('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 OnMenuTree(self, event):
+ """!Show dialog with menu tree"""
+ dlg = MenuTreeWindow(self)
+ dlg.CentreOnScreen()
+ dlg.Show()
+
+ def OnAboutGRASS(self, event):
+ """!Display 'About GRASS' dialog"""
+ win = AboutWindow(self)
+ win.Centre()
+ win.Show(True)
+
+ def OnWorkspace(self, event):
+ """!Workspace menu (new, load)"""
+ point = wx.GetMousePosition()
+ menu = wx.Menu()
+
+ # Add items to the menu
+ new = wx.MenuItem(menu, wx.ID_ANY, Icons["workspaceNew"].GetLabel())
+ new.SetBitmap(Icons["workspaceNew"].GetBitmap(self.iconsize))
+ menu.AppendItem(new)
+ self.Bind(wx.EVT_MENU, self.OnWorkspaceNew, new)
+
+ load = wx.MenuItem(menu, wx.ID_ANY, Icons["workspaceLoad"].GetLabel())
+ load.SetBitmap(Icons["workspaceLoad"].GetBitmap(self.iconsize))
+ menu.AppendItem(load)
+ self.Bind(wx.EVT_MENU, self.OnWorkspaceLoad, load)
+
+ # create menu
+ self.PopupMenu(menu)
+ menu.Destroy()
+
+ def OnWorkspaceNew(self, event=None):
+ """!Create new workspace file
+
+ Erase current workspace settings first"""
+
+ Debug.msg(4, "GMFrame.OnWorkspaceNew():")
+
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay()
+
+ maptree = self.curr_page.maptree
+
+ # ask user to save current settings
+ if maptree.GetCount() > 0:
+ dlg = wx.MessageDialog(self, message=_("Current workspace is not empty. "
+ "Do you want to store current settings "
+ "to workspace file?"),
+ caption=_("Create new workspace?"),
+ style=wx.YES_NO | wx.YES_DEFAULT | \
+ wx.CANCEL | wx.ICON_QUESTION)
+ ret = dlg.ShowModal()
+ if ret == wx.ID_YES:
+ self.OnWorkspaceSaveAs()
+ elif ret == wx.ID_CANCEL:
+ dlg.Destroy()
+ return
+
+ dlg.Destroy()
+
+ # delete all items
+ maptree.DeleteAllItems()
+
+ # add new root element
+ maptree.root = maptree.AddRoot("Map Layers")
+ self.curr_page.maptree.SetPyData(maptree.root, (None,None))
+
+ # no workspace file loaded
+ self.workspaceFile = None
+ self.SetTitle(self.baseTitle)
+
+ def OnWorkspaceOpen(self, event=None):
+ """!Open file with workspace definition"""
+ dlg = wx.FileDialog(parent=self, message=_("Choose workspace file"),
+ defaultDir=os.getcwd(), wildcard="*.gxw")
+
+ filename = ''
+ if dlg.ShowModal() == wx.ID_OK:
+ filename = dlg.GetPath()
+
+ if filename == '':
+ return
+
+ Debug.msg(4, "GMFrame.OnWorkspaceOpen(): filename=%s" % filename)
+
+ # delete current layer tree content
+ self.OnWorkspaceClose()
+
+ self.LoadWorkspaceFile(filename)
+
+ self.workspaceFile = filename
+ self.SetTitle(self.baseTitle + " - " + os.path.basename(self.workspaceFile))
+
+ def LoadWorkspaceFile(self, filename):
+ """!Load layer tree definition stored in GRASS Workspace XML file (gxw)
+
+ @todo Validate against DTD
+
+ @return True on success
+ @return False on error
+ """
+ # dtd
+ dtdFilename = os.path.join(globalvar.ETCWXDIR, "xml", "grass-gxw.dtd")
+
+ # parse workspace file
+ try:
+ gxwXml = workspace.ProcessWorkspaceFile(etree.parse(filename))
+ except Exception, err:
+ raise gcmd.GStdError(_("Reading workspace file <%(file)s> failed.\n"
+ "Invalid file, unable to parse XML document."
+ "\n\n%(err)s") % { 'file' : filename, 'err': err},
+ parent = self)
+
+ busy = wx.BusyInfo(message=_("Please wait, loading workspace..."),
+ parent=self)
+ wx.Yield()
+
+ #
+ # load layer manager window properties
+ #
+ if UserSettings.Get(group='workspace', key='posManager', subkey='enabled') is False:
+ if gxwXml.layerManager['pos']:
+ self.SetPosition(gxwXml.layerManager['pos'])
+ if gxwXml.layerManager['size']:
+ self.SetSize(gxwXml.layerManager['size'])
+
+ #
+ # start map displays first (list of layers can be empty)
+ #
+ displayId = 0
+ mapdisplay = []
+ for display in gxwXml.displays:
+ mapdisplay.append(self.NewDisplay(show=False))
+ maptree = self.gm_cb.GetPage(displayId).maptree
+
+ # set windows properties
+ mapdisplay[-1].SetProperties(render=display['render'],
+ mode=display['mode'],
+ showCompExtent=display['showCompExtent'],
+ constrainRes=display['constrainRes'],
+ projection=display['projection']['enabled'])
+
+ if display['projection']['enabled']:
+ if display['projection']['epsg']:
+ UserSettings.Set(group = 'display', key = 'projection', subkey = 'epsg',
+ value = display['projection']['epsg'])
+ if display['projection']['proj']:
+ UserSettings.Set(group = 'display', key = 'projection', subkey = 'proj4',
+ value = display['projection']['proj'])
+
+ # set position and size of map display
+ if UserSettings.Get(group='workspace', key='posDisplay', subkey='enabled') is False:
+ if display['pos']:
+ mapdisplay[-1].SetPosition(display['pos'])
+ if display['size']:
+ mapdisplay[-1].SetSize(display['size'])
+
+ # set extent if defined
+ if display['extent']:
+ w, s, e, n = display['extent']
+ maptree.Map.region = maptree.Map.GetRegion(w=w, s=s, e=e, n=n)
+
+ mapdisplay[-1].Show()
+
+ displayId += 1
+
+ maptree = None
+ selected = [] # list of selected layers
+ #
+ # load list of map layers
+ #
+ for layer in gxwXml.layers:
+ display = layer['display']
+ maptree = self.gm_cb.GetPage(display).maptree
+
+ newItem = maptree.AddLayer(ltype=layer['type'],
+ lname=layer['name'],
+ lchecked=layer['checked'],
+ lopacity=layer['opacity'],
+ lcmd=layer['cmd'],
+ lgroup=layer['group'],
+ lnviz=layer['nviz'],
+ lvdigit=layer['vdigit'])
+
+ if layer.has_key('selected'):
+ if layer['selected']:
+ selected.append((maptree, newItem))
+ else:
+ maptree.SelectItem(newItem, select=False)
+
+ for maptree, layer in selected:
+ if not maptree.IsSelected(layer):
+ maptree.SelectItem(layer, select=True)
+ maptree.layer_selected = layer
+
+ busy.Destroy()
+
+ if maptree:
+ # reverse list of map layers
+ maptree.Map.ReverseListOfLayers()
+
+ for mdisp in mapdisplay:
+ mdisp.MapWindow2D.UpdateMap()
+
+ return True
+
+ def OnWorkspaceLoad(self, event=None):
+ """!Load given map layers into layer tree"""
+ dialog = gdialogs.LoadMapLayersDialog(parent=self, title=_("Load map layers into layer tree"))
+
+ if dialog.ShowModal() == wx.ID_OK:
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay()
+
+ maptree = self.curr_page.maptree
+ busy = wx.BusyInfo(message=_("Please wait, loading workspace..."),
+ parent=self)
+ wx.Yield()
+
+ for layerName in dialog.GetMapLayers():
+ if dialog.GetLayerType() == 'raster':
+ cmd = ['d.rast', 'map=%s' % layerName]
+ elif dialog.GetLayerType() == 'vector':
+ cmd = ['d.vect', 'map=%s' % layerName]
+ newItem = maptree.AddLayer(ltype=dialog.GetLayerType(),
+ lname=layerName,
+ lchecked=True,
+ lopacity=1.0,
+ lcmd=cmd,
+ lgroup=None)
+
+ busy.Destroy()
+
+ def OnWorkspaceLoadGrcFile(self, event):
+ """!Load map layers from GRC file (Tcl/Tk GUI) into map layer tree"""
+ dlg = wx.FileDialog(parent=self, message=_("Choose GRC file to load"),
+ defaultDir=os.getcwd(), wildcard="*.grc")
+
+ filename = ''
+ if dlg.ShowModal() == wx.ID_OK:
+ filename = dlg.GetPath()
+
+ if filename == '':
+ return
+
+ Debug.msg(4, "GMFrame.OnWorkspaceLoadGrcFile(): filename=%s" % filename)
+
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay()
+
+ busy = wx.BusyInfo(message=_("Please wait, loading workspace..."),
+ parent=self)
+ wx.Yield()
+
+ maptree = None
+ for layer in workspace.ProcessGrcFile(filename).read(self):
+ maptree = self.gm_cb.GetPage(layer['display']).maptree
+ newItem = maptree.AddLayer(ltype=layer['type'],
+ lname=layer['name'],
+ lchecked=layer['checked'],
+ lopacity=layer['opacity'],
+ lcmd=layer['cmd'],
+ lgroup=layer['group'])
+
+ busy.Destroy()
+
+ if maptree:
+ # reverse list of map layers
+ maptree.Map.ReverseListOfLayers()
+
+ def OnWorkspaceSaveAs(self, event=None):
+ """!Save workspace definition to selected file"""
+
+ dlg = wx.FileDialog(parent=self, message=_("Choose file to save current workspace"),
+ defaultDir=os.getcwd(), wildcard="*.gxw", style=wx.FD_SAVE)
+
+ filename = ''
+ if dlg.ShowModal() == wx.ID_OK:
+ filename = dlg.GetPath()
+
+ if filename == '':
+ return False
+
+ # check for extension
+ if filename[-4:] != ".gxw":
+ filename += ".gxw"
+
+ if os.path.exists(filename):
+ dlg = wx.MessageDialog(self, message=_("Workspace file <%s> already exists. "
+ "Do you want to overwrite this file?") % filename,
+ caption=_("Save workspace"), style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
+ if dlg.ShowModal() != wx.ID_YES:
+ dlg.Destroy()
+ return False
+
+ Debug.msg(4, "GMFrame.OnWorkspaceSaveAs(): filename=%s" % filename)
+
+ self.SaveToWorkspaceFile(filename)
+ self.workspaceFile = filename
+ self.SetTitle(self.baseTitle + " - " + os.path.basename(self.workspaceFile))
+
+ def OnWorkspaceSave(self, event=None):
+ """!Save file with workspace definition"""
+
+ if self.workspaceFile:
+ dlg = wx.MessageDialog(self, message=_("Workspace file <%s> already exists. "
+ "Do you want to overwrite this file?") % \
+ self.workspaceFile,
+ caption=_("Save workspace"), style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
+ if dlg.ShowModal() == wx.ID_NO:
+ dlg.Destroy()
+ else:
+ Debug.msg(4, "GMFrame.OnWorkspaceSave(): filename=%s" % self.workspaceFile)
+ self.SaveToWorkspaceFile(self.workspaceFile)
+ else:
+ self.OnWorkspaceSaveAs()
+
+ def SaveToWorkspaceFile(self, filename):
+ """!Save layer tree layout to workspace file
+
+ Return True on success, False on error
+ """
+
+ try:
+ file = open(filename, "w")
+ except IOError:
+ wx.MessageBox(parent=self,
+ message=_("Unable to open workspace file <%s> for writing.") % filename,
+ caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+ return False
+
+ try:
+ workspace.WriteWorkspaceFile(lmgr=self, file=file)
+ except StandardError, e:
+ file.close()
+ wx.MessageBox(parent=self,
+ message=_("Writing current settings to workspace file failed (%s)." % e),
+ caption=_("Error"),
+ style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+ return False
+
+ file.close()
+
+ return True
+
+ def OnWorkspaceClose(self, event=None):
+ """!Close file with workspace definition
+
+ If workspace has been modified ask user to save the changes.
+ """
+
+ Debug.msg(4, "GMFrame.OnWorkspaceClose(): file=%s" % self.workspaceFile)
+ self.workspaceFile = None
+ self.SetTitle(self.baseTitle)
+
+ displays = []
+ for page in range(0, self.gm_cb.GetPageCount()):
+ displays.append(self.gm_cb.GetPage(page).maptree.mapdisplay)
+
+ for display in displays:
+ display.OnCloseWindow(event)
+
+ self.disp_idx = 0
+ self.curr_page = None
+
+
+ def RulesCmd(self, event, cmd = ''):
+ """
+ Launches dialog for commands that need rules
+ input and processes rules
+ """
+ if event:
+ cmd = self.GetMenuCmd(event)
+
+ if cmd[0] == 'r.colors' or cmd[0] == 'vcolors':
+ ctable = colorrules.ColorTable(self, cmd=cmd[0])
+ ctable.Show()
+ else:
+ dlg = rules.RulesText(self, cmd=cmd)
+ dlg.CenterOnScreen()
+ if dlg.ShowModal() == wx.ID_OK:
+ gtemp = utils.GetTempfile()
+ output = open(gtemp, "w")
+ try:
+ output.write(dlg.rules)
+ finally:
+ output.close()
+
+ cmdlist = [cmd[0],
+ 'input=%s' % dlg.inmap,
+ 'output=%s' % dlg.outmap,
+ 'rules=%s' % gtemp]
+
+ if dlg.overwrite == True:
+ cmdlist.append('--o')
+
+ dlg.Destroy()
+
+ self.goutput.RunCmd(cmdlist)
+
+ def OnPreferences(self, event):
+ """!General GUI preferences/settings"""
+ if not self.dialogs['preferences']:
+ dlg = preferences.PreferencesDialog(parent=self)
+ self.dialogs['preferences'] = dlg
+ self.dialogs['preferences'].CenterOnScreen()
+
+ self.dialogs['preferences'].ShowModal()
+
+ def DispHistogram(self, event):
+ """
+ Init histogram display canvas and tools
+ """
+ self.histogram = histogram.HistFrame(self,
+ id=wx.ID_ANY, pos=wx.DefaultPosition, size=(400,300),
+ style=wx.DEFAULT_FRAME_STYLE)
+
+ #show new display
+ self.histogram.Show()
+ self.histogram.Refresh()
+ self.histogram.Update()
+
+ def DispProfile(self, event):
+ """
+ Init profile canvas and tools
+ """
+ self.profile = profile.ProfileFrame(self,
+ id=wx.ID_ANY, pos=wx.DefaultPosition, size=(400,300),
+ style=wx.DEFAULT_FRAME_STYLE)
+ self.profile.Show()
+ self.profile.Refresh()
+ self.profile.Update()
+
+ def DispMapCalculator(self, event):
+ """
+ Init map calculator for interactive creation of mapcalc statements
+ """
+
+ self.mapcalculator = mapcalculator.MapCalcFrame(self, wx.ID_ANY, title='',
+ dimension=2)
+
+ def Disp3DMapCalculator(self, event):
+ """
+ Init map calculator for interactive creation of mapcalc statements
+ """
+
+ self.mapcalculator = mapcalculator.MapCalcFrame(self, wx.ID_ANY, title='',
+ dimension=3)
+
+ def AddToolbarButton(self, toolbar, label, icon, help, handler):
+ """!Adds button to the given toolbar"""
+
+ if not label:
+ toolbar.AddSeparator()
+ return
+ tool = toolbar.AddLabelTool(id=wx.ID_ANY, label=label, bitmap=icon, shortHelp=help)
+ self.Bind(wx.EVT_TOOL, handler, tool)
+
+ def ToolbarData(self):
+
+ return (
+ ('newdisplay', Icons["newdisplay"].GetBitmap(),
+ Icons["newdisplay"].GetLabel(), self.OnNewDisplay),
+ ('', '', '', ''),
+ ('workspaceLoad', Icons["workspaceLoad"].GetBitmap(),
+ Icons["workspaceLoad"].GetLabel(), self.OnWorkspace),
+ ('workspaceOpen', Icons["workspaceOpen"].GetBitmap(),
+ Icons["workspaceOpen"].GetLabel(), self.OnWorkspaceOpen),
+ ('workspaceSave', Icons["workspaceSave"].GetBitmap(),
+ Icons["workspaceSave"].GetLabel(), self.OnWorkspaceSave),
+ ('', '', '', ''),
+ ('addrast', Icons["addrast"].GetBitmap(),
+ Icons["addrast"].GetLabel(), self.OnAddRaster),
+ ('addshaded', Icons["addshaded"].GetBitmap(),
+ _("Add various raster-based map layers"), self.OnAddRasterMisc),
+ ('addvect', Icons["addvect"].GetBitmap(),
+ Icons["addvect"].GetLabel(), self.OnAddVector),
+ ('addthematic', Icons["addthematic"].GetBitmap(),
+ _("Add various vector-based map layer"), self.OnAddVectorMisc),
+ ('addcmd', Icons["addcmd"].GetBitmap(),
+ Icons["addcmd"].GetLabel(), self.OnAddCommand),
+ ('addgrp', Icons["addgrp"].GetBitmap(),
+ Icons["addgrp"].GetLabel(), self.OnAddGroup),
+ ('addovl', Icons["addovl"].GetBitmap(),
+ Icons["addovl"].GetLabel(), self.OnAddOverlay),
+ ('delcmd', Icons["delcmd"].GetBitmap(),
+ Icons["delcmd"].GetLabel(), self.OnDeleteLayer),
+ ('', '', '', ''),
+ ('attrtable', Icons["attrtable"].GetBitmap(),
+ Icons["attrtable"].GetLabel(), self.OnShowAttributeTable)
+ )
+
+ def OnImportDxfFile(self, event):
+ """!Convert multiple DXF layers to GRASS vector map layers"""
+ dlg = gdialogs.MultiImportDialog(parent=self, type='dxf',
+ title=_("Import DXF layers"))
+ dlg.ShowModal()
+
+ def OnImportGdalLayers(self, event):
+ """!Convert multiple GDAL layers to GRASS raster map layers"""
+ dlg = gdialogs.MultiImportDialog(parent=self, type='gdal',
+ title=_("Import GDAL layers"))
+ dlg.ShowModal()
+
+ def OnLinkGdalLayers(self, event):
+ """!Link multiple GDAL layers to GRASS raster map layers"""
+ dlg = gdialogs.MultiImportDialog(parent=self, type='gdal',
+ title=_("Link GDAL layers"),
+ link = True)
+ dlg.ShowModal()
+
+ def OnImportOgrLayers(self, event):
+ """!Convert multiple OGR layers to GRASS vector map layers"""
+ dlg = gdialogs.MultiImportDialog(parent=self, type='ogr',
+ title=_("Import OGR layers"))
+ dlg.ShowModal()
+
+ def OnLinkOgrLayers(self, event):
+ """!Links multiple OGR layers to GRASS vector map layers"""
+ dlg = gdialogs.MultiImportDialog(parent=self, type='ogr',
+ title=_("Link OGR layers"),
+ link = True)
+ dlg.ShowModal()
+
+ def OnImportWMS(self, event):
+ """!Import data from OGC WMS server"""
+ dlg = ogc_services.WMSDialog(parent = self, service = 'wms')
+ dlg.CenterOnScreen()
+
+ if dlg.ShowModal() == wx.ID_OK: # -> import layers
+ layers = dlg.GetLayers()
+
+ if len(layers.keys()) > 0:
+ for layer in layers.keys():
+ cmd = ['r.in.wms',
+ 'mapserver=%s' % dlg.GetSettings()['server'],
+ 'layers=%s' % layer,
+ 'output=%s' % layer]
+ styles = ','.join(layers[layer])
+ if styles:
+ cmd.append('styles=%s' % styles)
+ self.goutput.RunCmd(cmd, switchPage = True)
+ else:
+ self.goutput.WriteWarning(_("Nothing to import. No WMS layer selected."))
+
+ dlg.Destroy()
+
+ def OnShowAttributeTable(self, event):
+ """
+ Show attribute table of the given vector map layer
+ """
+ if not self.curr_page:
+ self.MsgNoLayerSelected()
+ return
+
+ layer = self.curr_page.maptree.layer_selected
+ # no map layer selected
+ if not layer:
+ self.MsgNoLayerSelected()
+ return
+
+ # available only for vector map layers
+ try:
+ maptype = self.curr_page.maptree.GetPyData(layer)[0]['maplayer'].type
+ except:
+ maptype = None
+
+ if not maptype or maptype != 'vector':
+ wx.MessageBox(parent=self,
+ message=_("Attribute management is available only "
+ "for vector maps."),
+ caption=_("Message"),
+ style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
+ return
+
+ if not self.curr_page.maptree.GetPyData(layer)[0]:
+ return
+ dcmd = self.curr_page.maptree.GetPyData(layer)[0]['cmd']
+ if not dcmd:
+ return
+
+ busy = wx.BusyInfo(message=_("Please wait, loading attribute data..."),
+ parent=self)
+ wx.Yield()
+
+ dbmanager = dbm.AttributeManager(parent=self, id=wx.ID_ANY,
+ size=wx.Size(500, 300),
+ item=layer, log=self.goutput)
+
+ busy.Destroy()
+
+ # register ATM dialog
+ self.dialogs['atm'].append(dbmanager)
+
+ # show ATM window
+ dbmanager.Show()
+
+ def OnNewDisplay(self, event=None):
+ """!Create new layer tree and map display instance"""
+ self.NewDisplay()
+
+ def NewDisplay(self, show=True):
+ """!Create new layer tree, which will
+ create an associated map display frame
+
+ @param show show map display window if True
+
+ @return reference to mapdisplay intance
+ """
+ Debug.msg(1, "GMFrame.NewDisplay(): idx=%d" % self.disp_idx)
+
+ # make a new page in the bookcontrol for the layer tree (on page 0 of the notebook)
+ self.pg_panel = wx.Panel(self.gm_cb, id=wx.ID_ANY, style= wx.EXPAND)
+ self.gm_cb.AddPage(self.pg_panel, text="Display "+ str(self.disp_idx + 1), select = True)
+ self.curr_page = self.gm_cb.GetCurrentPage()
+
+ # create layer tree (tree control for managing GIS layers) and put on new notebook page
+ self.curr_page.maptree = wxgui_utils.LayerTree(self.curr_page, id=wx.ID_ANY, pos=wx.DefaultPosition,
+ size=wx.DefaultSize, style=wx.TR_HAS_BUTTONS
+ |wx.TR_LINES_AT_ROOT|wx.TR_HIDE_ROOT
+ |wx.TR_DEFAULT_STYLE|wx.NO_BORDER|wx.FULL_REPAINT_ON_RESIZE,
+ idx=self.disp_idx, lmgr=self, notebook=self.gm_cb,
+ auimgr=self._auimgr, showMapDisplay=show)
+
+ # layout for controls
+ cb_boxsizer = wx.BoxSizer(wx.VERTICAL)
+ cb_boxsizer.Add(self.curr_page.maptree, proportion=1, flag=wx.EXPAND, border=1)
+ self.curr_page.SetSizer(cb_boxsizer)
+ cb_boxsizer.Fit(self.curr_page.maptree)
+ self.curr_page.Layout()
+ self.curr_page.maptree.Layout()
+
+ # use default window layout
+ if UserSettings.Get(group='general', key='defWindowPos', subkey='enabled') is True:
+ dim = UserSettings.Get(group='general', key='defWindowPos', subkey='dim')
+ idx = 4 + self.disp_idx * 4
+ try:
+ x, y = map(int, dim.split(',')[idx:idx + 2])
+ w, h = map(int, dim.split(',')[idx + 2:idx + 4])
+ self.curr_page.maptree.mapdisplay.SetPosition((x, y))
+ self.curr_page.maptree.mapdisplay.SetSize((w, h))
+ except:
+ pass
+
+ self.disp_idx += 1
+
+ return self.curr_page.maptree.mapdisplay
+
+ # toolBar button handlers
+ def OnAddRaster(self, event):
+ """!Add raster map layer"""
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay(show=False)
+
+ self.AddRaster(event)
+
+ def OnAddRasterMisc(self, event):
+ """!Add raster menu"""
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay(show=False)
+
+ point = wx.GetMousePosition()
+ rastmenu = wx.Menu()
+
+ # add items to the menu
+ if self.curr_page.maptree.mapdisplay.toolbars['nviz']:
+ addrast3d = wx.MenuItem(rastmenu, -1, Icons ["addrast3d"].GetLabel())
+ addrast3d.SetBitmap(Icons["addrast3d"].GetBitmap (self.iconsize))
+ rastmenu.AppendItem(addrast3d)
+ self.Bind(wx.EVT_MENU, self.AddRaster3d, addrast3d)
+
+ addshaded = wx.MenuItem(rastmenu, -1, Icons ["addshaded"].GetLabel())
+ addshaded.SetBitmap(Icons["addshaded"].GetBitmap (self.iconsize))
+ rastmenu.AppendItem(addshaded)
+ self.Bind(wx.EVT_MENU, self.AddShaded, addshaded)
+
+ addrgb = wx.MenuItem(rastmenu, -1, Icons["addrgb"].GetLabel())
+ addrgb.SetBitmap(Icons["addrgb"].GetBitmap(self.iconsize))
+ rastmenu.AppendItem(addrgb)
+ self.Bind(wx.EVT_MENU, self.AddRGB, addrgb)
+
+ addhis = wx.MenuItem(rastmenu, -1, Icons ["addhis"].GetLabel())
+ addhis.SetBitmap(Icons["addhis"].GetBitmap (self.iconsize))
+ rastmenu.AppendItem(addhis)
+ self.Bind(wx.EVT_MENU, self.AddHIS, addhis)
+
+ addrastarrow = wx.MenuItem(rastmenu, -1, Icons ["addrarrow"].GetLabel())
+ addrastarrow.SetBitmap(Icons["addrarrow"].GetBitmap (self.iconsize))
+ rastmenu.AppendItem(addrastarrow)
+ self.Bind(wx.EVT_MENU, self.AddRastarrow, addrastarrow)
+
+ addrastnums = wx.MenuItem(rastmenu, -1, Icons ["addrnum"].GetLabel())
+ addrastnums.SetBitmap(Icons["addrnum"].GetBitmap (self.iconsize))
+ rastmenu.AppendItem(addrastnums)
+ self.Bind(wx.EVT_MENU, self.AddRastnum, addrastnums)
+
+ # Popup the menu. If an item is selected then its handler
+ # will be called before PopupMenu returns.
+ self.PopupMenu(rastmenu)
+ rastmenu.Destroy()
+
+ # show map display
+ self.curr_page.maptree.mapdisplay.Show()
+
+ def OnAddVector(self, event):
+ """!Add vector map layer"""
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay(show=False)
+
+ self.AddVector(event)
+
+ def OnAddVectorMisc(self, event):
+ """!Add vector menu"""
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay(show=False)
+
+ point = wx.GetMousePosition()
+ vectmenu = wx.Menu()
+
+ addtheme = wx.MenuItem(vectmenu, -1, Icons["addthematic"].GetLabel())
+ addtheme.SetBitmap(Icons["addthematic"].GetBitmap(self.iconsize))
+ vectmenu.AppendItem(addtheme)
+ self.Bind(wx.EVT_MENU, self.AddThemeMap, addtheme)
+
+ addchart = wx.MenuItem(vectmenu, -1, Icons["addchart"].GetLabel())
+ addchart.SetBitmap(Icons["addchart"].GetBitmap(self.iconsize))
+ vectmenu.AppendItem(addchart)
+ self.Bind(wx.EVT_MENU, self.AddThemeChart, addchart)
+
+ # Popup the menu. If an item is selected then its handler
+ # will be called before PopupMenu returns.
+ self.PopupMenu(vectmenu)
+ vectmenu.Destroy()
+
+ # show map display
+ self.curr_page.maptree.mapdisplay.Show()
+
+ def OnAddOverlay(self, event):
+ """!Add overlay menu"""
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay(show=False)
+
+ point = wx.GetMousePosition()
+ ovlmenu = wx.Menu()
+
+ addgrid = wx.MenuItem(ovlmenu, wx.ID_ANY, Icons["addgrid"].GetLabel())
+ addgrid.SetBitmap(Icons["addgrid"].GetBitmap(self.iconsize))
+ ovlmenu.AppendItem(addgrid)
+ self.Bind(wx.EVT_MENU, self.AddGrid, addgrid)
+
+ addlabels = wx.MenuItem(ovlmenu, wx.ID_ANY, Icons["addlabels"].GetLabel())
+ addlabels.SetBitmap(Icons["addlabels"].GetBitmap(self.iconsize))
+ ovlmenu.AppendItem(addlabels)
+ self.Bind(wx.EVT_MENU, self.OnAddLabels, addlabels)
+
+ addgeodesic = wx.MenuItem(ovlmenu, wx.ID_ANY, Icons["addgeodesic"].GetLabel())
+ addgeodesic.SetBitmap(Icons["addgeodesic"].GetBitmap(self.iconsize))
+ ovlmenu.AppendItem(addgeodesic)
+ self.Bind(wx.EVT_MENU, self.AddGeodesic, addgeodesic)
+
+ addrhumb = wx.MenuItem(ovlmenu, wx.ID_ANY, Icons["addrhumb"].GetLabel())
+ addrhumb.SetBitmap(Icons["addrhumb"].GetBitmap(self.iconsize))
+ ovlmenu.AppendItem(addrhumb)
+ self.Bind(wx.EVT_MENU, self.AddRhumb, addrhumb)
+
+ # Popup the menu. If an item is selected then its handler
+ # will be called before PopupMenu returns.
+ self.PopupMenu(ovlmenu)
+ ovlmenu.Destroy()
+
+ # show map display
+ self.curr_page.maptree.mapdisplay.Show()
+
+ def AddRaster(self, event):
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('raster')
+
+ def AddRaster3d(self, event):
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('3d-raster')
+
+ def AddRGB(self, event):
+ """!Add RGB layer"""
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('rgb')
+
+ def AddHIS(self, event):
+ """!Add HIS layer"""
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('his')
+
+ def AddShaded(self, event):
+ """!Add shaded relief map layer"""
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('shaded')
+
+ def AddRastarrow(self, event):
+ """!Add raster flow arrows map"""
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('rastarrow')
+
+ def AddRastnum(self, event):
+ """!Add raster map with cell numbers"""
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('rastnum')
+
+ def AddVector(self, event):
+ """!Add vector layer"""
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('vector')
+
+ def AddThemeMap(self, event):
+ """!Add thematic map layer"""
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('thememap')
+
+ def AddThemeChart(self, event):
+ """!Add thematic chart layer"""
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('themechart')
+
+ def OnAddCommand(self, event):
+ """!Add command line layer"""
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay(show=False)
+
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('command')
+
+ # show map display
+ self.curr_page.maptree.mapdisplay.Show()
+
+ def OnAddGroup(self, event):
+ """!Add layer group"""
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay(show=False)
+
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('group')
+
+ # show map display
+ self.curr_page.maptree.mapdisplay.Show()
+
+ def AddGrid(self, event):
+ """!Add layer grid"""
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('grid')
+
+ def AddGeodesic(self, event):
+ """!Add layer geodesic"""
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('geodesic')
+
+ def AddRhumb(self, event):
+ """!Add layer rhumb"""
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('rhumb')
+
+ def OnAddLabels(self, event):
+ """!Add layer vector labels"""
+ # start new map display if no display is available
+ if not self.curr_page:
+ self.NewDisplay(show=False)
+
+ self.notebook.SetSelection(0)
+ self.curr_page.maptree.AddLayer('labels')
+
+ # show map display
+ self.curr_page.maptree.mapdisplay.Show()
+
+ def OnDeleteLayer(self, event):
+ """
+ Delete selected map display layer in GIS Manager tree widget
+ """
+ if not self.curr_page or not self.curr_page.maptree.layer_selected:
+ self.MsgNoLayerSelected()
+ return
+
+ if UserSettings.Get(group='manager', key='askOnRemoveLayer', subkey='enabled'):
+ layerName = ''
+ for item in self.curr_page.maptree.GetSelections():
+ name = str(self.curr_page.maptree.GetItemText(item))
+ idx = name.find('(opacity')
+ if idx > -1:
+ layerName += '<' + name[:idx].strip(' ') + '>,\n'
+ else:
+ layerName += '<' + name + '>,\n'
+ layerName = layerName.rstrip(',\n')
+
+ if len(layerName) > 2: # <>
+ message = _("Do you want to remove map layer(s)\n%s\n"
+ "from layer tree?") % layerName
+ else:
+ message = _("Do you want to remove selected map layer(s) "
+ "from layer tree?")
+
+ dlg = wx.MessageDialog (parent=self, message=message,
+ caption=_("Remove map layer"),
+ style=wx.YES_NO | wx.YES_DEFAULT | wx.CANCEL | wx.ICON_QUESTION)
+
+ if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
+ dlg.Destroy()
+ return
+
+ dlg.Destroy()
+
+ for layer in self.curr_page.maptree.GetSelections():
+ if self.curr_page.maptree.GetPyData(layer)[0]['type'] == 'group':
+ self.curr_page.maptree.DeleteChildren(layer)
+ self.curr_page.maptree.Delete(layer)
+
+ def OnKey(self, event):
+ """!Check hotkey"""
+ try:
+ kc = chr(event.GetKeyCode())
+ except ValueError:
+ event.Skip()
+ return
+
+ if event.AltDown():
+ if kc == 'R':
+ self.OnAddRaster(None)
+ elif kc == 'V':
+ self.OnAddVector(None)
+
+ event.Skip()
+
+ def OnCloseWindow(self, event):
+ """!Cleanup when wxGUI is quit"""
+ self.Destroy()
+
+ def MsgNoLayerSelected(self):
+ """!Show dialog message 'No layer selected'"""
+ wx.MessageBox(parent=self,
+ message=_("No map layer selected. Operation cancelled."),
+ caption=_("Message"),
+ style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
+
+
More information about the grass-commit
mailing list