-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathexample3.collapse.py
More file actions
executable file
·44 lines (37 loc) · 1.93 KB
/
example3.collapse.py
File metadata and controls
executable file
·44 lines (37 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
# Copyright (C) 2013 Patrick Totzke <patricktotzke@gmail.com>
# This file is released under the GNU GPL, version 3 or a later revision.
from example1 import construct_example_tree, palette, unhandled_input # example data
from urwidtrees.decoration import CollapsibleIndentedTree # for Decoration
from urwidtrees.widgets import TreeBox
import urwid
if __name__ == "__main__":
# get some SimpleTree
stree = construct_example_tree()
# Use (subclasses of) the wrapper decoration.CollapsibleTree to construct a
# tree where collapsible subtrees. Apart from the original tree, these take
# a callable `is_collapsed` that defines initial collapsed-status if a
# given position.
# We want all grandchildren collapsed initially
if_grandchild = lambda pos: stree.depth(pos) > 1
# We use CollapsibleIndentedTree around the original example tree.
# This uses Indentation to indicate the tree structure and squeezes in
# text-icons to indicate the collapsed status.
# Also try CollapsibleTree or CollapsibleArrowTree..
tree = CollapsibleIndentedTree(stree,
is_collapsed=if_grandchild,
icon_focussed_att='focus',
# indent=6,
# childbar_offset=1,
# icon_frame_left_char=None,
# icon_frame_right_char=None,
# icon_expanded_char='-',
# icon_collapsed_char='+',
)
# put the tree into a treebox
treebox = TreeBox(tree)
rootwidget = urwid.AttrMap(treebox, 'body')
#add a text footer
footer = urwid.AttrMap(urwid.Text('Q to quit'), 'focus')
#enclose all in a frame
urwid.MainLoop(urwid.Frame(rootwidget, footer=footer), palette, unhandled_input = unhandled_input).run() # go