[GRASS-SVN] r44640 - grass/branches/releasebranch_6_4/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Dec 20 07:18:32 EST 2010


Author: martinl
Date: 2010-12-20 04:18:32 -0800 (Mon, 20 Dec 2010)
New Revision: 44640

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
Log:
wxGUI/select: use keyboard shortcuts (expand, collapse mapsets)
Patch by Anna Kratochvilova
(merge r44638 from trunk)


Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py	2010-12-20 12:16:46 UTC (rev 44639)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py	2010-12-20 12:18:32 UTC (rev 44640)
@@ -76,6 +76,14 @@
             self.tcp.SetData(type = type, mapsets = mapsets,
                              multiple = multiple,
                              updateOnPopup = updateOnPopup, onPopup = onPopup)
+        self.GetChildren()[0].Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
+     
+    def OnKeyDown(self, event):
+        """!Shows popupwindow if down arrow key is pressed"""
+        if event.GetKeyCode() == wx.WXK_DOWN:
+            self.ShowPopup() 
+        else:
+            event.Skip()
         
     def SetElementList(self, type, mapsets = None):
         """!Set element list
@@ -138,6 +146,7 @@
                                    |wx.TR_LINES_AT_ROOT
                                    |wx.SIMPLE_BORDER
                                    |wx.TR_FULL_ROW_HIGHLIGHT)
+        self.seltree.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
         self.seltree.Bind(wx.EVT_MOTION, self.OnMotion)
         self.seltree.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
         self.seltree.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.mapsetExpanded)
@@ -145,7 +154,7 @@
         self.seltree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.mapsetActivated)
         self.seltree.Bind(wx.EVT_TREE_SEL_CHANGED, self.mapsetSelected)
         self.seltree.Bind(wx.EVT_TREE_DELETE_ITEM, lambda x: None)
-
+        
     # the following dummy handler are needed to keep tree events from propagating up to
     # the parent GIS Manager layer tree
     def mapsetExpanded(self, event):
@@ -176,6 +185,9 @@
         """!Set filter for GIS elements, see e.g. VectorSelect"""
         self.filterElements = filter
         
+    def _startsWith(self, text):
+        return True if text.startswith(self.GetCombo().GetValue()) else False
+    
     def OnPopup(self, force = False):
         """!Limited only for first selected"""
         if not force and not self.updateOnPopup:
@@ -186,8 +198,9 @@
             selected = None
             exclude  = False
             
+        self.SetFilter(self._startsWith)   
         self.GetElementList(selected, exclude)
-    
+        
     def GetElementList(self, elements = None, exclude = False):
         """!Get filtered list of GIS elements in accessible mapsets
         and display as tree with all relevant elements displayed
@@ -374,6 +387,47 @@
 
         item = self.seltree.AppendItem(parent, text=value)
         return item
+    
+    # able to recieve only wx.EVT_KEY_UP
+    def OnKeyUp(self, event):
+        """!Enables to select items using keyboard"""
+        
+        item = self.seltree.GetSelection()
+        if event.GetKeyCode() == wx.WXK_DOWN:
+            self.seltree.SelectItem(self.seltree.GetNextVisible(item))
+            
+        # problem with GetPrevVisible   
+        elif event.GetKeyCode() == wx.WXK_UP: 
+            if self.seltree.ItemHasChildren(item) and self.seltree.IsExpanded(self.seltree.GetPrevSibling(item)):
+                itemPrev = self.seltree.GetLastChild(self.seltree.GetPrevSibling(item))
+            else:
+                itemPrev = self.seltree.GetPrevSibling(item)
+                if not wx.TreeItemId.IsOk(itemPrev):
+                    itemPrev = self.seltree.GetItemParent(item)
+                    if item == self.seltree.GetFirstChild(self.seltree.GetRootItem())[0]:
+                        itemPrev = item
+            self.seltree.SelectItem(itemPrev)
+            
+        elif event.GetKeyCode() == wx.WXK_RIGHT:
+            if self.seltree.ItemHasChildren(item):
+                self.seltree.Expand(item)
+        
+        elif event.GetKeyCode() == wx.WXK_LEFT:
+            if self.seltree.ItemHasChildren(item):
+                self.seltree.Collapse(item)
+                
+        elif event.GetKeyCode() == wx.WXK_ESCAPE:
+            self.Dismiss()
+            
+        elif event.GetKeyCode() == wx.WXK_RETURN:
+            if self.seltree.GetRootItem() == self.seltree.GetItemParent(item):
+                self.value = [] 
+            else:
+                mapsetItem = self.seltree.GetItemParent(item)
+                fullName = self.seltree.GetItemText(item) + '@' \
+                            + self.seltree.GetItemText(mapsetItem).split(' ', 1)[1]
+                self.value = [fullName, ]
+                self.Dismiss()
 
     def OnMotion(self, evt):
         """!Have the selection follow the mouse, like in a real combobox
@@ -395,7 +449,8 @@
                 self.value = [] # cannot select mapset item
             else:
                 mapsetItem = self.seltree.GetItemParent(item)
-                fullName = self.seltree.GetItemText(item) + '@' + self.seltree.GetItemText(mapsetItem).split(' ', 1)[1]
+                fullName = self.seltree.GetItemText(item) + '@' + \
+                    self.seltree.GetItemText(mapsetItem).split(' ', 1)[1]
                 if self.multiple is True:
                     # text item should be unique
                     self.value.append(fullName)



More information about the grass-commit mailing list