[GRASS-SVN] r63174 - grass/trunk/gui/wxpython/gui_core
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Nov 26 21:11:28 PST 2014
Author: annakrat
Date: 2014-11-26 21:11:28 -0800 (Wed, 26 Nov 2014)
New Revision: 63174
Modified:
grass/trunk/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
Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py 2014-11-27 04:57:27 UTC (rev 63173)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py 2014-11-27 05:11:28 UTC (rev 63174)
@@ -198,11 +198,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
@@ -273,7 +280,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:
@@ -289,14 +298,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
"""
@@ -312,12 +336,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()
@@ -584,9 +603,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))
@@ -633,21 +655,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):
@@ -661,25 +670,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