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
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.1"
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
45
46
47
49 """
50 Show plugins list
51 """
52
53 _plugins = sorted(self.xyz.pm.get_all_loaded().values(),
54 lambda x, y: cmp(x.ns, y.ns))
55
56 _sel_attr = self.xyz.skin.attr(uilib.XYZListBox.resolution, u"selected")
57 self._walker = lowui.SimpleListWalker([PluginEntry(_obj, _sel_attr,
58 self._info)
59 for _obj in _plugins])
60
61 _dim = tuple([x - 2 for x in self.xyz.screen.get_cols_rows()])
62
63 uilib.XYZListBox(self.xyz, self.xyz.top, self._walker,
64 _(u"Active plugins list"), _dim).show()
65
66
67
69 """
70 Show plugin detailed info
71 """
72
73 def _add_info():
74 if _plugin.AUTHOR is not None:
75 _data.append(lowui.Text(_(u"Author: %s" % _plugin.AUTHOR)))
76
77 if _plugin.VERSION is not None:
78 _data.append(lowui.Text(_(u"Version: %s" % _plugin.VERSION)))
79
80 if _plugin.MIN_XYZ_VERSION is not None:
81 _data.append(lowui.Text(_(u"Minimal compatible version: %s"
82 % _plugin.MIN_XYZ_VERSION)))
83
84 if _plugin.HOMEPAGE is not None:
85 _data.append(lowui.Text(_(u"Homepage: %s" % _plugin.HOMEPAGE)))
86
87 _data.append(_div)
88
89 if _plugin.FULL_DESCRIPTION is not None:
90 _data.append(lowui.Text(_plugin.FULL_DESCRIPTION))
91
92
93
94 def make_args(func):
95 _args, _varargs, _varkw, _def = inspect.getargspec(func)
96
97
98 if len(_args) == 1:
99 return u""
100
101 _args = _args[1:]
102 _tmp = []
103
104
105 if _def is None:
106 _tmp = _args
107 else:
108 _delta = len(_args) - len(_def)
109
110 if _delta > 0:
111 _tmp.extend(_args[:_delta])
112 _args = _args[_delta:]
113
114 for _a, _d in zip(_args, _def):
115 _tmp.append(u"=".join((ustring(_a), ustring(_d))))
116
117 return u",".join(_tmp)
118
119
120
121 def _add_public_data():
122 if _plugin.public_data:
123 _data.append(uilib.Separator(_(u"Public data"),
124 title_attr=_titleattr,
125 div_attr=_divattr))
126
127 _dlen = len(_plugin.public_data)
128 _di = 0
129
130 for k, v in _plugin.public_data.iteritems():
131 _data.append(lowui.Text(u"%s: %s" % (k, type(v))))
132
133 _di += 1
134
135 if _di < _dlen:
136 _data.append(_div)
137
138
139
140 def _add_public_methods():
141 _data.append(uilib.Separator(_(u"Public methods"),
142 title_attr=_titleattr,
143 div_attr=_divattr))
144
145 keys = uilib.Keys()
146 _bind_data = self.xyz.km.get_binds()
147
148 _len = len(_plugin.public)
149 _i = 0
150
151 for k in sorted(_plugin.public.keys()):
152 v = _plugin.public[k]
153
154 if v.__doc__ is not None:
155 _doc = v.__doc__.rstrip()
156 else:
157 _doc = v.__doc__
158
159 _cur_bind = _(u"N/A")
160
161
162 for context in _bind_data:
163 for bind in _bind_data[context]:
164 if _bind_data[context][bind] is v:
165 _cur_bind = bind
166
167 _data.append(lowui.Text(u"%s(%s) [%s]: %s" %
168 (k, make_args(v), _cur_bind, _doc)))
169
170 _i += 1
171
172 if _i < _len:
173 _data.append(_div)
174
175
176
177 _w = self._walker.get_focus()[0]
178 _plugin = _w.plugin
179
180 _divattr = self.xyz.skin.attr(uilib.XYZListBox.resolution, u"border")
181 _titleattr = self.xyz.skin.attr(uilib.XYZListBox.resolution, u"title")
182 _div = lowui.Text("")
183
184 _data = []
185
186 _add_info()
187
188 if _plugin.DOC is not None:
189 _data.append(uilib.Separator(_(u"Plugin doc"),
190 title_attr=_titleattr,
191 div_attr=_divattr))
192
193 _data.append(lowui.Text(_plugin.DOC))
194
195 _add_public_data()
196 _add_public_methods()
197
198 _method_walker = lowui.SimpleListWalker(_data)
199 _dim = tuple([x - 2 for x in self.xyz.screen.get_cols_rows()])
200
201 uilib.XYZListBox(self.xyz, self.xyz.top, _method_walker,
202 _(u"Plugin info %s" % _plugin.ns), _dim).show()
203