From: crutcher Date: Thu, 5 Jul 2001 16:30:36 +0000 (+0000) Subject: added 'hide_checkbox' and 'unselectable' options to CheckboxTree X-Git-Tag: r0-50-28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=615bc463b1bcb3adbfbe42589caacc4f94c6ba08;p=thirdparty%2Fnewt.git added 'hide_checkbox' and 'unselectable' options to CheckboxTree --- diff --git a/checkboxtree.c b/checkboxtree.c index cf3ff41..c5131c7 100644 --- a/checkboxtree.c +++ b/checkboxtree.c @@ -316,10 +316,13 @@ newtComponent newtCheckboxTreeMulti(int left, int top, int height, char *seq, in ct->firstItem = NULL; ct->currItem = NULL; ct->flatList = NULL; - if (seq) - ct->seq = strdup(seq); - else - ct->seq = strdup(" *"); + + ct->flags = flags; + + if (seq) + ct->seq = strdup(seq); + else + ct->seq = strdup(" *"); if (flags & NEWT_FLAG_SCROLL) { ct->sb = newtVerticalScrollbar(left, top, height, COLORSET_LISTBOX, COLORSET_ACTLISTBOX); @@ -369,7 +372,7 @@ int ctSetItem(newtComponent co, struct items *item, enum newtFlagsSense sense) case NEWT_FLAGS_TOGGLE: if (item->branch) item->selected = !item->selected; - else { + else if (!(ct->flags & NEWT_CHECKBOXTREE_UNSELECTABLE)) { item->selected++; if (item->selected==strlen(ct->seq)) item->selected = 0; @@ -444,13 +447,21 @@ static void ctDraw(newtComponent co) { else SLsmg_write_string("<+> "); } else { - char tmp[5]; - snprintf(tmp,5,"[%c] ",ct->seq[(*item)->selected]); - SLsmg_write_string(tmp); + if (ct->flags & NEWT_CHECKBOXTREE_HIDE_BOX) { + if ((*item)->selected) + SLsmg_set_color(NEWT_COLORSET_ACTLISTBOX); + } else { + char tmp[5]; + snprintf(tmp,5,"[%c] ",ct->seq[(*item)->selected]); + SLsmg_write_string(tmp); + } } SLsmg_write_nstring((*item)->text, co->width - 4 - (3 * (*item)->depth)); + + SLsmg_set_color(NEWT_COLORSET_LISTBOX); + item++; i++; } diff --git a/newt.h b/newt.h index 3854240..22aa24a 100644 --- a/newt.h +++ b/newt.h @@ -77,6 +77,9 @@ enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET, NEWT_FLAGS_TOGGLE }; #define NEWT_FD_WRITE (1 << 1) #define NEWT_FD_EXCEPT (1 << 2) +#define NEWT_CHECKBOXTREE_UNSELECTABLE (1 << 12) +#define NEWT_CHECKBOXTREE_HIDE_BOX (1 << 13) + #define NEWT_CHECKBOXTREE_COLLAPSED '\0' #define NEWT_CHECKBOXTREE_EXPANDED '\1' #define NEWT_CHECKBOXTREE_UNSELECTED ' ' @@ -194,7 +197,7 @@ void newtCheckboxTreeSetEntry(newtComponent co, const void * data, char newtCheckboxTreeGetEntryValue(newtComponent co, const void * data); void newtCheckboxTreeSetEntryValue(newtComponent co, const void * data, char value); - + newtComponent newtTextboxReflowed(int left, int top, char * text, int width, int flexDown, int flexUp, int flags); newtComponent newtTextbox(int left, int top, int width, int height, int flags); diff --git a/newt.spec b/newt.spec index 185ad8f..47f16d3 100644 --- a/newt.spec +++ b/newt.spec @@ -1,6 +1,6 @@ Summary: A development library for text mode user interfaces. Name: newt -%define version 0.50.27 +%define version 0.50.28 Version: %{version} Release: 1 Copyright: LGPL @@ -105,6 +105,9 @@ rm -rf $RPM_BUILD_ROOT %endif %changelog +* Thu Jul 05 2001 Crutcher Dunnavant +- added 'hide_checkbox' and 'unselectable' options to CheckboxTrees + * Mon Jun 25 2001 Jeremy Katz - ClistBox -> Clistbox for API consistency - fixup replace() method of Clistbox diff --git a/snack.py b/snack.py index 0460756..2b39821 100644 --- a/snack.py +++ b/snack.py @@ -477,8 +477,8 @@ class CheckboxTree(Widget): curr = self.w.checkboxtreeGetCurrent() return self.key2item[curr] - def __init__(self, height, scroll = 0): - self.w = _snack.checkboxtree(height, scroll) + def __init__(self, height, scroll = 0, hide_checkbox = 0, unselectable = 0): + self.w = _snack.checkboxtree(height, scroll, hide_checkbox, unselectable) self.key2item = {} self.item2key = {} diff --git a/snackmodule.c b/snackmodule.c index d42d52b..db27b6c 100644 --- a/snackmodule.c +++ b/snackmodule.c @@ -55,7 +55,7 @@ static PyObject * setHelpCallback(PyObject * s, PyObject * args); static PyObject * reflowText(PyObject * s, PyObject * args); static snackWidget * textWidget(PyObject * s, PyObject * args); static PyObject * ternaryWindow(PyObject * s, PyObject * args); -static snackWidget * checkboxTreeWidget(PyObject * s, PyObject * args); +static snackWidget * checkboxTreeWidget(PyObject * s, PyObject * args, PyObject * kwargs); static PyMethodDef snackModuleMethods[] = { { "button", (PyCFunction) buttonWidget, METH_VARARGS, NULL }, @@ -88,7 +88,7 @@ static PyMethodDef snackModuleMethods[] = { { "suspendcallback", setSuspendCallback, METH_VARARGS, NULL }, { "ternary", ternaryWindow, METH_VARARGS, NULL }, { "textbox", (PyCFunction) textWidget, METH_VARARGS, NULL }, - { "checkboxtree", (PyCFunction) checkboxTreeWidget, METH_VARARGS, NULL }, + { "checkboxtree", (PyCFunction) checkboxTreeWidget, METH_VARARGS | METH_KEYWORDS, NULL }, { NULL } } ; @@ -225,7 +225,7 @@ static PyMethodDef widgetMethods[] = { { "checkboxtreeSetEntryValue", (PyCFunction) widgetCheckboxTreeSetEntryValue, METH_VARARGS, NULL }, { "checkboxtreeGetSelection", (PyCFunction) widgetCheckboxTreeGetSel, - METH_VARARGS, NULL }, + METH_VARARGS, NULL }, { "entrySetFlags", (PyCFunction) widgetEntrySetFlags, METH_VARARGS, NULL }, { "checkboxSetFlags", (PyCFunction) widgetCheckboxSetFlags, METH_VARARGS, NULL }, { "checkboxSetValue", (PyCFunction) widgetCheckboxSetValue, METH_VARARGS, NULL }, @@ -1031,17 +1031,25 @@ static PyObject * widgetListboxClear(snackWidget * s, PyObject * args) { static void emptyDestructor(PyObject * s) { } -static snackWidget * checkboxTreeWidget(PyObject * s, PyObject * args) { +static snackWidget * checkboxTreeWidget(PyObject * s, PyObject * args, PyObject * kwargs) { int height; int scrollBar = 0; + int hide_checkbox = 0; + int unselectable = 0; + int flags; snackWidget * widget; + const char *kw[] = {"height", "scrollbar", "hide_checkbox", "unselectable", NULL}; - if (!PyArg_ParseTuple(args, "i|i", &height, &scrollBar)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|iii", (char **) kw, + &height, &scrollBar, &hide_checkbox, &unselectable)) return NULL; + flags = (scrollBar ? NEWT_FLAG_SCROLL : 0) | + (hide_checkbox ? NEWT_CHECKBOXTREE_HIDE_BOX : 0) | + (unselectable ? NEWT_CHECKBOXTREE_UNSELECTABLE : 0); + widget = snackWidgetNew (); - widget->co = newtCheckboxTree(-1, -1, height, - scrollBar ? NEWT_FLAG_SCROLL : 0); + widget->co = newtCheckboxTree(-1, -1, height, flags); widget->anint = 1;