[GRASS-SVN] r63662 - grass/branches/releasebranch_7_0/gui/wxpython/gui_core
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Dec 21 18:59:19 PST 2014
Author: annakrat
Date: 2014-12-21 18:59:19 -0800 (Sun, 21 Dec 2014)
New Revision: 63662
Modified:
grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py
Log:
wxGUI/gselect: yet another attempt to improve map selection widget for wxPython 2.8, needs testing on other platforms than Linux, fortunately the widget is fixed in wxPython 3 (merge from trunk, r63174)
Modified: grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py 2014-12-22 02:45:14 UTC (rev 63661)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py 2014-12-22 02:59:19 UTC (rev 63662)
@@ -201,11 +201,18 @@
# from propagating up to the parent GIS Manager layer tree
self.seltree.Bind(wx.EVT_TREE_ITEM_EXPANDING, lambda x: None)
self.seltree.Bind(wx.EVT_TREE_ITEM_COLLAPSED, lambda x: None)
- self.seltree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, lambda x: None)
self.seltree.Bind(wx.EVT_TREE_SEL_CHANGED, lambda x: None)
self.seltree.Bind(wx.EVT_TREE_DELETE_ITEM, lambda x: None)
self.seltree.Bind(wx.EVT_TREE_BEGIN_DRAG, lambda x: None)
self.seltree.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, lambda x: None)
+ # navigation in list/tree is handled automatically since wxPython 3
+ # for older versions, we have to workaround it and write our own navigation
+ if globalvar.CheckWxVersion(version=[3]):
+ self.seltree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self._onItemConfirmed)
+ self.seltree.Bind(wx.EVT_TREE_KEY_DOWN, self._onDismissPopup)
+ else:
+ self.seltree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, lambda x: None)
+ self.seltree.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
def GetControl(self):
return self.seltree
@@ -276,7 +283,9 @@
self.seltree.AppendItem(root, text = item)
def OnKeyUp(self, event):
- """Enable to select items using keyboard
+ """Enable to select items using keyboard.
+
+ Unused with wxPython 3, can be removed in the future.
"""
item = self.seltree.GetSelection()
if event.GetKeyCode() == wx.WXK_DOWN:
@@ -292,14 +301,29 @@
elif event.GetKeyCode() == wx.WXK_RETURN:
self.seltree.SelectItem(item)
self.curitem = item
- item_str = self.seltree.GetItemText(self.curitem)
- if self.multiple:
- if item_str not in self.value:
- self.value.append(item_str)
- else:
- self.value = [item_str]
+ self._selectTreeItem(item)
self.Dismiss()
+ def _onDismissPopup(self, event):
+ """Hide popup without selecting item on Esc"""
+ if event.GetKeyCode() == wx.WXK_ESCAPE:
+ self.Dismiss()
+ else:
+ event.Skip()
+
+ def _selectTreeItem(self, item):
+ item_str = self.seltree.GetItemText(item)
+ if self.multiple:
+ if item_str not in self.value:
+ self.value.append(item_str)
+ else:
+ self.value = [item_str]
+
+ def _onItemConfirmed(self, event):
+ item = event.GetItem()
+ self._selectTreeItem(item)
+ self.Dismiss()
+
def OnMotion(self, evt):
"""Have the selection follow the mouse, like in a real combobox
"""
@@ -315,12 +339,7 @@
if self.curitem is None:
return
- item_str = self.seltree.GetItemText(self.curitem)
- if self.multiple:
- if item_str not in self.value:
- self.value.append(item_str)
- else:
- self.value = [item_str]
+ self._selectTreeItem(self.curitem)
self.Dismiss()
evt.Skip()
@@ -585,9 +604,12 @@
item = self.seltree.AppendItem(parent, text = value, data = wx.TreeItemData(data))
return item
- def OnKeyDown(self, event):
- """Enables to select items using keyboard"""
+ def OnKeyUp(self, event):
+ """Enables to select items using keyboard
+ Unused with wxPython 3, can be removed in the future.
+ """
+
item = self.seltree.GetSelection()
if event.GetKeyCode() == wx.WXK_DOWN:
self.seltree.SelectItem(self.seltree.GetNextVisible(item))
@@ -634,21 +656,8 @@
if self.seltree.GetPyData(item)['node']:
self.value = []
else:
- fullName = self.seltree.GetItemText(item)
- if self.fullyQualified and self.seltree.GetPyData(item)['mapset']:
- fullName += '@' + self.seltree.GetPyData(item)['mapset']
+ self._selectTreeItem(item)
- if self.multiple:
- self.value.append(fullName)
- else:
- if self.nmaps > 1: # see key_desc
- if len(self.value) >= self.nmaps:
- self.value = [fullName]
- else:
- self.value.append(fullName)
- else:
- self.value = [fullName]
-
self.Dismiss()
def OnLeftDown(self, evt):
@@ -662,25 +671,35 @@
evt.Skip()
return
- fullName = self.seltree.GetItemText(item)
- if self.fullyQualified and self.seltree.GetPyData(item)['mapset']:
- fullName += '@' + self.seltree.GetPyData(item)['mapset']
+ self._selectTreeItem(item)
+ self.Dismiss()
- if self.multiple:
- self.value.append(fullName)
+ evt.Skip()
+
+ def _selectTreeItem(self, item):
+ fullName = self.seltree.GetItemText(item)
+ if self.fullyQualified and self.seltree.GetPyData(item)['mapset']:
+ fullName += '@' + self.seltree.GetPyData(item)['mapset']
+
+ if self.multiple:
+ self.value.append(fullName)
+ else:
+ if self.nmaps > 1: # see key_desc
+ if len(self.value) >= self.nmaps:
+ self.value = [fullName]
+ else:
+ self.value.append(fullName)
else:
- if self.nmaps > 1: # see key_desc
- if len(self.value) >= self.nmaps:
- self.value = [fullName]
- else:
- self.value.append(fullName)
- else:
- self.value = [fullName]
+ self.value = [fullName]
- self.Dismiss()
+ def _onItemConfirmed(self, event):
+ item = event.GetItem()
+ if self.seltree.GetPyData(item)['node']:
+ self.value = []
+ else:
+ self._selectTreeItem(item)
+ self.Dismiss()
- evt.Skip()
-
def SetData(self, **kargs):
"""Set object properties"""
ListCtrlComboPopup.SetData(self, **kargs)
More information about the grass-commit
mailing list