]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
- add support for listbox multiple selection and border to snack (Shawn Starr)
authormlichvar <mlichvar>
Fri, 8 Jun 2007 12:15:19 +0000 (12:15 +0000)
committermlichvar <mlichvar>
Fri, 8 Jun 2007 12:15:19 +0000 (12:15 +0000)
newt.spec
snack.py
snackmodule.c

index 641799a01862e7f882b6a114e4b8adf31f35585c..a88923b7a23f086d876477178e571378a12f54b7 100644 (file)
--- a/newt.spec
+++ b/newt.spec
@@ -88,6 +88,8 @@ rm -rf $RPM_BUILD_ROOT
 %{_libdir}/libnewt.a
 
 %changelog
+- add support for listbox multiple selection and border to snack
+  (patch by Shawn Starr)
 - fix scrollbar positioning in listbox
 - cope with backward system time jumps (#240691)
 - free helplines and windows in newtFinished, check for overflow (#239992)
index e11e4305aab8f23f464451aa6edd1c216713d97d..e40515bde334b205e6288e501f4a95a1c7e867cf 100644 (file)
--- a/snack.py
+++ b/snack.py
@@ -144,11 +144,12 @@ class Listbox(Widget):
 
     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
     """
@@ -181,6 +182,13 @@ class Listbox(Widget):
     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])
 
@@ -189,8 +197,8 @@ class Listbox(Widget):
         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):
index 96ed4aa8c00c6f6dee553a7969ec460e602c3f1a..3a47a3d26aa2e6b23cb4010f4e37dc2f0e0d70cf 100644 (file)
@@ -200,6 +200,7 @@ 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 * 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);
@@ -223,6 +224,7 @@ static PyMethodDef widgetMethods[] = {
     { "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 },
@@ -654,16 +656,19 @@ static PyObject * widgetTextboxText(snackWidget * s, PyObject * args) {
 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;
     
@@ -1032,6 +1037,32 @@ static PyObject * widgetListboxGet(snackWidget * s, PyObject * args) {
     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;