]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added help support and testing
authorewt <ewt>
Tue, 2 May 2000 13:27:33 +0000 (13:27 +0000)
committerewt <ewt>
Tue, 2 May 2000 13:27:33 +0000 (13:27 +0000)
popcorn.py
snack.py

index e1283a40c4d10a591be05357552b105b3c171a4d..96b44bf362505422f8d5edd17ba03324a8108ce6 100755 (executable)
@@ -4,7 +4,8 @@ from snack import *
 import sys
 
 def help(screen, text):
-    ButtonChoiceWindow(screen, "Help", text)
+    raise ValueError, "foo"
+    ButtonChoiceWindow(screen, "Help", text, help = "Help on help")
 
 t = TextboxReflowed(25, "Some text which needs to be wrapped at a good place.")
 li = Listbox(5, width = 20, returnExit = 1)
@@ -58,7 +59,8 @@ foo = EntryWindow(screen, 'Title', 'This is some text for the entry window',
 
 lbcw = ListboxChoiceWindow(screen, 'Title 2', 
                    'Choose one item from the list below:', 
-                   ('One', 'Two', 'Three', 'Four', 'Five'), default = 2)
+                   ('One', 'Two', 'Three', 'Four', 'Five'), default = 2,
+                   help = "Help for a listbox")
 
 sg = Grid(2, 3)
 sg.setField(b, 0, 0, anchorLeft = 1)
index 3a46607676852a2ebe6d289fd97821ee882e1997..a8e65918fd1eae470c520454dbc6d3ff0917e35d 100644 (file)
--- a/snack.py
+++ b/snack.py
@@ -371,12 +371,12 @@ class ButtonBar(Grid):
        return None
 
 
-class GridForm(Grid):
+class GridFormHelp(Grid):
 
-    def __init__(self, screen, title, *args):
+    def __init__(self, screen, title, help, *args):
        self.screen = screen
        self.title = title
-       self.form = Form()
+       self.form = Form(help)
        self.childList = []
        self.form_created = 0
        args = list(args)
@@ -428,6 +428,12 @@ class GridForm(Grid):
     def setCurrent (self, co):
         self.form.setCurrent (co)
 
+class GridForm(GridFormHelp):
+
+    def __init__(self, screen, title, *args):
+       myargs = (self, screen, title, None) + args
+       apply(GridFormHelp.__init__, myargs)
+
 class CheckboxTree(Widget):
     def append(self, text, item = None, selected = 0):
        self.addItem(text, (snackArgs['append'], ), item, selected)
@@ -466,7 +472,8 @@ class CheckboxTree(Widget):
 
 def ListboxChoiceWindow(screen, title, text, items, 
                        buttons = ('Ok', 'Cancel'), 
-                       width = 40, scroll = 0, height = -1, default = None):
+                       width = 40, scroll = 0, height = -1, default = None,
+                       help = None):
     if (height == -1): height = len(items)
 
     bb = ButtonBar(screen, buttons)
@@ -491,7 +498,7 @@ def ListboxChoiceWindow(screen, title, text, items,
     if (default != None):
        l.setCurrent (default)
 
-    g = GridForm(screen, title, 1, 3)
+    g = GridFormHelp(screen, title, help, 1, 3)
     g.add(t, 0, 0)
     g.add(l, 0, 1, padding = (0, 1, 0, 1))
     g.add(bb, 0, 2, growx = 1)
@@ -502,17 +509,17 @@ def ListboxChoiceWindow(screen, title, text, items,
 
 def ButtonChoiceWindow(screen, title, text, 
                       buttons = [ 'Ok', 'Cancel' ], 
-                      width = 40, x = None, y = None):
+                      width = 40, x = None, y = None, help = None):
     bb = ButtonBar(screen, buttons)
     t = TextboxReflowed(width, text, maxHeight = screen.height - 12)
 
-    g = GridForm(screen, title, 1, 2)
+    g = GridFormHelp(screen, title, help, 1, 2)
     g.add(t, 0, 0, padding = (0, 0, 0, 1))
     g.add(bb, 0, 1, growx = 1)
     return bb.buttonPressed(g.runOnce(x, y))
 
 def EntryWindow(screen, title, text, prompts, allowCancel = 1, width = 40,
-               entryWidth = 20, buttons = [ 'Ok', 'Cancel' ]):
+               entryWidth = 20, buttons = [ 'Ok', 'Cancel' ], help = None):
     bb = ButtonBar(screen, buttons);
     t = TextboxReflowed(width, text)
 
@@ -535,7 +542,7 @@ def EntryWindow(screen, title, text, prompts, allowCancel = 1, width = 40,
        count = count + 1
        entryList.append(e)
 
-    g = GridForm(screen, title, 1, 3)
+    g = GridFormHelp(screen, title, help, 1, 3)
 
     g.add(t, 0, 0, padding = (0, 0, 0, 1))
     g.add(sg, 0, 1, padding = (0, 0, 0, 1))