Package plugins :: Package core :: Package pluginlist :: Module main |
[hide private]
[frames] | no frames]

# Source Code for Module plugins.core.pluginlist.main

      1  #-*- coding: utf8 -*
      2  #
      3  # Max E. Kuznecov ~syhpoon <syhpoon@syhpoon.name> 2008
      4  #
      5  # This file is part of XYZCommander.
      6  # XYZCommander is free software: you can redistribute it and/or modify
      7  # it under the terms of the GNU Lesser Public License as published by
      8  # the Free Software Foundation, either version 3 of the License, or
      9  # (at your option) any later version.
     10  # XYZCommander is distributed in the hope that it will be useful,
     11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     13  # GNU Lesser Public License for more details.
     14  # You should have received a copy of the GNU Lesser Public License
     15  # along with XYZCommander. If not, see <http://www.gnu.org/licenses/>.
     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
     27 -class XYZPlugin(BasePlugin):
     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
     47 -    def __init__(self, xyz):
     48          super(XYZPlugin, self).__init__(xyz)
     49
     50          self.export(self.show_list)
     51
     52      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     53
     54 -    def show_list(self):
     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
     77 -    def _info(self):
     78          """
     79          Show plugin detailed info
     80          """
     81
     82          def _add_info():
     83              if _plugin.AUTHOR is not None:
     84                  _data.append(lowui.Text(_(u"Author: %s" % _plugin.AUTHOR)))
     85
     86              if _plugin.VERSION is not None:
     87                  _data.append(lowui.Text(_(u"Version: %s" % _plugin.VERSION)))
     88
     89              if _plugin.MIN_XYZ_VERSION is not None:
     90                  _data.append(lowui.Text(_(u"Minimal compatible version: %s"
     91                                            % _plugin.MIN_XYZ_VERSION)))
     92
     93              if _plugin.HOMEPAGE is not None:
     94                  _data.append(lowui.Text(_(u"Homepage: %s" % _plugin.HOMEPAGE)))
     95
     96              _data.append(_div)
     97
     98              if _plugin.FULL_DESCRIPTION is not None:
     99                  _data.append(lowui.Text(_plugin.FULL_DESCRIPTION))
    100
    101          #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    102
    103          def make_args(func):
    104              _args, _varargs, _varkw, _def = inspect.getargspec(func)
    105
    106              # We will be inspecting only methods, so always skip self
    107              if len(_args) == 1:
    108                  return u""
    109
    110              _args = _args[1:]
    111              _tmp = []
    112
    113              # No defaults
    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                  # Try to find current binding for the method
    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