-
Notifications
You must be signed in to change notification settings - Fork 18
/
example5.nested.py
executable file
·84 lines (77 loc) · 3.28 KB
/
example5.nested.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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 palette, construct_example_tree # example data
from example1 import FocusableText, unhandled_input # Selectable Text used for nodes
from urwidtrees.widgets import TreeBox
from urwidtrees.tree import SimpleTree
from urwidtrees.nested import NestedTree
from urwidtrees.decoration import ArrowTree, CollapsibleArrowTree # decoration
import urwid
import logging
if __name__ == "__main__":
#logging.basicConfig(filename='example.log',level=logging.DEBUG)
# Take some Arrow decorated Tree that we later stick inside another tree.
innertree = ArrowTree(construct_example_tree())
# Some collapsible, arrow decorated tree with extra indent
anotherinnertree = CollapsibleArrowTree(construct_example_tree(),
indent=10)
# A SimpleTree, that contains the two above
middletree = SimpleTree(
[
(FocusableText('Middle ROOT'),
[
(FocusableText('Mid Child One'), None),
(FocusableText('Mid Child Two'), None),
(innertree, None),
(FocusableText('Mid Child Three'),
[
(FocusableText('Mid Grandchild One'), None),
(FocusableText('Mid Grandchild Two'), None),
]
),
(anotherinnertree,
# middletree defines a childnode here. This is usually
# covered by the tree 'anotherinnertree', unless the
# interepreting NestedTree's constructor gets parameter
# interpret_covered=True..
[
(FocusableText('XXX I\'m invisible!'), None),
]),
]
)
]
) # end SimpleTree constructor for middletree
# use customized arrow decoration for middle tree
middletree = ArrowTree(middletree,
arrow_hbar_char=u'\u2550',
arrow_vbar_char=u'\u2551',
arrow_tip_char=u'\u25B7',
arrow_connector_tchar=u'\u2560',
arrow_connector_lchar=u'\u255A')
# define outmost tree
outertree = SimpleTree(
[
(FocusableText('Outer ROOT'),
[
(FocusableText('Child One'), None),
(middletree, None),
(FocusableText('last outer child'), None),
]
)
]
) # end SimpleTree constructor
# add some Arrow decoration
outertree = ArrowTree(outertree)
# wrap the whole thing into a Nested Tree
outertree = NestedTree(outertree,
# show covered nodes like XXX
interpret_covered=False
)
# put it into a treebox and run
treebox = TreeBox(outertree)
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