Package plugins :: Package core :: Package bindlist :: Module main

[hide private]
[frames] | no frames]

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

     1  #-*- coding: utf8 -*
     2  #
     3  # Max E. Kuznecov <syhpoon@syhpoon.name> 2008
     4  #
     5
     6  from libxyz.core.plugins import BasePlugin
     7  from libxyz.core.utils import bstring
     8  from libxyz.ui import lowui
     9
    10  import libxyz.ui as uilib
    11
    12 -class XYZPlugin(BasePlugin):
    13      "Plugin bindlist"
    14
    15      NAME = u"bindlist"
    16      AUTHOR = u"Max E. Kuznecov <syhpoon@syhpoon.name>"
    17      VERSION = u"0.2"
    18      BRIEF_DESCRIPTION = u"Show keybindings"
    19      FULL_DESCRIPTION = u"Plugin is used to display all current keybindings "\
    20                         u"along with corresponding contextes and methods"
    21      NAMESPACE = u"core"
    22      HOMEPAGE = u"xyzcmd.syhpoon.name"
    23      EVENTS = [("show_binds",
    24                 "Event is fired before showing dialog. Receives no arguments."),
    25                ]
    26
    27 -    def __init__(self, xyz):
    28          super(XYZPlugin, self).__init__(xyz)
    29
    30          self.export(self.show_binds)
    31
    32          self._keys = uilib.Keys()
    33
    34      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    35
    36 -    def show_binds(self):
    37          """
    38          Show keybindings
    39          """
    40
    41          self.fire_event("show_binds")
    42
    43          _data = self.xyz.km.get_binds()
    44
    45          _entries = []
    46
    47          _divattr = self.xyz.skin.attr(uilib.XYZListBox.resolution, u"border")
    48
    49          _entries.append(lowui.Text(u"%-10s %-20s %s" %
    50                          (_(u"Context"), _(u"Bind"), _(u"Method"))))
    51          _entries.append(uilib.Separator(div_attr=_divattr))
    52
    53          for _context in sorted(_data.keys()):
    54              for _bind in sorted(_data[_context].keys(),
    55                                  cmp=lambda x, y: cmp(bstring(x), bstring(y))):
    56                  if _data[_context][_bind] is None:
    57                      continue
    58
    59                  _entries.append(lowui.Text(u"%-10s %-20s %s" %
    60                                  (_context, _bind, _data[_context][_bind].ns)))
    61
    62          _walker = lowui.SimpleListWalker(_entries)
    63
    64          _dim = tuple([x - 2 for x in self.xyz.screen.get_cols_rows()])
    65
    66          uilib.XYZListBox(self.xyz, self.xyz.top, _walker,
    67                           _(u"Keybindings"), _dim).show()
    68