]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
listbox set current method, listboxchoicewindow default setting
authormsw <msw>
Thu, 5 Aug 1999 04:09:35 +0000 (04:09 +0000)
committermsw <msw>
Thu, 5 Aug 1999 04:09:35 +0000 (04:09 +0000)
popcorn.py
snack.py
snackmodule.c

index 9357a386418fa75e38c184365268e2a605598c60..3b3919ba1ba4b745fc59ea567c3ff698ffd492b1 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/python
 
 from snack import *
+import sys
 
 t = TextboxReflowed(25, "Some text which needs to be wrapped at a good place.")
 li = Listbox(5, width = 20, returnExit = 1)
@@ -43,7 +44,7 @@ r2 = SingleRadioButton("Radio 2", r1)
 def something():
     print hello
 
-e.setCallback(lambda: sys.exit(1))
+e.setCallback(sys.exit, 1)
 
 screen = SnackScreen()
 
@@ -52,7 +53,7 @@ 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'))
+                   ('One', 'Two', 'Three', 'Four', 'Five'), default = 2)
 
 sg = Grid(2, 3)
 sg.setField(b, 0, 0, anchorLeft = 1)
index 0ddf6680121975788bb8b69a6ba52d947d598669..7b892ddd2311485c4ea326f32b1122ee04fb2c18 100644 (file)
--- a/snack.py
+++ b/snack.py
@@ -77,9 +77,8 @@ class Listbox(Widget):
     def current(self):
        return self.key2item[self.w.listboxGetCurrent()]
 
-    def setCurrent(self, item):
-       pass
-       #self.w.listboxSetCurrent(self.item2key[item])
+    def setCurrent(self, index):
+       self.w.listboxSetCurrent(index)
 
     def __init__(self, height, scroll = 0, returnExit = 0, width = 0):
        self.w = _snack.listbox(height, scroll, returnExit)
@@ -415,7 +414,7 @@ class CheckboxTree(Widget):
 
 def ListboxChoiceWindow(screen, title, text, items, 
                        buttons = ('Ok', 'Cancel'), 
-                       width = 40, scroll = 0, height = -1):
+                       width = 40, scroll = 0, height = -1, default = 0):
     if (height == -1): height = len(items)
 
     bb = ButtonBar(screen, buttons)
@@ -432,6 +431,8 @@ def ListboxChoiceWindow(screen, title, text, items,
        l.append(text, key)
        count = count + 1
 
+    l.setCurrent (default)
+
     g = GridForm(screen, title, 1, 3)
     g.add(t, 0, 0)
     g.add(l, 0, 1, padding = (0, 1, 0, 1))
index 2b1def4d81913da026f23cd17bc01e4afde53323..2c6a4199837efbba775e7615d24ce9ad43104b83 100644 (file)
@@ -161,10 +161,12 @@ static PyObject * widgetGetAttr(PyObject * s, char * name);
 static PyObject * widgetEntrySetValue(snackWidget * s, PyObject * args);
 static PyObject * widgetLabelText(snackWidget * s, PyObject * args);
 static PyObject * widgetListboxSetW(snackWidget * s, PyObject * args);
+static PyObject * widgetListboxSetCurrent(snackWidget * s, PyObject * args);
 static PyObject * widgetListboxAdd(snackWidget * s, PyObject * args);
 static PyObject * widgetListboxIns(snackWidget * s, PyObject * args);
 static PyObject * widgetListboxDel(snackWidget * s, PyObject * args);
 static PyObject * widgetListboxGet(snackWidget * s, PyObject * args);
+static PyObject * widgetListboxSet(snackWidget * s, PyObject * args);
 static PyObject * widgetTextboxText(snackWidget * s, PyObject * args);
 static PyObject * widgetCheckboxTreeAddItem(snackWidget * s, PyObject * args);
 static PyObject * widgetCheckboxTreeGetSel(snackWidget * s, PyObject * args);
@@ -178,6 +180,7 @@ static PyMethodDef widgetMethods[] = {
     { "listboxAddItem", (PyCFunction) widgetListboxAdd, METH_VARARGS, NULL },
     { "listboxInsertItem", (PyCFunction) widgetListboxIns, METH_VARARGS, NULL },
     { "listboxGetCurrent", (PyCFunction) widgetListboxGet, METH_VARARGS, NULL },
+    { "listboxSetCurrent", (PyCFunction) widgetListboxSet, METH_VARARGS, NULL },
     { "listboxSetWidth", (PyCFunction) widgetListboxSetW, METH_VARARGS, NULL },
     { "listboxDeleteItem", (PyCFunction) widgetListboxDel, METH_VARARGS, NULL },
     { "scaleSet", (PyCFunction) scaleSet, METH_VARARGS, NULL },
@@ -792,6 +795,18 @@ static PyObject * widgetListboxGet(snackWidget * s, PyObject * args) {
     return PyInt_FromLong((long) newtListboxGetCurrent(s->co));
 }
 
+static PyObject * widgetListboxSet(snackWidget * s, PyObject * args) {
+    int index;
+    
+    if (!PyArg_ParseTuple(args, "i", &index))
+       return NULL;
+
+    newtListboxSetCurrent(s->co, index);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
 static PyObject * widgetListboxSetW(snackWidget * s, PyObject * args) {
     int width;