1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import inspect
18
19 import libxyz.ui as uilib
20
21 from libxyz.ui import lowui
22 from libxyz.core.plugins import BasePlugin
23 from libxyz.core.utils import ustring, bstring
24
25 from entry import PluginEntry
26
28 """
29 Show installed plugins
30 """
31
32 NAME = u"pluginlist"
33 AUTHOR = u"Max E. Kuznecov ~syhpoon <syhpoon@syhpoon.name>"
34 VERSION = u"0.2"
35 BRIEF_DESCRIPTION = u"Show plugin list"
36 FULL_DESCRIPTION = u"Show all currently loaded plugins and associated "\
37 u"information"
38 NAMESPACE = u"core"
39 HOMEPAGE = u"xyzcmd.syhpoon.name"
40 EVENTS = [("show",
41 _(u"Fires upon showing dialog. Arguments: No")),
42 ("info",
43 _(u"Fires when showing detaild plugin info."\
44 u"Arguments: Plugin object")),
45 ]
46
51
52
53
55 """
56 Show plugins list
57 """
58
59 self.fire_event("show")
60
61 _plugins = sorted(self.xyz.pm.get_all_loaded().values(),
62 lambda x, y: cmp(x.ns, y.ns))
63
64 _sel_attr = self.xyz.skin.attr(uilib.XYZListBox.resolution,
65 u"selected")
66 self._walker = lowui.SimpleListWalker([PluginEntry(_obj, _sel_attr,
67 self._info)
68 for _obj in _plugins])
69
70 _dim = tuple([x - 2 for x in self.xyz.screen.get_cols_rows()])
71
72 uilib.XYZListBox(self.xyz, self.xyz.top, self._walker,
73 _(u"Active plugins list"), _dim).show()
74
75
76
100
101
102
103 def make_args(func):
104 _args, _varargs, _varkw, _def = inspect.getargspec(func)
105
106
107 if len(_args) == 1:
108 return u""
109
110 _args = _args[1:]
111 _tmp = []
112
113
114 if _def is None:
115 _tmp = _args
116 else:
117 _delta = len(_args) - len(_def)
118
119 if _delta > 0:
120 _tmp.extend(_args[:_delta])
121 _args = _args[_delta:]
122
123 for _a, _d in zip(_args, _def):
124 _tmp.append(u"=".join((ustring(_a), ustring(_d))))
125
126 return u",".join(_tmp)
127
128
129
130 def _add_public_data():
131 if _plugin.public_data:
132 _data.append(uilib.Separator(_(u"Public data"),
133 title_attr=_titleattr,
134 div_attr=_divattr))
135
136 _dlen = len(_plugin.public_data)
137 _di = 0
138
139 for k, v in _plugin.public_data.iteritems():
140 _data.append(lowui.Text(u"%s: %s" % (k, type(v))))
141
142 _di += 1
143
144 if _di < _dlen:
145 _data.append(_div)
146
147
148
149 def _add_public_methods():
150 _data.append(uilib.Separator(_(u"Public methods"),
151 title_attr=_titleattr,
152 div_attr=_divattr))
153
154 _bind_data = self.xyz.km.get_binds()
155
156 _len = len(_plugin.public)
157 _i = 0
158
159 for k in sorted(_plugin.public.keys()):
160 v = _plugin.public[k]
161
162 if v.__doc__ is not None:
163 _doc = v.__doc__.rstrip()
164 else:
165 _doc = v.__doc__
166
167 _cur_bind = _(u"N/A")
168
169
170 for context in _bind_data:
171 for bind in _bind_data[context]:
172 if _bind_data[context][bind] is v:
173 _cur_bind = bind
174
175 _data.append(lowui.Text(u"%s(%s) [%s]: %s" %
176 (k, make_args(v), _cur_bind, _doc)))
177
178 _i += 1
179
180 if _i < _len:
181 _data.append(_div)
182
183
184
185 _w = self._walker.get_focus()[0]
186 _plugin = _w.plugin
187
188 self.fire_event("info", _plugin)
189 _divattr = self.xyz.skin.attr(uilib.XYZListBox.resolution, u"border")
190 _titleattr = self.xyz.skin.attr(uilib.XYZListBox.resolution, u"title")
191 _div = lowui.Text("")
192
193 _data = []
194
195 _add_info()
196
197 if _plugin.DOC is not None:
198 _data.append(uilib.Separator(_(u"Plugin doc"),
199 title_attr=_titleattr,
200 div_attr=_divattr))
201
202 _data.append(lowui.Text(_plugin.DOC))
203
204 if isinstance(_plugin.EVENTS, list):
205 _data.append(uilib.Separator(_(u"Plugin events"),
206 title_attr=_titleattr,
207 div_attr=_divattr))
208
209 for event, desc in _plugin.EVENTS:
210 _data.append(lowui.Text("%s -- %s" %
211 (bstring(_plugin.event_name(event)),
212 bstring(desc))))
213
214 _add_public_data()
215 _add_public_methods()
216
217 _method_walker = lowui.SimpleListWalker(_data)
218 _dim = tuple([x - 2 for x in self.xyz.screen.get_cols_rows()])
219
220 uilib.XYZListBox(self.xyz, self.xyz.top, _method_walker,
221 _(u"Plugin info %s" % _plugin.ns), _dim).show()
222