From: johnsonm Date: Mon, 27 Oct 1997 22:07:17 +0000 (+0000) Subject: peanuts now working perfectly. X-Git-Tag: r0-20~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5a9ab2e452c07cd66410d4c08ba922d1d53ae4a9;p=thirdparty%2Fnewt.git peanuts now working perfectly. Don't add forms to grids... Other bug fixes. --- diff --git a/peanuts.py b/peanuts.py index 512b8f0..a8bc432 100755 --- a/peanuts.py +++ b/peanuts.py @@ -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) diff --git a/snack.py b/snack.py index 79f7eec..9baa668 100644 --- 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):