1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import traceback
18
19 import libxyz.ui as uilib
20
21 from libxyz.ui import lowui
22 from libxyz.ui.utils import truncate
23 from libxyz.core.utils import ustring
24
25 -class PluginEntry(lowui.FlowWidget):
26 """
27 Plugins list entry
28 """
29
30 - def __init__(self, plugin, selected_attr, enter_cb):
31 super(PluginEntry, self).__init__()
32
33 self.plugin = plugin
34 self.enter_cb = enter_cb
35
36 self._keys = uilib.Keys()
37
38 self._text = u"%s%*s - %s"
39
40 self._attr = selected_attr
41 self._content = lowui.Text(self._text)
42
43
44
45 - def selectable(self):
47
48
49
50 - def rows(self, (maxcol,), focus=False):
52
53
54
55 - def render(self, (maxcol,), focus=False):
56 percent = lambda per, total: int((total / 100.0) * per)
57
58 _pad = percent(35, maxcol) - len(self.plugin.ns)
59
60 _text = self._text % (self.plugin.ns, _pad,
61 self.plugin.VERSION,
62 self.plugin.BRIEF_DESCRIPTION)
63
64 if len(_text) >= maxcol:
65 _text = truncate(_text, maxcol, xyzenc)
66
67 if focus:
68 self._content.set_text((self._attr, _text))
69 else:
70 self._content.set_text(_text)
71
72 return self._content.render((maxcol,), focus)
73
74
75
76 - def keypress(self, (maxcol,), key):
77 if key == self._keys.ENTER:
78 try:
79 self.enter_cb()
80 except Exception, e:
81 xyzlog.error(_(u"Error in entry callback: %s" %
82 ustring(str(e))))
83 xyzlog.debug(ustring(traceback.format_exc()))
84 else:
85 return key
86