Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core

This commit is contained in:
Goffi 2010-08-18 12:45:48 +08:00
commit b3bff009e8

View file

@ -693,18 +693,23 @@ class GenericDialog(urwid.WidgetWrap):
buttons = None
if "OK/CANCEL" in style:
buttons = [urwid.Button(_("Cancel"), kwargs['cancel_cb']),
urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])]
cancel_arg = [kwargs['cancel_value']] if kwargs.has_key('cancel_value') else []
ok_arg = [kwargs['ok_value']] if kwargs.has_key('ok_value') else []
buttons = [urwid.Button(_("Cancel"), kwargs['cancel_cb'], *cancel_arg),
urwid.Button(_("Ok"), kwargs['ok_cb'], *ok_arg)]
elif "YES/NO" in style:
buttons = [urwid.Button(_("Yes"), kwargs['yes_cb']),
urwid.Button(_("No"), kwargs['no_cb'], kwargs['yes_value'])]
yes_arg = [kwargs['yes_value']] if kwargs.has_key('yes_value') else []
no_arg = [kwargs['no_value']] if kwargs.has_key('no_value') else []
buttons = [urwid.Button(_("Yes"), kwargs['yes_cb'], *yes_arg),
urwid.Button(_("No"), kwargs['no_cb'], *no_arg)]
if "OK" in style:
buttons = [urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])]
ok_arg = [kwargs['ok_value']] if kwargs.has_key('ok_value') else []
buttons = [urwid.Button(_("Ok"), kwargs['ok_cb'], *ok_arg)]
if buttons:
buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center')
body_content = urwid.SimpleListWalker(widgets_lst)
frame_body = urwid.ListBox(body_content)
frame = urwid.Frame(frame_body, frame_header, buttons_flow if buttons else None)
frame = FocusFrame(frame_body, frame_header, buttons_flow if buttons else None, 'footer' if buttons else 'body')
decorated_frame = urwid.LineBox(frame)
urwid.WidgetWrap.__init__(self, decorated_frame)
@ -715,14 +720,14 @@ class InputDialog(GenericDialog):
def __init__(self, title, instrucions, style=['OK/CANCEL'], default_txt = '', **kwargs):
instr_wid = urwid.Text(instrucions+':')
edit_box = urwid.Edit(edit_text=default_txt)
edit_box = AdvancedEdit(edit_text=default_txt)
GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs)
class ConfirmDialog(GenericDialog):
"""Dialog with buttons for confirm or cancel an action"""
def __init__(self, title, style=['YES/NO'], **kwargs):
GenericDialog.__init__(self, [], title, style, yes_value=None, **kwargs)
GenericDialog.__init__(self, [], title, style, **kwargs)
class Alert(GenericDialog):
"""Dialog with just a message and a OK button"""