Advertisement
Uno-Dan

Keyboard bindings

Sep 16th, 2019
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1.  
  2.  
  3.         def shift_up(event):
  4.             tree = event.widget
  5.             cur_item = tree.focus()
  6.             prev_item = tree.prev(cur_item)
  7.             _parent = super(Treeview, self).parent(cur_item)
  8.  
  9.             if self.root_selection < cur_item:
  10.                 tree.selection_remove(cur_item)
  11.  
  12.             if prev_item:
  13.                 _children = tree.get_children(prev_item)
  14.  
  15.                 if _children and tree.item(prev_item)['open']:
  16.                     self.select_tail(prev_item)
  17.                     prev_item = tree.focus()
  18.  
  19.                 tree.selection_add(prev_item)
  20.                 tree.focus(prev_item)
  21.             elif _parent:
  22.                 tree.selection_add(_parent)
  23.                 tree.focus(_parent)
  24.  
  25.             return 'break'
  26.  
  27.         self.bind('<Shift-Up>', lambda e: shift_up(e))
  28.  
  29.         def shift_down(event):
  30.             tree = event.widget
  31.             cur_item = tree.focus()
  32.             next_item = tree.next(cur_item)
  33.             children = tree.get_children(cur_item)
  34.             _parent = super(Treeview, self).parent(cur_item)
  35.  
  36.             if self.root_selection > cur_item:
  37.                 tree.selection_remove(cur_item)
  38.  
  39.             if children and tree.item(cur_item)['open']:
  40.                 cur_item = children[0]
  41.                 tree.selection_add(cur_item)
  42.                 tree.focus(cur_item)
  43.             elif next_item:
  44.                 tree.selection_add(next_item)
  45.                 tree.focus(next_item)
  46.             else:
  47.                 while not tree.next(_parent):
  48.                     _parent = super(Treeview, self).parent(_parent)
  49.                     if not _parent:
  50.                         tree.focus(cur_item)
  51.                         return
  52.  
  53.                 cur_item = tree.next(_parent)
  54.                 tree.selection_add(cur_item)
  55.                 tree.focus(cur_item)
  56.  
  57.             return 'break'
  58.  
  59.         self.bind('<Shift-Down>', lambda e: shift_down(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement