[GRASS-SVN] r59132 - in grass/trunk/gui/wxpython: gui_core mapwin
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 24 02:14:25 PST 2014
Author: turek
Date: 2014-02-24 02:14:25 -0800 (Mon, 24 Feb 2014)
New Revision: 59132
Modified:
grass/trunk/gui/wxpython/gui_core/gselect.py
grass/trunk/gui/wxpython/gui_core/widgets.py
grass/trunk/gui/wxpython/mapwin/graphics.py
Log:
coordinates select: show inserted coordinates in mapwindow
Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py 2014-02-24 09:17:27 UTC (rev 59131)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py 2014-02-24 10:14:25 UTC (rev 59132)
@@ -57,7 +57,7 @@
print >> sys.stderr, _("Unable to import pyGRASS: %s\n"
"Some functionality will be not accessible") % e
-from gui_core.widgets import ManageSettingsWidget
+from gui_core.widgets import ManageSettingsWidget, CoordinatesValidator
from core.gcmd import RunCommand, GError, GMessage
from core.utils import GetListOfLocations, GetListOfMapsets, \
@@ -66,7 +66,6 @@
from core.utils import GetVectorNumberOfLayers, _
from core.settings import UserSettings
from core.debug import Debug
-
from grass.pydispatch.signal import Signal
class Select(wx.combo.ComboCtrl):
@@ -2126,16 +2125,18 @@
self._giface = giface
self.multiple = multiple
self.mapWin = None
+ self.drawMapWin = None
+
+ super(CoordinatesSelect, self).__init__(parent=parent, id=wx.ID_ANY)
- super(CoordinatesSelect, self).__init__(parent = parent, id = wx.ID_ANY)
+ self.coordsField = wx.TextCtrl(parent=self, id=wx.ID_ANY,
+ size=globalvar.DIALOG_TEXTCTRL_SIZE,
+ validator=CoordinatesValidator())
- self.coordsField = wx.TextCtrl(parent = self, id = wx.ID_ANY,
- size = globalvar.DIALOG_TEXTCTRL_SIZE)
-
icon = wx.Bitmap(os.path.join(globalvar.ETCICONDIR, "grass", "pointer.png"))
- self.buttonInsCoords = buttons.ThemedGenBitmapToggleButton(parent = self, id = wx.ID_ANY,
- bitmap = icon,
- size = globalvar.DIALOG_COLOR_SIZE)
+ self.buttonInsCoords = buttons.ThemedGenBitmapToggleButton(parent=self, id=wx.ID_ANY,
+ bitmap=icon,
+ size=globalvar.DIALOG_COLOR_SIZE)
self.registered = False
self.buttonInsCoords.Bind(wx.EVT_BUTTON, self._onClick)
switcher = self._giface.GetMapDisplay().GetToolSwitcher()
@@ -2143,6 +2144,7 @@
btnId=self.buttonInsCoords.GetId(),
toggleHandler=self.buttonInsCoords.SetValue)
self._doLayout()
+ self.coordsField.Bind(wx.EVT_TEXT, lambda event : self._draw())
def _doLayout(self):
self.dialogSizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -2172,6 +2174,42 @@
self.registered = False
return
+
+ def drawCleanUp(self):
+ if self.drawMapWin:
+ self.drawMapWin.UnregisterGraphicsToDraw(self.pointsToDraw)
+
+ def _draw(self):
+ """!Draws points representing inserted coordinates in mapwindow."""
+ if self.drawMapWin != self.mapWin:
+ self.drawCleanUp()
+ if self.mapWin:
+ self.drawMapWin = self.mapWin
+ self.pointsToDraw = self.drawMapWin.RegisterGraphicsToDraw(graphicsType="point")
+
+ if self.drawMapWin:
+ items = self.pointsToDraw.GetAllItems()
+ for i in items:
+ self.pointsToDraw.DeleteItem(i)
+
+ coords = self._getCoords()
+ if coords is not None:
+ for i in range(len(coords)/2):
+ i = i * 2
+ self.pointsToDraw.AddItem(coords=(coords[i], coords[i + 1]))
+
+ self._giface.updateMap.emit(render=False, renderVector=False)
+
+ def _getCoords(self):
+ """!Get list of coordinates.
+
+ @return None if values are not valid
+ """
+ if self.coordsField.GetValidator().Validate():
+ return self.coordsField.GetValue().split(',')
+
+ return None
+
def _onMapClickHandler(self, event):
"""!Gets coordinates from mapwindow"""
if event == "unregistered":
@@ -2184,12 +2222,17 @@
prevCoords = self.coordsField.GetValue().strip()
if prevCoords != "":
prevCoords += ","
-
+
value = prevCoords + str(e) + "," + str(n)
self.coordsField.SetValue(value)
+ self._draw()
+
def OnClose(self):
"""!Unregistrates _onMapClickHandler from mapWin"""
+ self.drawCleanUp()
+ self._giface.updateMap.emit(render=False, renderVector=False)
+
switcher = self._giface.GetMapDisplay().GetToolSwitcher()
switcher.RemoveCustomToolFromGroup(self.buttonInsCoords.GetId())
if self.mapWin and self.registered:
Modified: grass/trunk/gui/wxpython/gui_core/widgets.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/widgets.py 2014-02-24 09:17:27 UTC (rev 59131)
+++ grass/trunk/gui/wxpython/gui_core/widgets.py 2014-02-24 10:14:25 UTC (rev 59132)
@@ -11,6 +11,7 @@
- widgets::SymbolButton
- widgets::StaticWrapText
- widgets::BaseValidator
+ - widgets::CoordinatesValidator
- widgets::IntegerValidator
- widgets::FloatValidator
- widgets::GListCtrl
@@ -21,7 +22,7 @@
- widgets::BarscalesComboBox
- widgets::NArrowsComboBox
-(C) 2008-2013 by the GRASS Development Team
+(C) 2008-2014 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.
@@ -494,16 +495,26 @@
try:
self.type(text)
except ValueError:
- textCtrl.SetBackgroundColour("grey")
- textCtrl.SetFocus()
- textCtrl.Refresh()
+ self._notvalid()
return False
+ self._valid()
+ return True
+
+ def _notvalid(self):
+ textCtrl = self.GetWindow()
+
+ textCtrl.SetBackgroundColour("grey")
+ textCtrl.SetFocus()
+ textCtrl.Refresh()
+
+ def _valid(self):
+ textCtrl = self.GetWindow()
+
sysColor = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)
textCtrl.SetBackgroundColour(sysColor)
textCtrl.Refresh()
-
return True
def TransferToWindow(self):
@@ -512,6 +523,38 @@
def TransferFromWindow(self):
return True # Prevent wxDialog from complaining.
+class CoordinatesValidator(BaseValidator):
+ """!Validator for coordinates input (list of floats separated by comma)"""
+
+ def __init__(self):
+ BaseValidator.__init__(self)
+
+ def Validate(self):
+ """Validate input"""
+
+ textCtrl = self.GetWindow()
+ text = textCtrl.GetValue()
+ if text:
+ try:
+ text = text.split(',')
+
+ for t in text:
+ float(t)
+
+ if len(text)%2 != 0:
+ return False
+
+ except ValueError:
+ self._notvalid()
+ return False
+
+ self._valid()
+ return True
+
+ def Clone(self):
+ """!Clone validator"""
+ return CoordinatesValidator()
+
class IntegerValidator(BaseValidator):
"""!Validator for floating-point input"""
def __init__(self):
Modified: grass/trunk/gui/wxpython/mapwin/graphics.py
===================================================================
--- grass/trunk/gui/wxpython/mapwin/graphics.py 2014-02-24 09:17:27 UTC (rev 59131)
+++ grass/trunk/gui/wxpython/mapwin/graphics.py 2014-02-24 10:14:25 UTC (rev 59132)
@@ -98,10 +98,14 @@
coords = item.GetCoords()
size = self.properties["size"]
- self.properties["text"]['coords'] = [coords[0] + size, coords[1] + size, size, size]
- self.properties["text"]['color'] = self.parentMapWin.pen.GetColour()
- self.properties["text"]['text'] = item.GetPropertyVal("label")
-
+ label = item.GetPropertyVal("label")
+ if label is None:
+ self.properties["text"] = None
+ else:
+ self.properties["text"]['coords'] = [coords[0] + size, coords[1] + size, size, size]
+ self.properties["text"]['color'] = self.parentMapWin.pen.GetColour()
+ self.properties["text"]['text'] = label
+
self.drawFunc(pdc=pdc, drawid=item.GetId(),
coords=coords,
text=self.properties["text"],
More information about the grass-commit
mailing list