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.2" 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 "\ 24 u"widget.\n"\ 25 u"If any keybinding currently exists for key it is "\ 26 u"shown on the bottom line" 27 ) 28 NAMESPACE = u"ui" 29 MIN_XYZ_VERSION = None 30 DOC = None 31 HOMEPAGE = u"xyzcmd.syhpoon.name" 32
33 - def __init__(self, xyz):
34 super(XYZPlugin, self).__init__(xyz) 35 36 self.export(self.show_box) 37 38 self._keys = uilib.Keys()
39 40 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 41
42 - def show_box(self, use_wrap=True):
43 """ 44 Show test_box dialog 45 @param use_wrap: Whether to use input wrapper which honours 46 learned keys 47 """ 48 49 _msg = _(u"Press any key. Escape twice to quit.") 50 51 _escape = 0 52 _escape_key = uilib.Shortcut(sc=[self._keys.ESCAPE]) 53 54 while True: 55 shortcut = InputBox(self.xyz, self.xyz.top, bstring(_msg), 56 _(u"Input test")).show(use_wrap=use_wrap) 57 58 if shortcut == _escape_key: 59 _escape += 1 60 if _escape == 2: 61 return 62 else: 63 _escape = 0 64 65 method = self.xyz.km.get_method_by_key(shortcut) 66 67 _msg = u"Shortcut: '%s'. Raw: '%s'" % ( 68 (u" ".join([ustring(x) for x in shortcut.sc]), 69 u" ".join([ustring(x) for x in shortcut.raw]))) 70 71 if method is not None: 72 _msg = u"%s\n[%s]" % (_msg, method.ns)
73 74 #++++++++++++++++++++++++++++++++++++++++++++++++ 75
76 -class InputBox(uilib.MessageBox):
77 - def show(self, dim=None, use_wrap=True):
78 def _get_input(): 79 if use_wrap: 80 return self.xyz.input.get() 81 else: 82 return self.screen.get_input()
83 84 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 85 86 if dim is None: 87 dim = self.screen.get_cols_rows() 88 89 self.screen.draw_screen(dim, self.render(dim, True)) 90 91 _input = None 92 93 while True: 94 _input = _get_input() 95 96 if self.xyz.km.is_prefix(uilib.Shortcut(raw=_input)): 97 _input += _get_input() 98 99 if _input: 100 break 101 102 return uilib.Shortcut(raw=_input)
103