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=60):
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):
74 """
75 Show box until key pressed
76 @param dim: Dimension
77 """
78
79 if dim is None:
80 dim = self.screen.get_cols_rows()
81
82 self.screen.draw_screen(dim, self.render(dim, True))
83
84 _input = None
85
86 while True:
87 _input = self.xyz.input.get()
88
89 if _input:
90 break
91
92 return _input
93
94
95
97 """
98 Calculate required rows
99 """
100
101
102 _maxrows = self.screen.get_cols_rows()[1] - \
103 2 - self.mount_span[u"vertical"]
104 _lines = msg.count("\n")
105
106 if _lines + self.rowspan > _maxrows:
107 _rows = _maxrows
108 else:
109 _rows = _lines + self.rowspan
110
111 return _rows
112
113
114
116 """
117 Strip title if needed
118 """
119
120 _maxlen = self.box_width - 6
121 _len = len(title)
122
123 _stripped = title
124
125 if _len >= _maxlen:
126 _stripped = u"%s..." % title[:_maxlen - 3]
127
128 return _stripped
129