Restrict non-club modifications to syscom
[mspang/pyceo.git] / pylib / csc / apps / urwid / widgets.py
index 2216240..8912726 100644 (file)
@@ -1,14 +1,28 @@
 import urwid
+from csc.apps.urwid.ldapfilter import *
+from csc.apps.urwid.window import raise_back, push_window
+
+def push_wizard(name, pages, dimensions=(50, 10)):
+    state = {}
+    wiz = Wizard()
+    for page in pages:
+        if type(page) != tuple:
+            page = (page, )
+        wiz.add_panel( page[0](state, *page[1:]) )
+    push_window( urwid.Filler( urwid.Padding(
+        urwid.LineBox(wiz), 'center', dimensions[0]),
+        'middle', dimensions[1] ), name )
 
 class ButtonText(urwid.Text):
-    def __init__(self, callback, *args, **kwargs):
+    def __init__(self, callback, data, *args, **kwargs):
         self.callback = callback
+        self.data = data
         urwid.Text.__init__(self, *args, **kwargs)
     def selectable(self):
         return True
     def keypress(self, size, key):
-        if key == 'enter':
-            self.callback(self.get_text())
+        if key == 'enter' and self.callback:
+            self.callback(self.data)
         else:
             return key
 
@@ -30,6 +44,11 @@ class WordEdit(SingleEdit):
     def valid_char(self, ch):
         return urwid.Edit.valid_char(self, ch) and ch != ' '
 
+class LdapFilterWordEdit(LdapFilter, WordEdit):
+    def __init__(self, *args):
+        LdapFilter.__init__(self, WordEdit)
+        WordEdit.__init__(self, *args)
+
 class PassEdit(SingleEdit):
     def get_text(self):
         text = urwid.Edit.get_text(self)
@@ -52,7 +71,7 @@ class Wizard(urwid.WidgetWrap):
         self.panels.append( panel )
         if len(self.panels) == 1:
             self.select(0)
-    
+
     def select(self, panelno, set_focus=True):
         if 0 <= panelno < len(self.panels):
             self.selected = panelno
@@ -64,14 +83,16 @@ class Wizard(urwid.WidgetWrap):
                     self.pile.set_focus( 0 )
                 else:
                     self.pile.set_focus( 1 )
-    
+
     def next(self, *args, **kwargs):
         if self.panels[self.selected].check():
             self.select( self.selected )
             return
         self.select(self.selected + 1)
-    
+
     def back(self, *args, **kwargs):
+        if self.selected == 0:
+            raise_back()
         self.select(self.selected - 1, False)
 
 class WizardPanel(urwid.WidgetWrap):