methods:
- - Listbox(self,height, scroll = 0l returnExit = 0, width = 0, showCursor = 0)
+ - Listbox(self, height, scroll = 0, returnExit = 0, width = 0, showCursor = 0, multiple = 0, border = 0)
- insert(self, text, item, before) : insert element; before = key to item to insert before, or None.
- delete(self, item) : delete item from list.
- replace(self, text,item) : Replace a given item's text
- current(self) : returns currently selected item
+ - getSelection(self) : returns a list of selected items
- setCurrent(self,i tem) : select current.
- clear(self) : clear listbox
"""
def current(self):
return self.key2item[self.w.listboxGetCurrent()]
+ def getSelection(self):
+ selection = []
+ list = self.w.listboxGetSelection()
+ for key in list:
+ selection.append(self.key2item[key])
+ return selection
+
def setCurrent(self, item):
self.w.listboxSetCurrent(self.item2key[item])
self.item2key = {}
self.w.listboxClear()
- def __init__(self, height, scroll = 0, returnExit = 0, width = 0, showCursor = 0):
- self.w = _snack.listbox(height, scroll, returnExit, showCursor)
+ def __init__(self, height, scroll = 0, returnExit = 0, width = 0, showCursor = 0, multiple = 0, border = 0):
+ self.w = _snack.listbox(height, scroll, returnExit, showCursor, multiple, border)
self.key2item = {}
self.item2key = {}
if (width):
static PyObject * widgetListboxIns(snackWidget * s, PyObject * args);
static PyObject * widgetListboxDel(snackWidget * s, PyObject * args);
static PyObject * widgetListboxGet(snackWidget * s, PyObject * args);
+static PyObject * widgetListboxGetSel(snackWidget * s, PyObject * args);
static PyObject * widgetListboxSet(snackWidget * s, PyObject * args);
static PyObject * widgetListboxClear(snackWidget * s, PyObject * args);
static PyObject * widgetTextboxText(snackWidget * s, PyObject * args);
{ "listboxAddItem", (PyCFunction) widgetListboxAdd, METH_VARARGS, NULL },
{ "listboxInsertItem", (PyCFunction) widgetListboxIns, METH_VARARGS, NULL },
{ "listboxGetCurrent", (PyCFunction) widgetListboxGet, METH_VARARGS, NULL },
+ { "listboxGetSelection", (PyCFunction) widgetListboxGetSel, METH_VARARGS, NULL },
{ "listboxSetCurrent", (PyCFunction) widgetListboxSet, METH_VARARGS, NULL },
{ "listboxSetWidth", (PyCFunction) widgetListboxSetW, METH_VARARGS, NULL },
{ "listboxDeleteItem", (PyCFunction) widgetListboxDel, METH_VARARGS, NULL },
static snackWidget * listboxWidget(PyObject * s, PyObject * args) {
snackWidget * widget;
int height;
- int doScroll = 0, returnExit = 0, showCursor = 0 ;
+ int doScroll = 0, returnExit = 0, showCursor = 0, multiple = 0, border = 0;
- if (!PyArg_ParseTuple(args, "i|iii", &height, &doScroll, &returnExit, &showCursor))
+ if (!PyArg_ParseTuple(args, "i|iiiii", &height, &doScroll, &returnExit,
+ &showCursor, &multiple, &border))
return NULL;
widget = snackWidgetNew ();
widget->co = newtListbox(-1, -1, height,
(doScroll ? NEWT_FLAG_SCROLL : 0) |
(returnExit ? NEWT_FLAG_RETURNEXIT : 0) |
- (showCursor ? NEWT_FLAG_SHOWCURSOR : 0)
+ (showCursor ? NEWT_FLAG_SHOWCURSOR : 0) |
+ (multiple ? NEWT_FLAG_MULTIPLE : 0) |
+ (border ? NEWT_FLAG_BORDER : 0)
);
widget->anint = 1;
return PyInt_FromLong((long) newtListboxGetCurrent(s->co));
}
+static PyObject * widgetListboxGetSel(snackWidget * s, PyObject * args) {
+ void ** selection;
+ int numselected;
+ int i;
+ PyObject * sel;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+
+ selection = (void **) newtListboxGetSelection(s->co, &numselected);
+
+ sel = PyList_New(0);
+
+ if (!selection) {
+ return sel;
+ }
+
+ sel = PyList_New(0);
+ for (i = 0; i < numselected; i++) {
+ PyList_Append(sel, PyInt_FromLong((long) selection[i]));
+ }
+ free(selection);
+
+ return sel;
+}
+
static PyObject * widgetListboxSet(snackWidget * s, PyObject * args) {
int index;