comparison frontends/primitivus/custom_widgets.py @ 182:556c2bd7c344

Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
author Goffi <goffi@goffi.org>
date Wed, 18 Aug 2010 12:45:48 +0800
parents 8f56238309d9
children 33e618d385cf
comparison
equal deleted inserted replaced
181:a566f654929e 182:556c2bd7c344
691 frame_header = urwid.AttrMap(urwid.Text(title,'center'),'title') 691 frame_header = urwid.AttrMap(urwid.Text(title,'center'),'title')
692 692
693 buttons = None 693 buttons = None
694 694
695 if "OK/CANCEL" in style: 695 if "OK/CANCEL" in style:
696 buttons = [urwid.Button(_("Cancel"), kwargs['cancel_cb']), 696 cancel_arg = [kwargs['cancel_value']] if kwargs.has_key('cancel_value') else []
697 urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])] 697 ok_arg = [kwargs['ok_value']] if kwargs.has_key('ok_value') else []
698 buttons = [urwid.Button(_("Cancel"), kwargs['cancel_cb'], *cancel_arg),
699 urwid.Button(_("Ok"), kwargs['ok_cb'], *ok_arg)]
698 elif "YES/NO" in style: 700 elif "YES/NO" in style:
699 buttons = [urwid.Button(_("Yes"), kwargs['yes_cb']), 701 yes_arg = [kwargs['yes_value']] if kwargs.has_key('yes_value') else []
700 urwid.Button(_("No"), kwargs['no_cb'], kwargs['yes_value'])] 702 no_arg = [kwargs['no_value']] if kwargs.has_key('no_value') else []
703 buttons = [urwid.Button(_("Yes"), kwargs['yes_cb'], *yes_arg),
704 urwid.Button(_("No"), kwargs['no_cb'], *no_arg)]
701 if "OK" in style: 705 if "OK" in style:
702 buttons = [urwid.Button(_("Ok"), kwargs['ok_cb'], kwargs['ok_value'])] 706 ok_arg = [kwargs['ok_value']] if kwargs.has_key('ok_value') else []
707 buttons = [urwid.Button(_("Ok"), kwargs['ok_cb'], *ok_arg)]
703 if buttons: 708 if buttons:
704 buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center') 709 buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center')
705 body_content = urwid.SimpleListWalker(widgets_lst) 710 body_content = urwid.SimpleListWalker(widgets_lst)
706 frame_body = urwid.ListBox(body_content) 711 frame_body = urwid.ListBox(body_content)
707 frame = urwid.Frame(frame_body, frame_header, buttons_flow if buttons else None) 712 frame = FocusFrame(frame_body, frame_header, buttons_flow if buttons else None, 'footer' if buttons else 'body')
708 decorated_frame = urwid.LineBox(frame) 713 decorated_frame = urwid.LineBox(frame)
709 urwid.WidgetWrap.__init__(self, decorated_frame) 714 urwid.WidgetWrap.__init__(self, decorated_frame)
710 715
711 716
712 717
713 class InputDialog(GenericDialog): 718 class InputDialog(GenericDialog):
714 """Dialog with an edit box""" 719 """Dialog with an edit box"""
715 720
716 def __init__(self, title, instrucions, style=['OK/CANCEL'], default_txt = '', **kwargs): 721 def __init__(self, title, instrucions, style=['OK/CANCEL'], default_txt = '', **kwargs):
717 instr_wid = urwid.Text(instrucions+':') 722 instr_wid = urwid.Text(instrucions+':')
718 edit_box = urwid.Edit(edit_text=default_txt) 723 edit_box = AdvancedEdit(edit_text=default_txt)
719 GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs) 724 GenericDialog.__init__(self, [instr_wid,edit_box], title, style, ok_value=edit_box, **kwargs)
720 725
721 class ConfirmDialog(GenericDialog): 726 class ConfirmDialog(GenericDialog):
722 """Dialog with buttons for confirm or cancel an action""" 727 """Dialog with buttons for confirm or cancel an action"""
723 728
724 def __init__(self, title, style=['YES/NO'], **kwargs): 729 def __init__(self, title, style=['YES/NO'], **kwargs):
725 GenericDialog.__init__(self, [], title, style, yes_value=None, **kwargs) 730 GenericDialog.__init__(self, [], title, style, **kwargs)
726 731
727 class Alert(GenericDialog): 732 class Alert(GenericDialog):
728 """Dialog with just a message and a OK button""" 733 """Dialog with just a message and a OK button"""
729 734
730 def __init__(self, title, message, style=['OK'], **kwargs): 735 def __init__(self, title, message, style=['OK'], **kwargs):