From: ewt Date: Mon, 12 Jul 1999 18:41:35 +0000 (+0000) Subject: added support for full checkbox trees X-Git-Tag: r0-50~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75d40644c441d2d2097e29221337524a7db751fe;p=thirdparty%2Fnewt.git added support for full checkbox trees --- diff --git a/popcorn.py b/popcorn.py index 32ca07e..bce2853 100755 --- a/popcorn.py +++ b/popcorn.py @@ -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() diff --git a/snack.py b/snack.py index 43a7348..9e1751f 100644 --- 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 diff --git a/snackmodule.c b/snackmodule.c index a17ec5f..35c422d 100644 --- a/snackmodule.c +++ b/snackmodule.c @@ -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++); }