[GRASS-SVN] r64833 - grass/trunk/gui/wxpython/gui_core
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Mar 10 10:54:38 PDT 2015
Author: martinl
Date: 2015-03-10 10:54:38 -0700 (Tue, 10 Mar 2015)
New Revision: 64833
Modified:
grass/trunk/gui/wxpython/gui_core/forms.py
grass/trunk/gui/wxpython/gui_core/gselect.py
grass/trunk/gui/wxpython/gui_core/vselect.py
Log:
wxGUI: gselect.VectorCategorySelect() implemented by Matej Krejci (krejcmat)
Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py 2015-03-10 14:53:31 UTC (rev 64832)
+++ grass/trunk/gui/wxpython/gui_core/forms.py 2015-03-10 17:54:38 UTC (rev 64833)
@@ -1621,6 +1621,30 @@
proportion = 0,
flag = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT,
border = 5)
+
+ elif prompt in ('cat', 'cats'):
+ # interactive selection of vector categories if layer manager is accessible
+ if self._giface:
+ win = gselect.VectorCategorySelect(parent = which_panel, giface = self._giface, task=self.task)
+
+ p['wxId'] = [win.GetTextWin().GetId()]
+ win.GetTextWin().Bind(wx.EVT_TEXT, self.OnSetValue)
+ # bind closing event because destructor is not working properly
+ if hasattr(self.parent, 'dialogClosing'):
+ self.parent.dialogClosing.connect(win.OnClose)
+ # normal text field
+ else:
+ win = wx.TextCtrl(parent = which_panel)
+ value = self._getValue(p)
+ win.SetValue(value)
+ p['wxId'] = [win.GetId()]
+ win.Bind(wx.EVT_TEXT, self.OnSetValue)
+
+ which_sizer.Add(item = win,
+ proportion = 0,
+ flag = wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT,
+ border = 5)
+
elif prompt in ('colortable', 'barscale', 'northarrow'):
if prompt == 'colortable':
cb = ColorTablesComboBox(parent=which_panel, value=p.get('default',''),
@@ -1646,15 +1670,6 @@
if p.get('guidependency', ''):
cb.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
- elif prompt in ('cat', 'cats'):
- win = wx.TextCtrl(parent=which_panel)
- value = self._getValue(p)
- win.SetValue(value)
- p['wxId'] = [win.GetId()]
- win.Bind(wx.EVT_TEXT, self.OnSetValue)
- which_sizer.Add(item=win, proportion=0,
- flag=wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT,
- border=5)
if self.parent.GetName() == 'MainFrame' and (self._giface and hasattr(self._giface, "_model")):
parChk = wx.CheckBox(parent = which_panel, id = wx.ID_ANY,
Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py 2015-03-10 14:53:31 UTC (rev 64832)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py 2015-03-10 17:54:38 UTC (rev 64833)
@@ -24,6 +24,7 @@
- :class:`ElementSelect`
- :class:`OgrTypeSelect`
- :class:`CoordinatesSelect`
+ - :class:`VectorCategorySelect`
- :class:`SignatureSelect`
- :class:`SeparatorSelect`
@@ -36,6 +37,7 @@
@author Martin Landa <landa.martin gmail.com>
@author Vaclav Petras <wenzeslaus gmail.com> (menu customization)
@author Stepan Turek <stepan.turek seznam.cz> (CoordinatesSelect, ListCtrlComboPopup)
+ at author Matej Krejci <matejkrejci gmail.com> (VectorCategorySelect)
"""
import os
@@ -61,16 +63,17 @@
from gui_core.widgets import ManageSettingsWidget, CoordinatesValidator
-from core.gcmd import RunCommand, GError, GMessage
+from core.gcmd import RunCommand, GError, GMessage, GWarning
from core.utils import GetListOfLocations, GetListOfMapsets, \
GetFormats, rasterFormatExtension, vectorFormatExtension
from core.utils import GetSettingsPath, GetValidLayerName, ListSortLower
from core.utils import GetVectorNumberOfLayers, _
from core.settings import UserSettings
from core.debug import Debug
+from gui_core.vselect import VectorSelectBase
+
from grass.pydispatch.signal import Signal
-
class Select(wx.combo.ComboCtrl):
def __init__(self, parent, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
type = None, multiple = False, nmaps = 1,
@@ -2277,6 +2280,122 @@
"""Get TextCtrl widget"""
return self.coordsField
+class VectorCategorySelect(wx.Panel):
+ """Widget that allows interactive selection of vector features"""
+ def __init__(self, parent, giface, task):
+ super(VectorCategorySelect, self).__init__(parent=parent, id=wx.ID_ANY)
+ self.task=task
+ self.parent = parent
+ self.giface = giface
+
+ self.selectedFeatures = None
+ self.registered = False
+ self._vectorSelect = None
+
+ self.mapdisp = self.giface.GetMapDisplay()
+
+ self.catsField = wx.TextCtrl(parent=self, id=wx.ID_ANY,
+ size=globalvar.DIALOG_TEXTCTRL_SIZE)
+
+ icon = wx.Bitmap(os.path.join(globalvar.ICONDIR, "grass", "select.png"))
+ self.buttonVecSelect = buttons.ThemedGenBitmapToggleButton(parent=self, id=wx.ID_ANY,
+ bitmap=icon,
+ size=globalvar.DIALOG_COLOR_SIZE)
+ self.buttonVecSelect.Bind(wx.EVT_BUTTON, self._onClick)
+
+
+ if self.mapdisp:
+ switcher = self.mapdisp.GetToolSwitcher()
+ switcher.AddCustomToolToGroup(group='mouseUse',
+ btnId=self.buttonVecSelect.GetId(),
+ toggleHandler=self.buttonVecSelect.SetValue)
+
+ self._layout()
+
+ def _isMapSelected(self):
+ """Check if layer list contains at least one selected map
+ """
+ layerList = self.giface.GetLayerList()
+ layerSelected = layerList.GetSelectedLayer()
+ if layerSelected is None:
+ GWarning(_("No vector map selected in layer manager. Operation canceled."))
+ return False
+
+ return True
+
+ def _chckMap(self):
+ """Check if selected map in 'input' widget is the same as selected map in lmgr """
+ if self._isMapSelected():
+ layerList = self.giface.GetLayerList()
+ layerSelected = layerList.GetSelectedLayer()
+ inputName=self.task.get_param('input')
+ if inputName['value'] != str(layerSelected):
+ if inputName['value'] == '' or inputName['value'] is None:
+ GWarning(_("Input vector map is not selected"))
+ return False
+ GWarning(_("Input vector map <%s> and selected map <%s> in layer manager are different. "
+ "Operation canceled.") % (inputName['value'], str(layerSelected)))
+ return False
+ return True
+
+ def _onClick(self, evt=None):
+ if not self._chckMap():
+ self.buttonVecSelect.SetValue(False)
+ return
+
+ if self._vectorSelect is None:
+
+ if self.mapdisp:
+ if self.buttonVecSelect.IsEnabled():
+ switcher = self.mapdisp.GetToolSwitcher()
+ switcher.ToolChanged(self.buttonVecSelect.GetId())
+
+ self._vectorSelect = VectorSelectBase(self.mapdisp, self.giface)
+ if self.mapdisp.GetWindow().RegisterMouseEventHandler(wx.EVT_LEFT_DOWN,
+ self._onMapClickHandler,
+ 'cross') == False:
+ return
+ self.registered = True
+ self.mapdisp.Raise()
+ else:
+ self.OnClose()
+
+ def OnClose(self, event=None):
+ switcher = self.mapdisp.GetToolSwitcher()
+ switcher.RemoveCustomToolFromGroup(self.buttonVecSelect.GetId())
+ if self._vectorSelect is not None:
+ tmp = self._vectorSelect.GetLineStringSelectedCats()
+ self._vectorSelect.OnClose()
+ self.catsField.SetValue(tmp)
+ self._vectorSelect = None
+
+ def _onMapClickHandler(self, event):
+ """Update category text input widget"""
+ if event == "unregistered":
+ return
+ if not self._chckMap():
+ self.OnClose()
+ else:
+ self.catsField.SetValue(self._vectorSelect.GetLineStringSelectedCats())
+
+ def GetTextWin(self):
+ return self.catsField
+
+ def GetValue(self):
+ return self.catsField.GetValue()
+
+ def SetValue(self, value):
+ self.catsField.SetValue(value)
+
+ def _layout(self):
+ self.dialogSizer = wx.BoxSizer(wx.HORIZONTAL)
+ self.dialogSizer.Add(item=self.catsField,
+ proportion=1,
+ flag=wx.EXPAND)
+
+ self.dialogSizer.Add(item=self.buttonVecSelect)
+ self.SetSizer(self.dialogSizer)
+
class SignatureSelect(wx.ComboBox):
"""Widget for selecting signatures"""
def __init__(self, parent, element, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
Modified: grass/trunk/gui/wxpython/gui_core/vselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/vselect.py 2015-03-10 14:53:31 UTC (rev 64832)
+++ grass/trunk/gui/wxpython/gui_core/vselect.py 2015-03-10 17:54:38 UTC (rev 64833)
@@ -126,7 +126,7 @@
self._dialog.AddWidget(self.slist)
self.onCloseDialog = Signal('VectorSelectBase.onCloseDialog')
-
+
def OnDeleteRow(self, event=None):
"""Delete row in widget
"""
@@ -160,6 +160,11 @@
self._onMapClickHandler)
self.register=False
+ def OnClose(self):
+ self.selectedFeatures=[]
+ self._draw()
+ self.UnregisterMapEvtHandler()
+
def OnCloseDialog(self,evt=None):
if not self.onCloseDialog:
return
@@ -177,7 +182,6 @@
self.slist.DeleteAllItems()
self._dialog.Raise()
self.RegisterMapEvtHandler()
- self._draw()
def _onMapClickHandler(self, event):
"""Registred handler for clicking on grass disp
@@ -312,17 +316,15 @@
tree.AddLayer(ltype='vector', lname=outMap,
lcmd=['d.vect', 'map=%s' % outMap],
lchecked=True)
- #colorize new map
- ret, err =RunCommand('d.vect',
- map=outMap,
- color='red',getErrorMsg=True)
+
+ #TODO colorize new map
self.Reset()
else:
GMessage(_('Vector map <%s> was created') % outMap)
self.Reset()
else:
GError(_("Unable to create a new vector map.\n\nReason: %s") % err)
-
+
"""
def SetSelectedCat(self, cats):
# allows to set selected vector categories by list of cats (per line)
@@ -366,10 +368,8 @@
self.data['Category'] = cats
def Clear(self):
- self.data['Category']=list()
- self.data['Layer']=1
- self.data['Map'] = None
- self.giface.updateMap.emit(render=True, renderVector=True)
+ self.mapdisp.RemoveQueryLayer()
+ self.giface.GetMapWindow().UpdateMap(render = False)
def DrawSelected(self):
"""Highlight selected features"""
More information about the grass-commit
mailing list