From: johnsonm Date: Mon, 27 Oct 1997 18:59:27 +0000 (+0000) Subject: New order for command line arguments in Grid.setField X-Git-Tag: r0-20~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=de25a3b8f73b9a06b0bd02772122d56a07ff4459;p=thirdparty%2Fnewt.git New order for command line arguments in Grid.setField New mega-widgets under development. --- diff --git a/popcorn.py b/popcorn.py index 1d19807..7549e44 100755 --- a/popcorn.py +++ b/popcorn.py @@ -16,18 +16,18 @@ r1 = SingleRadioButton("Radio 1", None, 1) r2 = SingleRadioButton("Radio 2", r1) sg = Grid(2, 3) -sg.setField(0, 0, b, anchorLeft = 1) -sg.setField(1, 0, e, (1, 0, 0, 0), anchorLeft = 1, anchorTop = 1) -sg.setField(0, 1, l, (0, 1, 0, 0), anchorLeft = 1) -sg.setField(1, 1, cb, (1, 1, 0, 0), anchorLeft = 1) -sg.setField(0, 2, r1, (0, 0, 0, 0), anchorLeft = 1) -sg.setField(1, 2, r2, (1, 0, 0, 0), anchorLeft = 1) +sg.setField(b, 0, 0, anchorLeft = 1) +sg.setField(e, 1, 0, (1, 0, 0, 0), anchorLeft = 1, anchorTop = 1) +sg.setField(l, 0, 1, (0, 1, 0, 0), anchorLeft = 1) +sg.setField(cb, 1, 1, (1, 1, 0, 0), anchorLeft = 1) +sg.setField(r1, 0, 2, (0, 0, 0, 0), anchorLeft = 1) +sg.setField(r2, 1, 2, (1, 0, 0, 0), anchorLeft = 1) g = Grid(1, 3) -g.setField(0, 0, t) -g.setField(0, 1, li, (0, 1, 0, 1)) -g.setField(0, 2, sg) +g.setField(t, 0, 0) +g.setField(li, 0, 1, (0, 1, 0, 1)) +g.setField(sg, 0, 2) g.place(1, 1) diff --git a/snack.py b/snack.py index 59fe694..aafa19e 100644 --- a/snack.py +++ b/snack.py @@ -80,7 +80,7 @@ class Grid: def place(self, x, y): return self.g.place(x, y) - def setField(self, col, row, what, padding = (0, 0, 0, 0), + def setField(self, what, col, row, padding = (0, 0, 0, 0), anchorLeft = 0, anchorTop = 0, anchorRight = 0, anchorBottom = 0, growx = 0, growy = 0): anchorFlags = 0 @@ -136,3 +136,67 @@ class SnackScreen: def reflow(text, width, flexDown = 5, flexUp = 5): return _snack.reflow(text, width, flexDown, flexUp) + +# combo widgets + +def RadioGroup(Widget): + + def __init__(self): + self.group = None + self.buttonlist = [] + + def add(self, title, value, default = None): + if not self.group 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 + buttonlist.append((b, value)) + return b + + def getSelection(self): + for (b, value) in self.buttonlist: + if b.selected: return value + + +# pack a ButtonBar with growx = 1 + +def ButtonBar(Grid): + + def __init__(self, screen, buttonlist): + self.list = [] + self.item = 0 + Grid.__init__(self, len(buttonlist), 1) + for (title, value) in buttonlist: + b = Button(title) + self.list.append(b, value)) + self.setField(b, self.item, 0, (0, 1, 0, 1)) + self.item = self.item + 1 + +# FIXME: need to make it possible to find what button was pressed... + + +def GridForm(Grid): + + def __init__(self, screen, title, *args): + self.screen = screen + self.title = title + self.form = Form() + args = list(args) + args[:0] = self + apply(Grid.__init__, args) + + def add(self, widget, col, row, padding = (0, 0, 0, 0), + anchorLeft = 0, anchorTop = 0, anchorRight = 0, + anchorBottom = 0, growx = 0, growy = 0): + self.setField(widget, col, row, padding, anchorLeft, + anchorTop, anchorRight, anchorBottom, + growx, growy); + self.form.add(widget) + + def run(self): + self.screen.gridWrappedWindow(self.grid, title) + self.form.run() + self.screen.popWindow() +