]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
added support for full checkbox trees
authorewt <ewt>
Mon, 12 Jul 1999 18:41:35 +0000 (18:41 +0000)
committerewt <ewt>
Mon, 12 Jul 1999 18:41:35 +0000 (18:41 +0000)
popcorn.py
snack.py
snackmodule.c

index 32ca07e06a432040d54f741286a97f99d5599d00..bce285323c883c96be3f03ab3b91457bc1a83370 100755 (executable)
@@ -8,6 +8,16 @@ li.append("First", "f")
 li.append("Second", "s")
 li.insert("Another", "a", "f")
 li.delete("a")
+ct = CheckboxTree(5, scroll = 1)
+ct.append("Colors")
+ct.addItem("Red", (0, snackArgs['append']))
+ct.addItem("Yellow", (0, snackArgs['append']))
+ct.addItem("Blue", (0, snackArgs['append']))
+ct.append("Flavors")
+ct.append("Numbers")
+ct.append("Names")
+ct.append("Months")
+ct.append("Events")
 b = Button("Button")
 e = Entry(15, "Entry")
 l = Label("label")
@@ -63,6 +73,11 @@ res = f.run()
 
 screen.popWindow()
 
+g = GridForm(screen, "Tree", 1, 2)
+g.add(ct, 0, 0, (0, 0, 0, 1))
+g.add(Button("Ok"), 0, 1)
+g.runOnce()
+
 
 screen.finish()
 
index 43a73483a9a0e0f4c4e8a50856528c628e9d8352..9e1751faa3d755a0937535cf2e93cad641b7b500 100644 (file)
--- a/snack.py
+++ b/snack.py
@@ -8,6 +8,9 @@ import _snack
 import types
 import string
 
+snackArgs = {}
+snackArgs['append'] = -1
+
 class Widget:
 
     def setCallback(self, obj):
@@ -374,8 +377,13 @@ class GridForm(Grid):
        return result
 
 class CheckboxTree(Widget):
-    def append(self, text, item, selected):
-       key = self.w.checkboxtreeAppend(text, selected)
+    def append(self, text, item = None, selected = 0):
+       self.addItem(text, (snackArgs['append'], ), item, selected)
+
+    def addItem(self, text, path, item = None, selected = 0):
+       if (not item):
+           item = text
+       key = self.w.checkboxtreeAddItem(text, path, selected)
        self.key2item[key] = item
        self.item2key[item] = key
 
index a17ec5f913e6c93effc345a5e5f6bff0206791b0..35c422d2d68235bdbc9792ef9b60acff2aebf220 100644 (file)
@@ -201,7 +201,7 @@ static PyObject * widgetListboxIns(snackWidget * s, PyObject * args);
 static PyObject * widgetListboxDel(snackWidget * s, PyObject * args);
 static PyObject * widgetListboxGet(snackWidget * s, PyObject * args);
 static PyObject * widgetTextboxText(snackWidget * s, PyObject * args);
-static PyObject * widgetCheckboxTreeAppend(snackWidget * s, PyObject * args);
+static PyObject * widgetCheckboxTreeAddItem(snackWidget * s, PyObject * args);
 static cbSelection * widgetCheckboxTreeGetSel(snackWidget * s,
                                              PyObject * args);
 
@@ -216,7 +216,7 @@ static PyMethodDef widgetMethods[] = {
     { "listboxSetWidth", (PyCFunction) widgetListboxSetW, METH_VARARGS, NULL },
     { "listboxDeleteItem", (PyCFunction) widgetListboxDel, METH_VARARGS, NULL },
     { "scaleSet", (PyCFunction) scaleSet, METH_VARARGS, NULL },
-    { "checkboxtreeAppend", (PyCFunction) widgetCheckboxTreeAppend,
+    { "checkboxtreeAddItem", (PyCFunction) widgetCheckboxTreeAddItem,
       METH_VARARGS, NULL },
     { "checkboxtreeGetSelection", (PyCFunction) widgetCheckboxTreeGetSel,
       METH_VARARGS, NULL },
@@ -821,15 +821,28 @@ static snackWidget * checkboxTreeWidget(PyObject * s, PyObject * args) {
     return widget;
 }
 
-static PyObject * widgetCheckboxTreeAppend(snackWidget * s, PyObject * args) {
+static PyObject * widgetCheckboxTreeAddItem(snackWidget * s, PyObject * args) {
     char * text;
-    void * key;
     int selected = 0;
-    
-    if (!PyArg_ParseTuple(args, "s|i", &text, &selected))
+    PyObject * pathList, * o;
+    int len;
+    int * path;
+    int i;
+
+    if (!PyArg_ParseTuple(args, "sOi", &text, &pathList, &selected))
        return NULL;
 
-    newtCheckboxTreeAppend(s->co, selected, text, (void *) s->anint);
+    len = PyTuple_Size(pathList);
+    path = alloca(sizeof(*path) * (len + 1));
+    for (i = 0; i < len; i++) {
+        o = PyTuple_GetItem(pathList, i);
+       path[i] = PyInt_AsLong(o);
+       printf("found %d\n", path[i]);
+    }
+    path[len] = NEWT_ARG_LAST;
+
+    newtCheckboxTreeAddArray(s->co, text, (void *) 5,
+                            selected ? NEWT_FLAG_SELECTED : 0, path);
 
     return PyInt_FromLong(s->anint++);
 }