Created
October 9, 2014 18:04
-
-
Save adam-stokes/cff5d052fc99e28cd4f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PasswordInput(WidgetWrap): | |
""" Password input dialog | |
""" | |
__metaclass__ = signals.MetaSignals | |
signals = ['done'] | |
def __init__(self, title, done_signal_handler): | |
self.title = '{0} (Esc)'.format(title) | |
self.pass_input = Edit(caption=('', 'Password: '), mask='*') | |
self.pass_confirm_input = Edit( | |
caption=('', 'Confirm Password: '), mask='*') | |
w = self._build_widget() | |
w = AttrWrap(w, 'dialog') | |
connect_signal(self, 'done', done_signal_handler) | |
super().__init__(w) | |
def _buttons(self): | |
buttons = [AttrWrap(Button("Ok", self.submit), | |
'button'), | |
AttrWrap(Button("Cancel", self.cancel), | |
'button')] | |
return Columns(buttons) | |
def _build_widget(self, **kwargs): | |
lbox = ListBox([ | |
AttrWrap(self.pass_input, 'input', 'input focus'), | |
AttrWrap(self.pass_confirm_input, 'input', 'input focus'), | |
Divider(), | |
self._buttons() | |
]) | |
lbox.set_focus(0) | |
w = LineBox( | |
BoxAdapter(lbox, height=4), title='Enter new Password (ESC)') | |
return w | |
def keypress(self, size, key): | |
if key == 'enter': | |
self.submit() | |
return | |
elif key == 'esc': | |
self.cancel() | |
return | |
def submit(self, button): | |
self.emit_done_signal(self.editor.get_edit_text()) | |
def cancel(self, button): | |
self.emit_done_signal() | |
def emit_done_signal(self, content=None): | |
emit_signal(self, 'done', content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment