[GRASS-SVN] r58937 - in grass/trunk/gui/wxpython: gui_core lmgr vdigit
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Feb 7 07:34:54 PST 2014
Author: martinl
Date: 2014-02-07 07:34:54 -0800 (Fri, 07 Feb 2014)
New Revision: 58937
Modified:
grass/trunk/gui/wxpython/gui_core/dialogs.py
grass/trunk/gui/wxpython/gui_core/gselect.py
grass/trunk/gui/wxpython/lmgr/layertree.py
grass/trunk/gui/wxpython/vdigit/toolbars.py
Log:
wxGUI/vdigit: introduce dialog for selected background vector map (see #2088)
Modified: grass/trunk/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/dialogs.py 2014-02-07 14:40:00 UTC (rev 58936)
+++ grass/trunk/gui/wxpython/gui_core/dialogs.py 2014-02-07 15:34:54 UTC (rev 58937)
@@ -7,6 +7,7 @@
- dialogs::SimpleDialog
- dialogs::LocationDialog
- dialogs::MapsetDialog
+ - dialogs::VectorDialog
- dialogs::NewVectorDialog
- dialogs::SavedRegion
- dialogs::GroupDialog
@@ -183,8 +184,53 @@
def GetMapset(self):
return self.element.GetValue()
-
-class NewVectorDialog(SimpleDialog):
+
+class VectorDialog(SimpleDialog):
+ def __init__(self, parent, title = _("Select vector map"), layerTree = None):
+ """!Dialog for selecting existing vector map
+
+ @param parent parent window
+ @param title window title
+ @param layerTree show only vector maps in given layer tree if not None
+
+ @return dialog instance
+ """
+ SimpleDialog.__init__(self, parent, title)
+
+ self.element = Select(parent = self.panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
+ type = 'vector', layerTree = layerTree,
+ validator = SimpleValidator(callback = self.ValidatorCallback))
+ self.element.SetFocus()
+
+ self.warning = _("Name of vector map is missing.")
+ wx.CallAfter(self._layout)
+
+ def _layout(self):
+ """!Do layout"""
+ self.dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
+ label = _("Name of vector map:")),
+ proportion = 0, flag = wx.ALL, border = 1)
+ self.dataSizer.Add(item = self.element, proportion = 0,
+ flag = wx.EXPAND | wx.ALL, border = 1)
+
+ self.panel.SetSizer(self.sizer)
+ self.sizer.Fit(self)
+
+ def GetName(self, full = False):
+ """!Get name of vector map to be created
+
+ @param full True to get fully qualified name
+ """
+ name = self.element.GetValue()
+ if full:
+ if '@' in name:
+ return name
+ else:
+ return name + '@' + grass.gisenv()['MAPSET']
+
+ return name.split('@', 1)[0]
+
+class NewVectorDialog(VectorDialog):
def __init__(self, parent, title = _("Create new vector map"),
disableAdd = False, disableTable = False, showType = False):
"""!Dialog for creating new vector map
@@ -197,18 +243,15 @@
@return dialog instance
"""
- SimpleDialog.__init__(self, parent, title)
+ VectorDialog.__init__(self, parent, title)
- self.element = Select(parent = self.panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
- type = 'vector', mapsets = [grass.gisenv()['MAPSET'],],
- validator = SimpleValidator(callback = self.ValidatorCallback))
- self.element.SetFocus()
# determine output format
if showType:
self.ftype = OgrTypeSelect(parent = self, panel = self.panel)
else:
self.ftype = None
+ # create attribute table
self.table = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
label = _("Create attribute table"))
self.table.SetValue(True)
@@ -235,8 +278,6 @@
self.table.Bind(wx.EVT_CHECKBOX, self.OnTable)
self.warning = _("Name of new vector map is missing.")
- self._layout()
- self.SetMinSize(self.GetSize())
def OnTable(self, event):
if self.keycol:
@@ -275,21 +316,8 @@
self.panel.SetSizer(self.sizer)
self.sizer.Fit(self)
+ self.SetMinSize(self.GetSize())
- def GetName(self, full = False):
- """!Get name of vector map to be created
-
- @param full True to get fully qualified name
- """
- name = self.element.GetValue()
- if full:
- if '@' in name:
- return name
- else:
- return name + '@' + grass.gisenv()['MAPSET']
-
- return name.split('@', 1)[0]
-
def GetKey(self):
"""!Get key column name"""
if self.keycol:
Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py 2014-02-07 14:40:00 UTC (rev 58936)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py 2014-02-07 15:34:54 UTC (rev 58937)
@@ -73,7 +73,7 @@
def __init__(self, parent, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
type = None, multiple = False, nmaps = 1,
mapsets = None, updateOnPopup = True, onPopup = None,
- fullyQualified = True, extraItems = {},
+ fullyQualified = True, extraItems = {}, layerTree = None,
validator = wx.DefaultValidator):
"""!Custom control to create a ComboBox with a tree control to
display and select GIS elements within acessible mapsets.
@@ -89,6 +89,7 @@
@param onPopup function to be called on Popup
@param fullyQualified True to provide fully qualified names (map at mapset)
@param extraItems extra items to add (given as dictionary) - see gmodeler for usage
+ @param layerTree show only elements from given layer tree if not None
@param validator validator for TextCtrl
"""
wx.combo.ComboCtrl.__init__(self, parent=parent, id=id, size=size, validator=validator)
@@ -102,7 +103,7 @@
self.tcp.SetData(type = type, mapsets = mapsets,
multiple = multiple, nmaps = nmaps,
updateOnPopup = updateOnPopup, onPopup = onPopup,
- fullyQualified = fullyQualified, extraItems = extraItems)
+ fullyQualified = fullyQualified, extraItems = extraItems, layerTree = layerTree)
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
def OnKeyDown(self, event):
@@ -170,10 +171,13 @@
"""
# overridden ComboPopup methods
def Init(self):
- self.value = [] # for multiple is False -> len(self.value) in [0,1]
+ self.value = [] # for multiple is False ->
+ # len(self.value) in [0,1]
self.curitem = None
self.multiple = False
self.updateOnPopup = True
+ self.filterItems = [] # limit items based on this list,
+ # see layerTree parameter
def Create(self, parent):
self.seltree = wx.TreeCtrl(parent, style=wx.TR_HIDE_ROOT
@@ -318,7 +322,14 @@
self.multiple = kargs['multiple']
if 'onPopup' in kargs:
self.onPopup = kargs['onPopup']
-
+ if kargs.get('layerTree', None):
+ self.filterItems = [] # reset
+ ltype = kargs['type']
+ for layer in kargs['layerTree'].GetVisibleLayers(skipDigitized = True):
+ if layer.GetType() != ltype:
+ continue
+ self.filterItems.append(layer.GetName())
+
def DeleteAllItems(self):
"""!Delete all items in popup"""
self.seltree.DeleteAllItems()
@@ -547,6 +558,9 @@
for elem in elist:
if elem != '':
fullqElem = elem + '@' + mapset
+ if self.filterItems and fullqElem not in self.filterItems:
+ continue # skip items missed in self.filterItems
+
if elements is not None:
if (exclude and fullqElem in elements) or \
(not exclude and fullqElem not in elements):
@@ -566,6 +580,7 @@
parent = root
data = {'node': node, 'mapset': mapset}
+
item = self.seltree.AppendItem(parent, text = value, data = wx.TreeItemData(data))
return item
Modified: grass/trunk/gui/wxpython/lmgr/layertree.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/layertree.py 2014-02-07 14:40:00 UTC (rev 58936)
+++ grass/trunk/gui/wxpython/lmgr/layertree.py 2014-02-07 15:34:54 UTC (rev 58937)
@@ -521,15 +521,16 @@
item.SetBitmap(MetaIcon(img = 'edit').GetBitmap(self.bmpsize))
self.popupMenu.AppendItem(item)
- if digitToolbar:
+ ### removed from layer tree
+ # if digitToolbar:
# background vector map
- self.popupMenu.Append(self.popupID['bgmap'],
- text = _("Use as background vector map for digitizer"),
- kind = wx.ITEM_CHECK)
- self.Bind(wx.EVT_MENU, self.OnSetBgMap, id = self.popupID['bgmap'])
- if UserSettings.Get(group = 'vdigit', key = 'bgmap', subkey = 'value',
- internal = True) == layer.GetName():
- self.popupMenu.Check(self.popupID['bgmap'], True)
+ # self.popupMenu.Append(self.popupID['bgmap'],
+ # text = _("Use as background vector map for digitizer"),
+ # kind = wx.ITEM_CHECK)
+ # self.Bind(wx.EVT_MENU, self.OnSetBgMap, id = self.popupID['bgmap'])
+ # if UserSettings.Get(group = 'vdigit', key = 'bgmap', subkey = 'value',
+ # internal = True) == layer.GetName():
+ # self.popupMenu.Check(self.popupID['bgmap'], True)
self.popupMenu.Append(self.popupID['topo'], text = _("Rebuild topology"))
self.Bind(wx.EVT_MENU, self.OnTopology, id = self.popupID['topo'])
@@ -921,23 +922,24 @@
self._setGradient()
self.RefreshLine(self.layer_selected)
+
+ ### unused since r58937
+ # def OnSetBgMap(self, event):
+ # """!Set background vector map for editing sesstion"""
+ # digit = self.mapdisplay.GetWindow().digit
+ # if event.IsChecked():
+ # mapName = self.GetLayerInfo(self.layer_selected, key = 'maplayer').GetName()
+ # UserSettings.Set(group = 'vdigit', key = 'bgmap', subkey = 'value',
+ # value = str(mapName), internal = True)
+ # digit.OpenBackgroundMap(mapName)
+ # self._setGradient('bgmap')
+ # else:
+ # UserSettings.Set(group = 'vdigit', key = 'bgmap', subkey = 'value',
+ # value = '', internal = True)
+ # digit.CloseBackgroundMap()
+ # self._setGradient()
- def OnSetBgMap(self, event):
- """!Set background vector map for editing sesstion"""
- digit = self.mapdisplay.GetWindow().digit
- if event.IsChecked():
- mapName = self.GetLayerInfo(self.layer_selected, key = 'maplayer').GetName()
- UserSettings.Set(group = 'vdigit', key = 'bgmap', subkey = 'value',
- value = str(mapName), internal = True)
- digit.OpenBackgroundMap(mapName)
- self._setGradient('bgmap')
- else:
- UserSettings.Set(group = 'vdigit', key = 'bgmap', subkey = 'value',
- value = '', internal = True)
- digit.CloseBackgroundMap()
- self._setGradient()
-
- self.RefreshLine(self.layer_selected)
+ # self.RefreshLine(self.layer_selected)
def OnPopupProperties (self, event):
"""!Popup properties dialog"""
@@ -1734,7 +1736,7 @@
if nlayers < 2:
mapWin.ResetView()
- def GetVisibleLayers(self):
+ def GetVisibleLayers(self, skipDigitized=False):
# make a list of visible layers
layers = []
@@ -1743,12 +1745,19 @@
if not vislayer or self.GetPyData(vislayer) is None:
return layers
+ vdigitLayer = None
+ if skipDigitized:
+ digitToolbar = self.mapdisplay.GetToolbar('vdigit')
+ if digitToolbar:
+ vdigitLayer = digitToolbar.GetLayer()
+
itemList = ""
for item in range(self.GetCount()):
itemList += self.GetItemText(vislayer) + ','
lType = self.GetLayerInfo(vislayer, key='type')
- if lType and lType != 'group':
- layers.append(self.GetLayerInfo(vislayer, key='maplayer'))
+ mapLayer = self.GetLayerInfo(vislayer, key='maplayer')
+ if lType and lType != 'group' and mapLayer is not vdigitLayer:
+ layers.append(mapLayer)
if not self.GetNextVisible(vislayer):
break
Modified: grass/trunk/gui/wxpython/vdigit/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/toolbars.py 2014-02-07 14:40:00 UTC (rev 58936)
+++ grass/trunk/gui/wxpython/vdigit/toolbars.py 2014-02-07 15:34:54 UTC (rev 58937)
@@ -20,7 +20,7 @@
from grass.pydispatch.signal import Signal
from gui_core.toolbars import BaseToolbar, BaseIcons
-from gui_core.dialogs import CreateNewVector
+from gui_core.dialogs import CreateNewVector, VectorDialog
from vdigit.preferences import VDigitSettingsDialog
from core.debug import Debug
from core.settings import UserSettings
@@ -556,6 +556,30 @@
def OnCopy(self, event):
"""!Copy selected features from (background) vector map"""
+ if not self.digit:
+ GError(_("No vector map open for editing."), self.parent)
+ return
+
+ # select background map
+ dlg = VectorDialog(self.parent, title = _("Select background vector map"),
+ layerTree = self.layerTree)
+ if dlg.ShowModal() != wx.ID_OK:
+ dlg.Destroy()
+ return
+
+ mapName = dlg.GetName(full=True)
+ dlg.Destroy()
+
+ # close open background map if any
+ if UserSettings.Get(group = 'vdigit', key = 'bgmap', subkey = 'value',
+ internal = True):
+ self.digit.CloseBackgroundMap()
+
+ # open background map for reading
+ UserSettings.Set(group = 'vdigit', key = 'bgmap', subkey = 'value',
+ value = str(mapName), internal = True)
+ self.digit.OpenBackgroundMap(mapName)
+
if self.action['desc'] == 'copyLine': # select previous action
self.ToggleTool(self.addPoint, True)
self.ToggleTool(self.additionalTools, False)
@@ -902,6 +926,11 @@
"vector map <%s>...") % self.mapLayer.GetName(),
0)
self.digit.CloseMap()
+
+ # close open background map if any
+ if UserSettings.Get(group = 'vdigit', key = 'bgmap', subkey = 'value',
+ internal = True):
+ self.digit.CloseBackgroundMap()
# TODO: replace by giface
lmgr = self.parent.GetLayerManager()
More information about the grass-commit
mailing list