]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
New order for command line arguments in Grid.setField
authorjohnsonm <johnsonm>
Mon, 27 Oct 1997 18:59:27 +0000 (18:59 +0000)
committerjohnsonm <johnsonm>
Mon, 27 Oct 1997 18:59:27 +0000 (18:59 +0000)
New mega-widgets under development.

popcorn.py
snack.py

index 1d198077f48d6a28c396bbc3ffcbbeea1d5e11c7..7549e444951bb63f84404e92e08a85a95602c84c 100755 (executable)
@@ -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)
 
index 59fe6941578036862a6ab91eb55f81d93c82a7dc..aafa19e413f600a181f43c6497299954e812ca22 100644 (file)
--- 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()
+