# HG changeset patch # User Goffi # Date 1352922510 -3600 # Node ID a99951c9ce2ab58274ec0a11fafee33dc308542e # Parent 7155b81ffdd5101aa89983fbf42121adaa618d35 Password now use AdvancedEdit to take advantage of shortcuts diff -r 7155b81ffdd5 -r a99951c9ce2a urwid_satext/sat_widgets.py --- a/urwid_satext/sat_widgets.py Wed Nov 14 20:27:11 2012 +0100 +++ b/urwid_satext/sat_widgets.py Wed Nov 14 20:48:30 2012 +0100 @@ -24,34 +24,8 @@ import encodings utf8decode = lambda s: encodings.codecs.utf_8_decode(s)[0] -from urwid.util import is_mouse_press #XXX: is_mouse_press is not include in urwid in 1.0.0 - - -class Password(urwid.Edit): - """Edit box which doesn't show what is entered (show '*' or other char instead)""" - - def __init__(self, *args, **kwargs): - """Same args than Edit.__init__ with an additional keyword arg 'hidden_char' - @param hidden_char: char to show instead of what is actually entered: default '*' - """ - self.hidden_char=kwargs['hidden_char'] if kwargs.has_key('hidden_char') else '*' - self.__real_text='' - super(Password, self).__init__(*args, **kwargs) +from urwid.util import is_mouse_press #XXX: is_mouse_press is not included in urwid in 1.0.0 - def set_edit_text(self, text): - self.__real_text = text - hidden_txt = len(text)*'*' - super(Password, self).set_edit_text(hidden_txt) - - def get_edit_text(self): - return self.__real_text - - def insert_text(self, text): - self._edit_text = self.__real_text - super(Password,self).insert_text(text) - - def render(self, size, focus=False): - return super(Password, self).render(size, focus) class AdvancedEdit(urwid.Edit): """Edit box with some custom improvments @@ -112,6 +86,32 @@ #No completion method defined pass return super(AdvancedEdit, self).keypress(size, key) + +class Password(AdvancedEdit): + """Edit box which doesn't show what is entered (show '*' or other char instead)""" + + def __init__(self, *args, **kwargs): + """Same args than Edit.__init__ with an additional keyword arg 'hidden_char' + @param hidden_char: char to show instead of what is actually entered: default '*' + """ + self.hidden_char=kwargs['hidden_char'] if kwargs.has_key('hidden_char') else '*' + self.__real_text='' + super(Password, self).__init__(*args, **kwargs) + + def set_edit_text(self, text): + self.__real_text = text + hidden_txt = len(text)*'*' + super(Password, self).set_edit_text(hidden_txt) + + def get_edit_text(self): + return self.__real_text + + def insert_text(self, text): + self._edit_text = self.__real_text + super(Password,self).insert_text(text) + + def render(self, size, focus=False): + return super(Password, self).render(size, focus) class ModalEdit(AdvancedEdit): """AdvancedEdit with vi-like mode management