Package libxyz :: Package core :: Module inputwrapper
[hide private]
[frames] | no frames]

Source Code for Module libxyz.core.inputwrapper

 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 -class InputWrapper(object):
18 """ 19 Wrap get_input and seek in user-defined keycodes before return keys 20 """ 21 22 WIN_RESIZE = 'window resize' 23
24 - def __init__(self, xyz):
25 self.xyz = xyz 26 self.plugin = xyz.pm.load(u":core:keycodes") 27 self.keycodes = {} 28 self._resized = False 29 30 self.update()
31 32 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 33
34 - def update(self, data=None):
35 """ 36 Set/load keycodes data 37 @param data: Keycodes data. If not provided load via get_keys() 38 @type data: dict 39 """ 40 41 if data is not None: 42 self.keycodes = data 43 else: 44 self.keycodes = self.plugin.get_keys()
45 46 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 47
48 - def get(self):
49 """ 50 Get input from screen and search if it matches any user-defined 51 keycodes 52 """ 53 54 _input = None 55 56 while True: 57 _in = self.xyz.screen.get_input() 58 59 if not _in: 60 continue 61 62 if self.WIN_RESIZE in _in: 63 self._resized = True 64 65 try: 66 _input = [self.keycodes[tuple(_in)]] 67 except KeyError: 68 _input = _in 69 finally: 70 break 71 72 return _input
73 74 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 75
76 - def _resized_get(self):
77 rval = self._resized 78 79 if rval: 80 self._resized = False 81 82 return rval
83 84 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 85
86 - def _resized_set(self, value):
87 self._resized = True if value else False
88 89 resized = property(_resized_get, _resized_set)
90