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
20 -class Box(lowui.WidgetWrap):
21 """
22 Base box
23 """
24
25
26 resolution = (u"box", u"widget")
27
28 - def __init__(self, xyz, body, message, title="", width=70):
29 """
30 @param xyz: XYZ data
31 @param body: Top-level widget
32 @param message: Message to display
33 @param title: Box title
34 @param width: Box width
35
36 Required resources: title, box, mount
37 """
38
39 self.xyz = xyz
40 self.screen = xyz.screen
41 self.skin = xyz.skin
42 self.message = message
43 self.full_width = width
44 self._enc = xyzenc
45
46 self.mount_span = {u"vertical": 2, u"horizontal": 2}
47
48 self._attr = lambda name: self.skin.attr(self.resolution, name)
49
50
51
53 """
54 Calculate size
55 """
56
57 self.rowspan = rowspan
58 self.box_width = self.full_width - self.mount_span[u"horizontal"]
59 self.box_height = self._rows(self.message)
60 self.full_height = self.box_height + self.mount_span[u"vertical"]
61
62
63
65 """
66 Init parent class
67 """
68
69 super(Box, self).__init__(box)
70
71
72
73 - def show(self, dim=None, wait=True):
74 """
75 Show box
76 @param dim: Dimension
77 @param wait: If True wait for key pressed
78 """
79
80 if dim is None:
81 dim = self.screen.get_cols_rows()
82
83 self.screen.draw_screen(dim, self.render(dim, True))
84
85 _input = None
86
87 if wait:
88 while True:
89 _input = self.xyz.input.get()
90
91 if _input:
92 break
93
94 return _input
95
96
97
99 """
100 Calculate required rows
101 """
102
103
104 _maxrows = self.screen.get_cols_rows()[1] - \
105 2 - self.mount_span[u"vertical"]
106 _lines = msg.count("\n")
107
108 if _lines + self.rowspan > _maxrows:
109 _rows = _maxrows
110 else:
111 _rows = _lines + self.rowspan
112
113 return _rows
114
115
116
118 """
119 Strip title if needed
120 """
121
122 _maxlen = self.box_width - 6
123 _len = len(title)
124
125 _stripped = title
126
127 if _len >= _maxlen:
128 _stripped = u"%s..." % title[:_maxlen - 3]
129
130 return _stripped
131