[GRASS-SVN] r39407 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Oct 5 04:02:10 EDT 2009
Author: martinl
Date: 2009-10-05 04:02:08 -0400 (Mon, 05 Oct 2009)
New Revision: 39407
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
Log:
use vdigit's PseudoDC only during digitize session
(merge from trunk, r39406)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2009-10-05 07:58:25 UTC (rev 39406)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2009-10-05 08:02:08 UTC (rev 39407)
@@ -1,4 +1,4 @@
-"""
+"""!
@package mapdisp.py
@brief GIS map display canvas, with toolbar for various display
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py 2009-10-05 07:58:25 UTC (rev 39406)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py 2009-10-05 08:02:08 UTC (rev 39407)
@@ -41,7 +41,7 @@
from vdigit import VDigitCategoryDialog
from vdigit import VDigitZBulkDialog
from vdigit import VDigitDuplicatesDialog
-from vdigit import PseudoDC
+from vdigit import PseudoDC as VDigitPseudoDC
class MapWindow(object):
"""!
@@ -225,14 +225,7 @@
# platforms at initialization, but little harm done.
### self.OnSize(None)
- # create PseudoDC used for background map, map decorations like scales and legends
- self.pdc = PseudoDC()
- # used for digitization tool
- self.pdcVector = None
- # decorations (region box, etc.)
- self.pdcDec = PseudoDC()
- # pseudoDC for temporal objects (select box, measurement tool, etc.)
- self.pdcTmp = PseudoDC()
+ self.DefinePseudoDC()
# redraw all pdc's, pdcTmp layer is redrawn always (speed issue)
self.redrawAll = True
@@ -245,6 +238,25 @@
self.dragid = -1
self.lastpos = (0, 0)
+ def DefinePseudoDC(self, vdigit = False):
+ """!Define PseudoDC class to use
+
+ @vdigit True to use PseudoDC from vdigit
+ """
+ if vdigit:
+ PseudoDC = VDigitPseudoDC
+ else:
+ PseudoDC = wx.PseudoDC
+
+ # create PseudoDC used for background map, map decorations like scales and legends
+ self.pdc = PseudoDC()
+ # used for digitization tool
+ self.pdcVector = None
+ # decorations (region box, etc.)
+ self.pdcDec = PseudoDC()
+ # pseudoDC for temporal objects (select box, measurement tool, etc.)
+ self.pdcTmp = PseudoDC()
+
def Draw(self, pdc, img=None, drawid=None, pdctype='image', coords=[0, 0, 0, 0]):
"""!
Draws map and overlay decorations
@@ -677,8 +689,9 @@
# re-calculate threshold for digitization tool
self.parent.digit.driver.GetThreshold()
# draw map
- self.pdcVector.Clear()
- self.pdcVector.RemoveAll()
+ if self.pdcVector:
+ self.pdcVector.Clear()
+ self.pdcVector.RemoveAll()
try:
item = self.tree.FindItemByData('maplayer', digitToolbar.GetLayer())
except TypeError:
@@ -2543,15 +2556,15 @@
if l.type == 'raster':
rast.append(l.name)
elif l.type == 'vector':
- if self.parent.digit and l.name == self.parent.digit.map and \
- self.parent.digit.type == 'vdigit':
+ digitToolbar = self.parent.toolbars['vdigit']
+ if digitToolbar and digitToolbar.GetLayer() == l.name:
w, s, b, e, n, t = self.parent.digit.driver.GetMapBoundingBox()
self.Map.GetRegion(n=n, s=s, w=w, e=e,
update=True)
updated = True
else:
vect.append(l.name)
-
+
if not updated:
self.Map.GetRegion(rast = rast,
vect = vect,
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py 2009-10-05 07:58:25 UTC (rev 39406)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py 2009-10-05 08:02:08 UTC (rev 39407)
@@ -1109,16 +1109,17 @@
### 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)
+ if mapLayer:
+ 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)
- 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
@@ -1131,9 +1132,13 @@
self.parent.digit.SetMapName(mapLayer.GetName())
except gcmd.DigitError, e:
self.mapLayer = None
+ self.StopEditing()
print >> sys.stderr, e # wxMessageBox
return False
-
+
+ # use vdigit's PseudoDC
+ self.parent.MapWindow.DefinePseudoDC(vdigit = True)
+
# update toolbar
self.combo.SetValue(mapLayer.GetName())
self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
@@ -1158,42 +1163,43 @@
return True
- def StopEditing (self):
+ def StopEditing(self):
"""!Stop editing of selected vector map layer.
@return True on success
@return False on failure
"""
- if not self.mapLayer:
- return False
+ # use wx's PseudoDC
+ self.parent.MapWindow.DefinePseudoDC(vdigit = 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()
+ if self.mapLayer:
+ Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
+ 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.statusbar.SetStatusText(_("Please wait, "
+ "closing and rebuilding topology of "
+ "vector map <%s>...") % self.mapLayer.GetName(),
+ 0)
- self.parent.digit.SetMapName(None) # -> close map
+ 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)
+ # 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"])
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py 2009-10-05 07:58:25 UTC (rev 39406)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py 2009-10-05 08:02:08 UTC (rev 39407)
@@ -34,6 +34,7 @@
import string
import copy
import textwrap
+import traceback
from threading import Thread
@@ -122,9 +123,9 @@
ret = self.driver.Reset(self.map)
except StandardError, e:
raise gcmd.DigitError(parent=self.mapWindow.parent,
- message="%s %s (%s)" % (_('Unable to initialize display driver, '
- 'see README file for more information.\n\n'
- 'Details:'), e, errorMsg))
+ message="%s %s (%s)" % (_("Unable to initialize display driver of vector "
+ "digitizer. See 'Command output' for details.\n\n"
+ "Details:"), e, errorMsg))
if map and ret == -1:
raise gcmd.DigitError(parent=self.mapWindow.parent,
@@ -232,15 +233,22 @@
@param settings initial settings of digitization tool
"""
AbstractDigit.__init__(self, mapwindow)
-
+
+ if not mapwindow.parent.IsStandalone():
+ self.log = mapwindow.parent.GetLayerManager().goutput.cmd_stderr
+ else:
+ self.log = sys.stderr
+
+ self.toolbar = mapwindow.parent.toolbars['vdigit']
+
try:
self.digit = wxvdigit.Digit(self.driver.GetDevice(),
mapwindow)
- except (ImportError, NameError):
+ except (ImportError, NameError, TypeError):
+ # print traceback
+ traceback.print_exc(file = self.log)
self.digit = None
-
- self.toolbar = mapwindow.parent.toolbars['vdigit']
-
+
self.UpdateSettings()
def __del__(self):
@@ -699,6 +707,9 @@
def GetUndoLevel(self):
"""!Get undo level (number of active changesets)"""
+ if not self.digit:
+ return -1
+
return self.digit.GetUndoLevel()
def UpdateSettings(self):
@@ -841,7 +852,8 @@
@param pdc wx.PseudoDC instance
"""
- self.__display.SetDevice(pdc)
+ if self.__display:
+ self.__display.SetDevice(pdc)
def Reset(self, map):
"""!Reset map
@@ -879,6 +891,9 @@
@return wx.Image instance
"""
+ if not self.__display:
+ return 0
+
nlines = self.__display.DrawMap(True) # force
Debug.msg(3, "CDisplayDriver.DrawMap(): nlines=%d" % nlines)
@@ -931,6 +946,9 @@
@param grassId if grassId is True returns GRASS ids, otherwise
internal ids of objects drawn in PseudoDC"""
+ if not self.__display:
+ return list()
+
if grassId:
selected = self.__display.GetSelected(True)
else:
@@ -1017,6 +1035,8 @@
"""!Set geographical region
Needed for 'cell2pixel' conversion"""
+ if not self.__display:
+ return
map = self.mapwindow.Map
reg = map.region
More information about the grass-commit
mailing list