comparison urwid_satext/sat_widgets.py @ 59:a99951c9ce2a

Password now use AdvancedEdit to take advantage of shortcuts
author Goffi <goffi@goffi.org>
date Wed, 14 Nov 2012 20:48:30 +0100
parents d493f95724a7
children 5cef69971f23
comparison
equal deleted inserted replaced
58:7155b81ffdd5 59:a99951c9ce2a
22 import urwid 22 import urwid
23 from logging import debug, info, warning, error 23 from logging import debug, info, warning, error
24 import encodings 24 import encodings
25 utf8decode = lambda s: encodings.codecs.utf_8_decode(s)[0] 25 utf8decode = lambda s: encodings.codecs.utf_8_decode(s)[0]
26 26
27 from urwid.util import is_mouse_press #XXX: is_mouse_press is not include in urwid in 1.0.0 27 from urwid.util import is_mouse_press #XXX: is_mouse_press is not included in urwid in 1.0.0
28 28
29
30 class Password(urwid.Edit):
31 """Edit box which doesn't show what is entered (show '*' or other char instead)"""
32
33 def __init__(self, *args, **kwargs):
34 """Same args than Edit.__init__ with an additional keyword arg 'hidden_char'
35 @param hidden_char: char to show instead of what is actually entered: default '*'
36 """
37 self.hidden_char=kwargs['hidden_char'] if kwargs.has_key('hidden_char') else '*'
38 self.__real_text=''
39 super(Password, self).__init__(*args, **kwargs)
40
41 def set_edit_text(self, text):
42 self.__real_text = text
43 hidden_txt = len(text)*'*'
44 super(Password, self).set_edit_text(hidden_txt)
45
46 def get_edit_text(self):
47 return self.__real_text
48
49 def insert_text(self, text):
50 self._edit_text = self.__real_text
51 super(Password,self).insert_text(text)
52
53 def render(self, size, focus=False):
54 return super(Password, self).render(size, focus)
55 29
56 class AdvancedEdit(urwid.Edit): 30 class AdvancedEdit(urwid.Edit):
57 """Edit box with some custom improvments 31 """Edit box with some custom improvments
58 new chars: 32 new chars:
59 - C-a: like 'home' 33 - C-a: like 'home'
110 return 84 return
111 except AttributeError: 85 except AttributeError:
112 #No completion method defined 86 #No completion method defined
113 pass 87 pass
114 return super(AdvancedEdit, self).keypress(size, key) 88 return super(AdvancedEdit, self).keypress(size, key)
89
90 class Password(AdvancedEdit):
91 """Edit box which doesn't show what is entered (show '*' or other char instead)"""
92
93 def __init__(self, *args, **kwargs):
94 """Same args than Edit.__init__ with an additional keyword arg 'hidden_char'
95 @param hidden_char: char to show instead of what is actually entered: default '*'
96 """
97 self.hidden_char=kwargs['hidden_char'] if kwargs.has_key('hidden_char') else '*'
98 self.__real_text=''
99 super(Password, self).__init__(*args, **kwargs)
100
101 def set_edit_text(self, text):
102 self.__real_text = text
103 hidden_txt = len(text)*'*'
104 super(Password, self).set_edit_text(hidden_txt)
105
106 def get_edit_text(self):
107 return self.__real_text
108
109 def insert_text(self, text):
110 self._edit_text = self.__real_text
111 super(Password,self).insert_text(text)
112
113 def render(self, size, focus=False):
114 return super(Password, self).render(size, focus)
115 115
116 class ModalEdit(AdvancedEdit): 116 class ModalEdit(AdvancedEdit):
117 """AdvancedEdit with vi-like mode management 117 """AdvancedEdit with vi-like mode management
118 - there is a new 'mode' property wich can be changed with properties 118 - there is a new 'mode' property wich can be changed with properties
119 specified during init 119 specified during init