From: msw Date: Thu, 5 Aug 1999 04:09:35 +0000 (+0000) Subject: listbox set current method, listboxchoicewindow default setting X-Git-Tag: r0-50~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99438c192ef4b778a4533f27468a0b217359b1f2;p=thirdparty%2Fnewt.git listbox set current method, listboxchoicewindow default setting --- diff --git a/popcorn.py b/popcorn.py index 9357a38..3b3919b 100755 --- a/popcorn.py +++ b/popcorn.py @@ -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) diff --git a/snack.py b/snack.py index 0ddf668..7b892dd 100644 --- 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)) diff --git a/snackmodule.c b/snackmodule.c index 2b1def4..2c6a419 100644 --- a/snackmodule.c +++ b/snackmodule.c @@ -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;