[accerciser] Add expand/collapse node key handling



commit 1c33c09d354fc87d546a363bd3298f01a9dad93c
Author: Jan-Marek Glogowski <glogow fbihome de>
Date:   Mon May 27 20:11:45 2019 +0200

    Add expand/collapse node key handling
    
    This collapses or expandes the focused node based on the Left or
    Right arrow keys. If the current node can't be collapsed, try to
    collapse the parent node.

 src/lib/accerciser/accessible_treeview.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
---
diff --git a/src/lib/accerciser/accessible_treeview.py b/src/lib/accerciser/accessible_treeview.py
index fceca54..9e86859 100644
--- a/src/lib/accerciser/accessible_treeview.py
+++ b/src/lib/accerciser/accessible_treeview.py
@@ -571,6 +571,7 @@ class AccessibleTreeView(gtk.TreeView, ToolsAccessor):
 
     self.connect('popup-menu', self._onPopup)
     self.connect('button-press-event', self._onPopup)
+    self.connect('key-press-event', self._onKeyPress)
 
     self.connect('cursor-changed', self._onCursorChanged)
 
@@ -582,6 +583,24 @@ class AccessibleTreeView(gtk.TreeView, ToolsAccessor):
     path = self.get_cursor()[0]
     self.refresh_current_action.set_sensitive(path is not None)      
 
+  def _onKeyPress(self, w, event):
+    '''
+    Expand or collapse a row on Left/Right key-press
+    '''
+    if event.state == 0:
+      path, col = self.get_cursor()
+      if path is not None:
+        if event.keyval == gdk.KEY_Left:
+          if not self.collapse_row(path):
+            # if we ccouldn't collapse the current row, collapse the parent
+            if path.up():
+              self.collapse_row(path)
+          return True
+        elif event.keyval == gdk.KEY_Right:
+          self.expand_row(path, False)
+          return True
+    return False
+
   def _onPopup(self, w, event=None):
     '''
     Callback for popup button or right mouse button. Brings up a context


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]