Package plugins :: Package ui :: Package testinput :: Module main
[hide private]
[frames] | no frames]

Source Code for Module plugins.ui.testinput.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 ustring, bstring 
 8   
 9  import libxyz.ui as uilib 
10   
11 -class XYZPlugin(BasePlugin):
12 """ 13 Plugin testinput 14 """ 15 16 NAME = u"testinput" 17 AUTHOR = u"Max E. Kuznecov <syhpoon@syhpoon.name>" 18 VERSION = u"0.1" 19 BRIEF_DESCRIPTION = u"Test input" 20 FULL_DESCRIPTION = u"Simple dialog to show pressed keys.\n"\ 21 u"Shortcut is what XYZCommander expects to see in "\ 22 u"configuration files.\n"\ 23 u"Raw is what low-level library emits to focus widget" 24 NAMESPACE = u"ui" 25 MIN_XYZ_VERSION = None 26 DOC = None 27 HOMEPAGE = u"xyzcmd.syhpoon.name" 28
29 - def __init__(self, xyz):
30 super(XYZPlugin, self).__init__(xyz) 31 32 self.export(self.show_box) 33 34 self._keys = uilib.Keys()
35 36 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 37
38 - def show_box(self, use_wrap=True):
39 """ 40 Show test_box dialog 41 @param use_wrap: Whether to use input wrapper which honours 42 learned keys 43 """ 44 45 _msg = _(u"Press any key. Escape twice to quit.") 46 47 _escape = 0 48 49 while True: 50 _input = InputBox(self.xyz, self.xyz.top, bstring(_msg), 51 _(u"Input test")).show(use_wrap=use_wrap) 52 53 if self._keys.ESCAPE in _input: 54 _escape += 1 55 if _escape == 2: 56 return 57 else: 58 _escape = 0 59 60 shortcut = uilib.Shortcut(raw=_input) 61 62 _low = [ustring(x) for x in _input] 63 _msg = u"Shortcut: '%s'. Raw: '%s'" % ( 64 (u" ".join([ustring(x) for x in shortcut.sc]), 65 u" ".join([ustring(x) for x in shortcut.raw])))
66 67 #++++++++++++++++++++++++++++++++++++++++++++++++ 68
69 -class InputBox(uilib.MessageBox):
70 - def show(self, dim=None, use_wrap=True):
71 if dim is None: 72 dim = self.screen.get_cols_rows() 73 74 self.screen.draw_screen(dim, self.render(dim, True)) 75 76 _input = None 77 78 while True: 79 if use_wrap: 80 _input = self.xyz.input.get() 81 else: 82 _input = self.screen.get_input() 83 84 if _input: 85 break 86 87 return _input
88