2 from csc.apps.urwid.ldapfilter import *
4 class ButtonText(urwid.Text):
5 def __init__(self, callback, data, *args, **kwargs):
6 self.callback = callback
8 urwid.Text.__init__(self, *args, **kwargs)
11 def keypress(self, size, key):
12 if key == 'enter' and self.callback:
13 self.callback(self.data)
17 class SingleEdit(urwid.Edit):
18 def keypress(self, size, key):
20 return urwid.Edit.keypress(self, size, 'down')
22 return urwid.Edit.keypress(self, size, key)
24 class SingleIntEdit(urwid.IntEdit):
25 def keypress(self, size, key):
27 return urwid.Edit.keypress(self, size, 'down')
29 return urwid.Edit.keypress(self, size, key)
31 class WordEdit(SingleEdit):
32 def valid_char(self, ch):
33 return urwid.Edit.valid_char(self, ch) and ch != ' '
35 class LdapFilterWordEdit(LdapFilter, WordEdit):
36 def __init__(self, *args):
37 LdapFilter.__init__(self, WordEdit)
38 WordEdit.__init__(self, *args)
40 class PassEdit(SingleEdit):
42 text = urwid.Edit.get_text(self)
43 return (self.caption + " " * len(self.get_edit_text()), text[1])
45 class Wizard(urwid.WidgetWrap):
50 self.panelwrap = urwid.WidgetWrap( urwid.SolidFill() )
51 self.back = urwid.Button("Back", self.back)
52 self.next = urwid.Button("Next", self.next)
53 self.buttons = urwid.Columns( [ self.back, self.next ], dividechars=3, focus_column=1 )
54 pad = urwid.Padding( self.buttons, ('fixed right', 2), 19 )
55 self.pile = urwid.Pile( [self.panelwrap, ('flow', pad)], 0 )
56 urwid.WidgetWrap.__init__(self, self.pile)
58 def add_panel(self, panel):
59 self.panels.append( panel )
60 if len(self.panels) == 1:
63 def select(self, panelno, set_focus=True):
64 if 0 <= panelno < len(self.panels):
65 self.selected = panelno
66 self.panelwrap.set_w( self.panels[panelno] )
67 self.panels[panelno].activate()
70 if self.panels[panelno].focusable():
71 self.pile.set_focus( 0 )
73 self.pile.set_focus( 1 )
75 def next(self, *args, **kwargs):
76 if self.panels[self.selected].check():
77 self.select( self.selected )
79 self.select(self.selected + 1)
81 def back(self, *args, **kwargs):
82 self.select(self.selected - 1, False)
84 class WizardPanel(urwid.WidgetWrap):
85 def __init__(self, state):
88 self.box = urwid.ListBox( urwid.SimpleListWalker( self.widgets ) )
89 urwid.WidgetWrap.__init__( self, self.box )
90 def init_widgets(self):
92 def focus_widget(self, widget):
93 self.box.set_focus( self.widgets.index( widget ) )