Package libxyz :: Package ui :: Module xyzlistbox
[hide private]
[frames] | no frames]

Source Code for Module libxyz.ui.xyzlistbox

  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  from libxyz.ui import lowui 
 18  from libxyz.ui import align 
 19  from libxyz.ui import Border 
 20  from libxyz.ui import Keys 
 21   
22 -class XYZListBox(lowui.WidgetWrap):
23 """ 24 Simple list box 25 """ 26 27 # Skin rulesets resolution order 28 resolution = (u"list_box", u"box", u"widget") 29
30 - def __init__(self, xyz, body, walker, title, dim=None):
31 """ 32 @param xyz: XYZ data 33 @param body: Top-level widget 34 @param walker: SimpleWalker or any walker-like instance 35 @param title: ListBox title 36 37 Required resources: title, border, box, selected 38 """ 39 40 self.xyz = xyz 41 42 if dim is None: 43 _dim = self._get_dim() 44 else: 45 _dim = dim 46 47 self._walker = walker 48 self._keys = Keys() 49 50 self._listbox = lowui.AttrWrap(lowui.ListBox(walker), 51 self._attr(u"box")) 52 53 _box = Border(self._listbox, title, self._attr(u"title"), 54 self._attr(u"border")) 55 56 _box = lowui.Overlay(_box, body, align.CENTER, _dim[0], 57 align.MIDDLE, _dim[1]) 58 59 super(XYZListBox, self).__init__(_box)
60 61 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 62
63 - def show(self, dim=None, exit_keys=None):
64 """ 65 Show list 66 """ 67 68 exit_keys = exit_keys or [] 69 70 if dim is None: 71 dim = self.xyz.screen.get_cols_rows() 72 73 while True: 74 self.xyz.screen.draw_screen(dim, self.render(dim, True)) 75 76 _i = self.xyz.input.get() 77 78 if self.xyz.input.WIN_RESIZE in _i: 79 dim = self.xyz.screen.get_cols_rows() 80 continue 81 82 if _i: 83 for _k in _i: 84 if _k == self._keys.ESC: 85 return 86 elif _k == "j": 87 _k = self._keys.DOWN 88 elif _k == "k": 89 _k = self._keys.UP 90 91 self._listbox.keypress(dim, _k) 92 93 # Also quit on specified keys if any 94 if _k in exit_keys: 95 return
96 97 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 98
99 - def _attr(self, name):
100 """ 101 Find palette 102 """ 103 104 return self.xyz.skin.attr(self.resolution, name)
105 106 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 107
108 - def _get_dim(self):
109 _dim = self.xyz.screen.get_cols_rows() 110 111 return (_dim[0] - 4, _dim[1] - 4)
112