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

Source Code for Module plugins.core.pluginlist.entry

 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 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):
46 return True
47 48 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 49
50 - def rows(self, (maxcol,), focus=False):
51 return 1
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 unicode(e)) 83 xyzlog.debug(ustring(traceback.format_exc())) 84 else: 85 return key
86