From: ewt Date: Tue, 13 Jul 1999 17:31:16 +0000 (+0000) Subject: fixes for width and returns X-Git-Tag: r0-50~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5a6729cf456c001570aa597dffc655b8f381df7a;p=thirdparty%2Fnewt.git fixes for width and returns --- diff --git a/checkboxtree.c b/checkboxtree.c index d637549..e9a490a 100644 --- a/checkboxtree.c +++ b/checkboxtree.c @@ -230,7 +230,7 @@ int newtCheckboxTreeAddArray(newtComponent co, item->branch = NULL; item->depth = numIndexes - 1; - i = 4; + i = 4 + (3 * item->depth); if ((strlen(text) + i + ct->pad) > co->width) { co->width = strlen(text) + i + ct->pad; @@ -333,7 +333,8 @@ static void ctPlace(newtComponent co, int newLeft, int newTop) { int ctSetItem(newtComponent co, struct items *item, enum newtFlagsSense sense) { struct CheckboxTree * ct = co->data; - struct items ** currItem; + struct items * currItem; + struct items * firstItem; if (!item) return 1; @@ -351,12 +352,16 @@ int ctSetItem(newtComponent co, struct items *item, enum newtFlagsSense sense) } if (item->branch) { - currItem = ct->currItem; + currItem = *ct->currItem; + firstItem = *ct->firstItem; buildFlatList(co); ct->currItem = ct->flatList; - while (*ct->currItem != *currItem) ct->currItem++; + while (*ct->currItem != currItem) ct->currItem++; + + ct->firstItem = ct->flatList; + while (*ct->firstItem != firstItem) ct->firstItem++; } return 0; diff --git a/popcorn.py b/popcorn.py index bce2853..9357a38 100755 --- a/popcorn.py +++ b/popcorn.py @@ -14,10 +14,25 @@ ct.addItem("Red", (0, snackArgs['append'])) ct.addItem("Yellow", (0, snackArgs['append'])) ct.addItem("Blue", (0, snackArgs['append'])) ct.append("Flavors") +ct.addItem("Vanilla", (1, snackArgs['append'])) +ct.addItem("Chocolate", (1, snackArgs['append'])) +ct.addItem("Stawberry", (1, snackArgs['append'])) ct.append("Numbers") +ct.addItem("1", (2, snackArgs['append'])) +ct.addItem("2", (2, snackArgs['append'])) +ct.addItem("3", (2, snackArgs['append'])) ct.append("Names") +ct.addItem("Matt", (3, snackArgs['append'])) +ct.addItem("Shawn", (3, snackArgs['append'])) +ct.addItem("Wilson", (3, snackArgs['append'])) ct.append("Months") +ct.addItem("February", (4, snackArgs['append'])) +ct.addItem("August", (4, snackArgs['append'])) +ct.addItem("September", (4, snackArgs['append'])) ct.append("Events") +ct.addItem("Christmas", (5, snackArgs['append'])) +ct.addItem("Labor Day", (5, snackArgs['append'])) +ct.addItem("My Vacation", (5, snackArgs['append'])) b = Button("Button") e = Entry(15, "Entry") l = Label("label") diff --git a/snackmodule.c b/snackmodule.c index 9cba457..caddefb 100644 --- a/snackmodule.c +++ b/snackmodule.c @@ -153,44 +153,6 @@ struct snackWidget_s { int anint; } ; -typedef struct cbSelection_t { - PyObject_HEAD; - void ** selection; - int numselected; -} cbSelection; - -static int selectionLength(PyObject * o); -PyObject * selectionItem(PyObject * o, int n); - -static PySequenceMethods selectionAsSeq = { - selectionLength, /* length */ - 0, /* concat */ - 0, /* repeat */ - selectionItem, /* item */ - 0, /* slice */ - 0, /* assign item */ - 0, /* assign slice */ -}; - -static void selectionDestructor(PyObject * s); - -static PyTypeObject cbTreeSelection = { - PyObject_HEAD_INIT(&PyType_Type) - 0, /* ob_size */ - "cbselection", /* tp_name */ - sizeof(cbSelection), /* tp_size */ - 0, /* tp_itemsize */ - selectionDestructor, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - &selectionAsSeq, /* tp_as_sequence */ - 0, /* tp_as_mapping */ -}; - static PyObject * widgetAddCallback(snackWidget * s, PyObject * args); static PyObject * widgetGetAttr(PyObject * s, char * name); static PyObject * widgetEntrySetValue(snackWidget * s, PyObject * args); @@ -202,8 +164,8 @@ static PyObject * widgetListboxDel(snackWidget * s, PyObject * args); static PyObject * widgetListboxGet(snackWidget * s, PyObject * args); static PyObject * widgetTextboxText(snackWidget * s, PyObject * args); static PyObject * widgetCheckboxTreeAddItem(snackWidget * s, PyObject * args); -static cbSelection * widgetCheckboxTreeGetSel(snackWidget * s, - PyObject * args); +static PyObject * widgetCheckboxTreeGetSel(snackWidget * s, + PyObject * args); static PyMethodDef widgetMethods[] = { { "setCallback", (PyCFunction) widgetAddCallback, METH_VARARGS, NULL }, @@ -840,52 +802,34 @@ static PyObject * widgetCheckboxTreeAddItem(snackWidget * s, PyObject * args) { } path[len] = NEWT_ARG_LAST; - newtCheckboxTreeAddArray(s->co, text, (void *) 5, + newtCheckboxTreeAddArray(s->co, text, (void *) s->anint, selected ? NEWT_FLAG_SELECTED : 0, path); return PyInt_FromLong(s->anint++); } -static cbSelection * widgetCheckboxTreeGetSel(snackWidget * s, +static PyObject * widgetCheckboxTreeGetSel(snackWidget * s, PyObject * args) { void ** selection; int numselected; - cbSelection * sel; + int i; + PyObject * sel; selection = newtCheckboxTreeGetSelection(s->co, &numselected); - sel = PyObject_NEW(cbSelection, &cbTreeSelection); - sel->selection = selection; - sel->numselected = numselected; - - return sel; -} - -static int selectionLength(PyObject * o) { - cbSelection * sel = (void *) o; - - return sel->numselected; -} - -PyObject * selectionItem(PyObject * o, int n) { - cbSelection * sel = (void *) o; - void **result; - - if (n > sel->numselected - 1 || sel->numselected == 0) { - PyErr_SetString(PyExc_IndexError, "index out of bounds"); - return NULL; + if (!selection) { + Py_INCREF(Py_None); + return Py_None; } - result = sel->selection[n]; - - return Py_BuildValue("i", (int) result); -} - -static void selectionDestructor(PyObject * o) { - cbSelection * sel = (void *) o; + sel = PyList_New(0); + for (i = 0; i < numselected; i++) { + PyList_Append(sel, PyInt_FromLong((int) selection[i])); + printf("got %d\n", selection[i]); + } + free(selection); - if (sel->selection != NULL) - free(sel->selection); + return sel; } void init_snack(void) {