]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
peanuts now working perfectly.
authorjohnsonm <johnsonm>
Mon, 27 Oct 1997 22:07:17 +0000 (22:07 +0000)
committerjohnsonm <johnsonm>
Mon, 27 Oct 1997 22:07:17 +0000 (22:07 +0000)
Don't add forms to grids...
Other bug fixes.

peanuts.py
snack.py

index 512b8f0b52655a5c1b4d6658073086d6c6056b47..a8bc4326ec76c00134b5b8bd94e854467f57d134 100755 (executable)
@@ -4,7 +4,7 @@ from snack import *
 
 screen = SnackScreen()
 
-li = Listbox(4, width = 20, returnExit = 1)
+li = Listbox(height = 3, width = 20, returnExit = 1)
 li.append("First")
 li.append("Second")
 li.append("Third")
@@ -15,14 +15,13 @@ bb = ButtonBar(screen, (("Ok", "ok"), ("Cancel", "cancel")))
 
 g = GridForm(screen, "My Test", 1, 3)
 g.add(li, 0, 0)
-g.add(rb, 0, 1)
+g.add(rb, 0, 1, (0, 1, 0, 1))
 g.add(bb, 0, 2, growx = 1)
 
 result = g.run()
 
 screen.finish()
 
-print "listbox", li.current()
-print "rb", rb.getSelection()
-print "bb", bb.buttonPressed(res)
-print res
+print "listbox:", li.current()
+print "rb:", rb.getSelection()
+print "bb:", bb.buttonPressed(result)
index 79f7eec86d49f8eba8db09237cc0a3c6f80b5995..9baa6684c2d3e0930108196f505852929a11db99 100644 (file)
--- a/snack.py
+++ b/snack.py
@@ -87,13 +87,13 @@ class Form:
        self.w.addhotkey(hotkeys[keyname])
 
     def add(self, widget):
-       if widget.__dict__.has_key('w'):
+       if widget.__dict__.has_key('gridmembers'):
+           for w in widget.gridmembers:
+               self.add(w)
+       elif widget.__dict__.has_key('w'):
            self.trans[widget.w.key] = widget
-       if widget.__dict__.has_key('w'):
            return self.w.add(widget.w)
-       elif widget.__dict__.has_key('g'):
-           return self.w.add(widget.g)
-       return Null
+       return None
 
     def run(self):
        (what, which) = self.w.run()
@@ -114,6 +114,7 @@ class Grid:
     def setField(self, what, col, row, padding = (0, 0, 0, 0),
                 anchorLeft = 0, anchorTop = 0, anchorRight = 0,
                 anchorBottom = 0, growx = 0, growy = 0):
+       self.gridmembers.append(what)
        anchorFlags = 0
        if (anchorLeft):
            anchorFlags = _snack.ANCHOR_LEFT
@@ -139,6 +140,7 @@ class Grid:
 
     def __init__(self, *args):
        self.g = apply(_snack.grid, args)
+       self.gridmembers = []
 
 class SnackScreen:
 
@@ -173,22 +175,22 @@ def reflow(text, width, flexDown = 5, flexUp = 5):
 class RadioGroup(Widget):
 
     def __init__(self):
-       self.group = None
+       self.prev = None
        self.buttonlist = []
 
     def add(self, title, value, default = None):
-       if not self.group and default == None:
+       if not self.prev and default == None:
            # If the first element is not explicitly set to
            # not be the default, make it be the default
            default = 1
-       b = SingleRadioButton(title, self.group, default)
-       if not self.group: self.group = b
+       b = SingleRadioButton(title, self.prev, default)
+       self.prev = b
        self.buttonlist.append((b, value))
        return b
 
     def getSelection(self):
        for (b, value) in self.buttonlist:
-           if b.selected: return value
+           if b.selected(): return value
        return None
 
 
@@ -202,7 +204,7 @@ class RadioBar(Grid):
        for (title, value, default) in buttonlist:
            b = self.group.add(title, value, default)
            self.list.append(b, value)
-           self.setField(b, 0, self.item)
+           self.setField(b, 0, self.item, anchorLeft = 1)
            self.item = self.item + 1
 
     def getSelection(self):