Mercurial > urwid-satext
changeset 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 | 7155b81ffdd5 |
children | 8d4bf7d1d84e |
files | urwid_satext/sat_widgets.py |
diffstat | 1 files changed, 27 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- 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