[GRASS-SVN] r42723 - grass-addons/gui/wxpython/wx.path
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 8 10:46:39 EDT 2010
Author: rashadkm
Date: 2010-07-08 14:46:39 +0000 (Thu, 08 Jul 2010)
New Revision: 42723
Modified:
grass-addons/gui/wxpython/wx.path/wx.path.py
Log:
minor fixes; errors display when anything goes wrong
Modified: grass-addons/gui/wxpython/wx.path/wx.path.py
===================================================================
--- grass-addons/gui/wxpython/wx.path/wx.path.py 2010-07-08 13:54:11 UTC (rev 42722)
+++ grass-addons/gui/wxpython/wx.path/wx.path.py 2010-07-08 14:46:39 UTC (rev 42723)
@@ -56,28 +56,43 @@
import toolbars
from preferences import globalSettings as UserSettings
from icon import Icons
-from mapdisp_command import Command
-from mapdisp_window import BufferedWindow
+from mapdisp import Command
+from mapdisp import BufferedWindow
from mapdisp import MapFrame
from debug import Debug
import images
import gcmd
from grass.script import core as grass
+import toolbars
+
imagepath = images.__path__[0]
sys.path.append(imagepath)
class NetworkPath(MapFrame):
- def __init__(self, parent=None, id=wx.ID_ANY, title=_("v.net.path [vector, networking]"),
- style=wx.DEFAULT_FRAME_STYLE, toolbars=["map"],Map=None,size=wx.DefaultSize):
+ def __init__(self, parent=None, id=wx.ID_ANY, title=_("GRASS GIS - Map display"),
+ pos=wx.DefaultPosition, size=wx.DefaultSize,
+ style=wx.DEFAULT_FRAME_STYLE, toolbars=["map"],
+ tree=None, notebook=None, gismgr=None, page=None,
+ Map=None, auimgr=None):
self.Map = Map
+ self.gismanager = gismgr # GIS Manager object
+ self.Map = Map # instance of render.Map
+ self.tree = tree # GIS Manager layer tree object
+ self.page = page # Notebook page holding the layer tree
+ self.layerbook = notebook # GIS Manager layer tree notebook
+ self.parent = parent
#
# available cursors
#
+
+ self.counter = 0
+ # available cursors
+ #
self.cursors = {
# default: cross
# "default" : wx.StockCursor(wx.CURSOR_DEFAULT),
@@ -87,20 +102,16 @@
"pencil" : wx.StockCursor(wx.CURSOR_PENCIL),
"sizenwse": wx.StockCursor(wx.CURSOR_SIZENWSE)
}
-
- wx.Frame.__init__(self, parent, id, title, style = style)
-
+ wx.Frame.__init__(self, parent, id, title, pos, size, style)
+ self.SetName("MapWindow")
+
#
# set the size & system icon
#
- self.SetClientSize(self.GetSize())
+ self.SetClientSize(size)
self.iconsize = (16, 16)
- self.SetName("MapWindow")
- self.counter = 0
- self.points =[]
-
self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass_map.ico'), wx.BITMAP_TYPE_ICO))
#
@@ -109,9 +120,6 @@
# self._mgr = auimgr
self._mgr = wx.aui.AuiManager(self)
- self._layerManager = None
- self.georectifying =None
-
#
# Add toolbars
#
@@ -122,109 +130,78 @@
for toolb in toolbars:
self.AddToolbar(toolb)
-
-
#
# Add statusbar
#
self.statusbar = self.CreateStatusBar(number=4, style=0)
self.statusbar.SetStatusWidths([-5, -2, -1, -1])
- self.statusbarWin = dict()
- self.statusbarWin['toggle'] = wx.Choice(self.statusbar, wx.ID_ANY,
- choices = globalvar.MAP_DISPLAY_STATUSBAR_MODE)
- self.statusbarWin['toggle'].SetSelection(UserSettings.Get(group='display',
- key='statusbarMode',
- subkey='selection'))
- self.statusbar.Bind(wx.EVT_CHOICE, self.OnToggleStatus, self.statusbarWin['toggle'])
+ self.toggleStatus = wx.Choice(self.statusbar, wx.ID_ANY,
+ choices = globalvar.MAP_DISPLAY_STATUSBAR_MODE)
+ self.toggleStatus.SetSelection(UserSettings.Get(group='display', key='statusbarMode', subkey='selection'))
+ self.statusbar.Bind(wx.EVT_CHOICE, self.OnToggleStatus, self.toggleStatus)
# auto-rendering checkbox
- self.statusbarWin['render'] = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Render"))
- self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleRender, self.statusbarWin['render'])
- self.statusbarWin['render'].SetValue(UserSettings.Get(group='display',
- key='autoRendering',
- subkey='enabled'))
- self.statusbarWin['render'].SetToolTip(wx.ToolTip (_("Enable/disable auto-rendering")))
+ self.autoRender = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
+ label=_("Render"))
+ self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleRender, self.autoRender)
+ self.autoRender.SetValue(UserSettings.Get(group='display', key='autoRendering', subkey='enabled'))
+ self.autoRender.SetToolTip(wx.ToolTip (_("Enable/disable auto-rendering")))
# show region
- self.statusbarWin['region'] = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Show computational extent"))
- self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleShowRegion, self.statusbarWin['region'])
+ self.showRegion = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
+ label=_("Show computational extent"))
+ self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleShowRegion, self.showRegion)
- self.statusbarWin['region'].SetValue(False)
- self.statusbarWin['region'].Hide()
- self.statusbarWin['region'].SetToolTip(wx.ToolTip (_("Show/hide computational "
- "region extent (set with g.region). "
- "Display region drawn as a blue box inside the "
- "computational region, "
- "computational region inside a display region "
- "as a red box).")))
+ self.showRegion.SetValue(False)
+ self.showRegion.Hide()
+ self.showRegion.SetToolTip(wx.ToolTip (_("Show/hide computational "
+ "region extent (set with g.region). "
+ "Display region drawn as a blue box inside the "
+ "computational region, "
+ "computational region inside a display region "
+ "as a red box).")))
# set resolution
- self.statusbarWin['resolution'] = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Constrain display resolution to computational settings"))
- self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleResolution, self.statusbarWin['resolution'])
- self.statusbarWin['resolution'].SetValue(UserSettings.Get(group='display', key='compResolution', subkey='enabled'))
- self.statusbarWin['resolution'].Hide()
- self.statusbarWin['resolution'].SetToolTip(wx.ToolTip (_("Constrain display resolution "
- "to computational region settings. "
- "Default value for new map displays can "
- "be set up in 'User GUI settings' dialog.")))
+ self.compResolution = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
+ label=_("Constrain display resolution to computational settings"))
+ self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleResolution, self.compResolution)
+ self.compResolution.SetValue(UserSettings.Get(group='display', key='compResolution', subkey='enabled'))
+ self.compResolution.Hide()
+ self.compResolution.SetToolTip(wx.ToolTip (_("Constrain display resolution "
+ "to computational region settings. "
+ "Default value for new map displays can "
+ "be set up in 'User GUI settings' dialog.")))
# map scale
- self.statusbarWin['mapscale'] = wx.ComboBox(parent = self.statusbar, id = wx.ID_ANY,
- style = wx.TE_PROCESS_ENTER,
- size=(150, -1))
- self.statusbarWin['mapscale'].SetItems(['1:1000',
- '1:5000',
- '1:10000',
- '1:25000',
- '1:50000',
- '1:100000',
- '1:1000000'])
- self.statusbarWin['mapscale'].Hide()
- self.statusbar.Bind(wx.EVT_TEXT_ENTER, self.OnChangeMapScale, self.statusbarWin['mapscale'])
- self.statusbar.Bind(wx.EVT_COMBOBOX, self.OnChangeMapScale, self.statusbarWin['mapscale'])
+ self.mapScale = wx.TextCtrl(parent=self.statusbar, id=wx.ID_ANY,
+ value="", style=wx.TE_PROCESS_ENTER,
+ size=(150, -1))
+ self.mapScale.Hide()
+ self.statusbar.Bind(wx.EVT_TEXT_ENTER, self.OnChangeMapScale, self.mapScale)
- # go to
- self.statusbarWin['goto'] = wx.TextCtrl(parent=self.statusbar, id=wx.ID_ANY,
- value="", style=wx.TE_PROCESS_ENTER,
- size=(300, -1))
- self.statusbarWin['goto'].Hide()
- self.statusbar.Bind(wx.EVT_TEXT_ENTER, self.OnGoTo, self.statusbarWin['goto'])
-
- # projection
- self.statusbarWin['projection'] = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Use defined projection"))
- self.statusbarWin['projection'].SetValue(False)
- size = self.statusbarWin['projection'].GetSize()
- self.statusbarWin['projection'].SetMinSize((size[0] + 150, size[1]))
- self.statusbarWin['projection'].SetToolTip(wx.ToolTip (_("Reproject coordinates displayed "
- "in the statusbar. Projection can be "
- "defined in GUI preferences dialog "
- "(tab 'Display')")))
- self.statusbarWin['projection'].Hide()
-
# mask
- self.statusbarWin['mask'] = wx.StaticText(parent = self.statusbar, id = wx.ID_ANY,
+ self.maskInfo = wx.StaticText(parent = self.statusbar, id = wx.ID_ANY,
label = '')
- self.statusbarWin['mask'].SetForegroundColour(wx.Colour(255, 0, 0))
+ self.maskInfo.SetForegroundColour(wx.Colour(255, 0, 0))
+
# on-render gauge
- self.statusbarWin['progress'] = wx.Gauge(parent=self.statusbar, id=wx.ID_ANY,
+ self.onRenderGauge = wx.Gauge(parent=self.statusbar, id=wx.ID_ANY,
range=0, style=wx.GA_HORIZONTAL)
- self.statusbarWin['progress'].Hide()
+ self.onRenderGauge.Hide()
self.StatusbarReposition() # reposition statusbar
#
# Init map display (buffered DC & set default cursor)
#
- self.MapWindow2D = BufferedWindow(self, id=wx.ID_ANY,Map=self.Map)
+ self.MapWindow2D = BufferedWindow(self, id=wx.ID_ANY,
+ Map=self.Map, tree=self.tree, gismgr=self.gismanager)
# default is 2D display mode
self.MapWindow = self.MapWindow2D
self.MapWindow.Bind(wx.EVT_MOTION, self.OnMotion)
self.MapWindow.SetCursor(self.cursors["default"])
- self.MapWindow.Bind(wx.EVT_LEFT_DCLICK,self.OnButtonDClick)
# used by Nviz (3D display mode)
self.MapWindow3D = None
+ self.MapWindow.Bind(wx.EVT_LEFT_DCLICK,self.OnButtonDClick)
+
#
# initialize region values
#
@@ -235,18 +212,21 @@
#
#self.Bind(wx.EVT_ACTIVATE, self.OnFocus)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
- # self.Bind(render.EVT_UPDATE_PRGBAR, self.OnUpdateProgress)
+ self.Bind(render.EVT_UPDATE_PRGBAR, self.OnUpdateProgress)
#
# Update fancy gui style
#
self._mgr.AddPane(self.MapWindow, wx.aui.AuiPaneInfo().CentrePane().
- Dockable(False).BestSize((-1,-1)).
- CloseButton(False).DestroyOnClose(True).
- Layer(0))
+ Dockable(False).BestSize((-1,-1)).
+ CloseButton(False).DestroyOnClose(True).
+ Layer(0))
self._mgr.Update()
-
+ #
+ # Init print module and classes
+ #
+ #self.printopt = disp_print.PrintOptions(self, self.MapWindow)
#
# Initialization of digitization tool
@@ -272,46 +252,83 @@
self.decorationDialog = None # decoration/overlays
- self.Maximize()
+ #
+ # Re-use dialogs
+ #
+ self.mapname = 'roads@' + grass.gisenv()['MAPSET']
+ self.cmd= ['d.vect', str("map=" + self.mapname),'width=4']
+ self.Map.AddLayer(type='vector', name=self.mapname, command=self.cmd)
+ self.MapWindow.UpdateMap(render=True)
+ self.dialogs = {}
+ self.dialogs['attributes'] = None
+ self.dialogs['category'] = None
+ self.dialogs['barscale'] = None
+ self.dialogs['legend'] = None
+
+ self.decorationDialog = None # decoration/overlays
+
+ #self.Maximize()
+ self.points = []
+
+
+
+
+
def OnButtonDClick(self,event):
+ self.mapname = 'graph@' + grass.gisenv()['MAPSET']
+ self.Map.RemoveLayer(name=self.mapname)
+ self.MapWindow.UpdateMap(render=True)
- precision = int(UserSettings.Get(group = 'projection', key = 'format',
- subkey = 'precision'))
+ # precision = int(UserSettings.Get(group = 'projection', key = 'format',
+ # subkey = 'precision'))
try:
e, n = self.MapWindow.Pixel2Cell(event.GetPositionTuple())
+ print e,n
except AttributeError:
return
self.counter = self.counter + 1
- point =("%.*f|%.*f" % (precision, e, precision, n))
+ point =("%f|%f" % ( e, n))
self.points.append(point + '|point')
if self.counter == 2:
f =open("tmp1",'w')
for p in self.points:
- f.write("%s\n" % p)
+ f.write("%s\n" % p)
f.close()
f =open("tmp2",'w')
f.write("%d %d %d\n" %(1,1,2) )
f.close()
-
- #print self.points
- command =["g.remove",'vect=vnet_out,startend,tmp_vnet_path']
- gcmd.CommandThread(command,stdout=None,stderr=None).run()
- command =["v.in.ascii",'input=tmp1','output=startend']
+ command =["g.remove",'vect=path,vnet,startend']
gcmd.CommandThread(command,stdout=None,stderr=None).run()
+
- command=["v.net", "input=myroads",'points=startend', 'out=vnet_out', 'op=connect', 'thresh=200']
- gcmd.CommandThread(command).run()
+# command =["v.in.ascii",'input=tmp1','output=startend']
+ z =gcmd.RunCommand('v.in.ascii',input='tmp1',output='startend')
- command=["v.net.path", 'vnet_out','afcol=forward', 'abcol=backward', 'out=tmp_vnet_path','file=tmp2']
- gcmd.CommandThread(command).run()
+ if z == 1:
+ print "error executing v.in.ascii"
+ return 1
- self.mapname = 'tmp_vnet_path@' + grass.gisenv()['MAPSET']
+ #command=["v.net", "input=roads",'points=startend', 'output=vnet', 'op=connect', 'thresh=200']
+ y=gcmd.RunCommand('v.net', input='roads',points='startend', output='vnet', op='connect', thresh='200')
+ if y == 1:
+ print "error executing v.net"
+ return 1
+
+
+ #command=["v.net.path", 'input=vnet', 'output=path','file=tmp2']
+ x= gcmd.RunCommand('v.net.path', input='vnet', output='path', file='tmp2')
+ if x == 1:
+ print "error executing v.net.path"
+ return 1
+
+
+ self.mapname = 'path@'+ grass.gisenv()['MAPSET']
self.cmd= ['d.vect', str("map=" + self.mapname),'col=red','width=2']
self.Map.AddLayer(type='vector', name=self.mapname, command=self.cmd)
self.MapWindow.UpdateMap(render=True)
@@ -319,6 +336,7 @@
self.points=[]
+
def __InitDisplay(self):
"""
Initialize map display, set dimensions and map region
@@ -337,83 +355,18 @@
"""!Add defined toolbar to the window
"""
# default toolbar
- self.toolbars['map'] = Toolbar(self, self.Map)
+ self.toolbars['map'] = toolbars.MapToolbar(self, self.Map)
- self._mgr.AddPane(self.toolbars['map'],
- wx.aui.AuiPaneInfo().
- Name("maptoolbar").Caption(_("Map Toolbar")).
- ToolbarPane().Top().
- LeftDockable(False).RightDockable(False).
- BottomDockable(False).TopDockable(True).
- CloseButton(False).Layer(2).
- BestSize((self.toolbars['map'].GetSize())))
+ self._mgr.AddPane(self.toolbars['map'].toolbar,
+ wx.aui.AuiPaneInfo().
+ Name("maptoolbar").Caption(_("Map Toolbar")).
+ ToolbarPane().Top().
+ LeftDockable(False).RightDockable(False).
+ BottomDockable(False).TopDockable(True).
+ CloseButton(False).Layer(2).
+ BestSize((self.toolbars['map'].GetToolbar().GetSize())))
-class Toolbar(toolbars.MapToolbar):
- def __init__(self, parent, mapcontent):
- """!Map Display constructor
-
- @param parent reference to MapFrame
- @param mapcontent reference to render.Map (registred by MapFrame)
- """
- self.mapcontent = mapcontent # render.Map
- toolbars.AbstractToolbar.__init__(self, parent = parent) # MapFrame
-
- self.InitToolbar(self.ToolbarData())
-
- # optional tools
-
- self.action = { 'id' : self.pointer }
- self.defaultAction = { 'id' : self.pointer,
- 'bind' : self.parent.OnPointer }
-
- self.OnTool(None)
-
- self.EnableTool(self.zoomback, False)
-
- self.FixSize(width = 90)
-
- def ToolbarData(self):
- """!Toolbar data"""
-
- 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.zoomextent = wx.NewId()
-
-
- # tool, label, bitmap, kind, shortHelp, longHelp, handler
- return (
-
- (self.pointer, "pointer", Icons["pointer"].GetBitmap(),
- wx.ITEM_CHECK, Icons["pointer"].GetLabel(), Icons["pointer"].GetDesc(),
- self.parent.OnPointer),
- (self.query, "query", Icons["query"].GetBitmap(),
- wx.ITEM_CHECK, Icons["query"].GetLabel(), Icons["query"].GetDesc(),
- self.parent.OnQuery),
- (self.pan, "pan", Icons["pan"].GetBitmap(),
- wx.ITEM_CHECK, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
- self.parent.OnPan),
- (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
- wx.ITEM_CHECK, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
- self.parent.OnZoomIn),
- (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
- wx.ITEM_CHECK, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
- self.parent.OnZoomOut),
- (self.zoomextent, "zoom_extent", Icons["zoom_extent"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["zoom_extent"].GetLabel(), Icons["zoom_extent"].GetDesc(),
- self.parent.OnZoomToMap),
- (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
- self.parent.OnZoomBack),
- )
-
-
-
class PathApp(wx.App):
"""
MapApp class
@@ -424,10 +377,8 @@
Map = render.Map()
else:
Map = None
- self.mapname = 'myroads at PERMANENT'
- self.cmd= ['d.vect', str("map=" + self.mapname)]
- Map.AddLayer(type='vector', name=self.mapname, command=self.cmd)
+
self.frame = NetworkPath(parent=None, id=wx.ID_ANY, Map=Map,
size=globalvar.MAP_WINDOW_SIZE)
More information about the grass-commit
mailing list