#!/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)
def something():
print hello
-e.setCallback(lambda: sys.exit(1))
+e.setCallback(sys.exit, 1)
screen = SnackScreen()
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)
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)
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)
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))
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);
{ "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 },
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;