]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
add python bindings for setting label colors
authorJoey Boggs <jboggs@redhat.com>
Tue, 31 May 2011 20:17:08 +0000 (16:17 -0400)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 1 Jun 2011 14:45:37 +0000 (16:45 +0200)
snack.py
snackmodule.c

index 7b27e635c61f34326a8009047316c43f7bdeb907..30b760c91025d54d93a98b5fc20e5cf90caaef48 100644 (file)
--- a/snack.py
+++ b/snack.py
@@ -240,6 +240,7 @@ class Label(Widget):
 
      - Label(self,text)   : create label
      - setText(self,text) : change text.
+     - setColors(self, colorset) : change individual colors
     """
     def setText(self, text):
         self.w.labelText(text)
@@ -247,6 +248,9 @@ class Label(Widget):
     def __init__(self, text):
         self.w = _snack.label(text)
 
+    def setColors(self, colorset):
+        self.w.labelSetColors(colorset)
+
 class Scale(Widget):
     """A Scale (progress bar).
 
@@ -517,7 +521,11 @@ class SnackScreen:
         return _snack.refresh()
 
     def setColor(self, colorset, fg, bg):
-        return _snack.setcolor(colorsets[colorset], fg, bg)
+        if colorset in colorsets:
+            return _snack.setcolor(colorsets[colorset], fg, bg)
+        else:
+           # assume colorset is an integer for the custom color set
+           return _snack.setcolor(colorset, fg, bg)
 
 def reflow(text, width, flexDown = 5, flexUp = 5):
     """ returns a tuple of the wrapped text, the actual width, and the actual height
@@ -982,3 +990,6 @@ class CListbox(Grid):
 
     def clear(self):
         self.listbox.clear()
+
+def customColorset(x):
+    return 30 + x
index 55d1a0aa480ff612e16dcc86c45d457702fa2739..78c61247c3ef39ecb8e0564dbe9a5eb51adafbe6 100644 (file)
@@ -195,6 +195,7 @@ static PyObject * widgetGetAttr(PyObject * s, char * name);
 static void widgetDestructor(PyObject * s);
 static PyObject * widgetEntrySetValue(snackWidget * s, PyObject * args);
 static PyObject * widgetLabelText(snackWidget * s, PyObject * args);
+static PyObject * widgetLabelSetColors(snackWidget * s, PyObject * args);
 static PyObject * widgetListboxSetW(snackWidget * s, PyObject * args);
 static PyObject * widgetListboxAdd(snackWidget * s, PyObject * args);
 static PyObject * widgetListboxIns(snackWidget * s, PyObject * args);
@@ -219,6 +220,7 @@ static PyObject * widgetCheckboxSetValue(snackWidget * s, PyObject * args);
 
 static PyMethodDef widgetMethods[] = {
     { "setCallback", (PyCFunction) widgetAddCallback, METH_VARARGS, NULL },
+    { "labelSetColors", (PyCFunction) widgetLabelSetColors, METH_VARARGS, NULL },
     { "labelText", (PyCFunction) widgetLabelText, METH_VARARGS, NULL },
     { "textboxText", (PyCFunction) widgetTextboxText, METH_VARARGS, NULL },
     { "textboxHeight", (PyCFunction) widgetTextboxHeight, METH_VARARGS, NULL },
@@ -662,6 +664,17 @@ static PyObject * widgetLabelText(snackWidget * s, PyObject * args) {
     return Py_None;
 }
 
+static PyObject * widgetLabelSetColors(snackWidget * s, PyObject * args) {
+    int colorset;
+
+    if (!PyArg_ParseTuple(args, "i", &colorset)) return NULL;
+
+    newtLabelSetColors(s->co, colorset);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
 static PyObject * widgetTextboxText(snackWidget * s, PyObject * args) {
     char * text;