1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from libxyz.ui import lowui
18 from libxyz.ui import align
19 from libxyz.ui import Border
20 from libxyz.ui import Keys
21
23 """
24 Simple list box
25 """
26
27
28 resolution = (u"list_box", u"box", u"widget")
29
30 - def __init__(self, xyz, body, walker, title, dim=None):
31 """
32 @param xyz: XYZ data
33 @param body: Top-level widget
34 @param walker: SimpleWalker or any walker-like instance
35 @param title: ListBox title
36
37 Required resources: title, border, box, selected
38 """
39
40 self.xyz = xyz
41
42 if dim is None:
43 _dim = self._get_dim()
44 else:
45 _dim = dim
46
47 self._walker = walker
48 self._keys = Keys()
49
50 self._listbox = lowui.AttrWrap(lowui.ListBox(walker),
51 self._attr(u"box"))
52
53 _box = Border(self._listbox, title, self._attr(u"title"),
54 self._attr(u"border"))
55
56 _box = lowui.Overlay(_box, body, align.CENTER, _dim[0],
57 align.MIDDLE, _dim[1])
58
59 super(XYZListBox, self).__init__(_box)
60
61
62
63 - def show(self, dim=None, exit_keys=None):
64 """
65 Show list
66 """
67
68 exit_keys = exit_keys or []
69
70 if dim is None:
71 dim = self.xyz.screen.get_cols_rows()
72
73 while True:
74 self.xyz.screen.draw_screen(dim, self.render(dim, True))
75
76 _i = self.xyz.input.get()
77
78 if self.xyz.input.WIN_RESIZE in _i:
79 dim = self.xyz.screen.get_cols_rows()
80 continue
81
82 if _i:
83 for _k in _i:
84 if _k == self._keys.ESC:
85 return
86 elif _k == "j":
87 _k = self._keys.DOWN
88 elif _k == "k":
89 _k = self._keys.UP
90
91 self._listbox.keypress(dim, _k)
92
93
94 if _k in exit_keys:
95 return
96
97
98
105
106
107
109 _dim = self.xyz.screen.get_cols_rows()
110
111 return (_dim[0] - 4, _dim[1] - 4)
112