]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
- add python binding for newtSetColor
authormlichvar <mlichvar>
Wed, 28 Feb 2007 17:37:57 +0000 (17:37 +0000)
committermlichvar <mlichvar>
Wed, 28 Feb 2007 17:37:57 +0000 (17:37 +0000)
snack.py
snackmodule.c

index 1bd2424ae140ce4bf7dc11846cf962e9edf483f3..e11e4305aab8f23f464451aa6edd1c216713d97d 100644 (file)
--- a/snack.py
+++ b/snack.py
@@ -395,6 +395,30 @@ class Grid:
         self.g = apply(_snack.grid, args)
         self.gridmembers = []
 
+colorsets = { "ROOT" : _snack.COLORSET_ROOT,
+              "BORDER" : _snack.COLORSET_BORDER,
+              "WINDOW" : _snack.COLORSET_WINDOW,
+              "SHADOW" : _snack.COLORSET_SHADOW,
+              "TITLE" : _snack.COLORSET_TITLE,
+              "BUTTON" : _snack.COLORSET_BUTTON,
+              "ACTBUTTON" : _snack.COLORSET_ACTBUTTON,
+              "CHECKBOX" : _snack.COLORSET_CHECKBOX,
+              "ACTCHECKBOX" : _snack.COLORSET_ACTCHECKBOX,
+              "ENTRY" : _snack.COLORSET_ENTRY,
+              "LABEL" : _snack.COLORSET_LABEL,
+              "LISTBOX" : _snack.COLORSET_LISTBOX,
+              "ACTLISTBOX" : _snack.COLORSET_ACTLISTBOX,
+              "TEXTBOX" : _snack.COLORSET_TEXTBOX,
+              "ACTTEXTBOX" : _snack.COLORSET_ACTTEXTBOX,
+              "HELPLINE" : _snack.COLORSET_HELPLINE,
+              "ROOTTEXT" : _snack.COLORSET_ROOTTEXT,
+              "EMPTYSCALE" : _snack.COLORSET_EMPTYSCALE,
+              "FULLSCALE" : _snack.COLORSET_FULLSCALE,
+              "DISENTRY" : _snack.COLORSET_DISENTRY,
+              "COMPACTBUTTON" : _snack.COLORSET_COMPACTBUTTON,
+              "ACTSELLISTBOX" : _snack.COLORSET_ACTSELLISTBOX,
+              "SELLISTBOX" : _snack.COLORSET_SELLISTBOX }
+
 class SnackScreen:
     """A Screen;
 
@@ -468,6 +492,9 @@ class SnackScreen:
     def refresh(self):
         return _snack.refresh()
 
+    def setColor(self, colorset, fg, bg):
+        return _snack.setcolor(colorsets[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
     """
index c71c2dfb03685b0a9dbef06704cc582f0b88fcf2..96ed4aa8c00c6f6dee553a7969ec460e602c3f1a 100644 (file)
@@ -57,6 +57,7 @@ static PyObject * popWindowNoRefresh(PyObject * s, PyObject * args);
 static PyObject * pushHelpLine(PyObject * s, PyObject * args);
 static snackWidget * radioButtonWidget(PyObject * s, PyObject * args);
 static PyObject * refreshScreen(PyObject * s, PyObject * args);
+static PyObject * setColor(PyObject * s, PyObject * args);
 static PyObject * scaleWidget(PyObject * s, PyObject * args);
 static PyObject * scaleSet(snackWidget * s, PyObject * args);
 static PyObject * screenSize(PyObject * s, PyObject * args);
@@ -93,6 +94,7 @@ static PyMethodDef snackModuleMethods[] = {
     { "radiobutton", (PyCFunction) radioButtonWidget, METH_VARARGS, NULL },
     { "reflow", (PyCFunction) reflowText, METH_VARARGS, NULL },
     { "refresh", refreshScreen, METH_VARARGS, NULL },
+    { "setcolor", setColor, METH_VARARGS, NULL },
     { "resume", doResume, METH_VARARGS, NULL },
     { "scale", scaleWidget, METH_VARARGS, NULL },
     { "size", screenSize, METH_VARARGS, NULL },
@@ -301,6 +303,18 @@ static PyObject * refreshScreen(PyObject * s, PyObject * args) {
     return Py_None;
 }
 
+static PyObject * setColor(PyObject * s, PyObject * args) {
+    char * fg, * bg;
+    int colorset;
+    if (!PyArg_ParseTuple(args, "iss", &colorset, &fg, &bg))
+       return NULL;
+
+    newtSetColor(colorset, fg, bg);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
 static PyObject * scaleWidget(PyObject * s, PyObject * args) {
     snackWidget * widget;
     int width, fullAmount;
@@ -1270,4 +1284,28 @@ void init_snack(void) {
     PyDict_SetItemString(d, "FLAGS_SET", PyInt_FromLong(NEWT_FLAGS_SET));
     PyDict_SetItemString(d, "FLAGS_RESET", PyInt_FromLong(NEWT_FLAGS_RESET));
     PyDict_SetItemString(d, "FLAGS_TOGGLE", PyInt_FromLong(NEWT_FLAGS_TOGGLE));
+
+    PyDict_SetItemString(d, "COLORSET_ROOT", PyInt_FromLong(NEWT_COLORSET_ROOT));
+    PyDict_SetItemString(d, "COLORSET_BORDER", PyInt_FromLong(NEWT_COLORSET_BORDER));
+    PyDict_SetItemString(d, "COLORSET_WINDOW", PyInt_FromLong(NEWT_COLORSET_WINDOW));
+    PyDict_SetItemString(d, "COLORSET_SHADOW", PyInt_FromLong(NEWT_COLORSET_SHADOW));
+    PyDict_SetItemString(d, "COLORSET_TITLE", PyInt_FromLong(NEWT_COLORSET_TITLE));
+    PyDict_SetItemString(d, "COLORSET_BUTTON", PyInt_FromLong(NEWT_COLORSET_BUTTON));
+    PyDict_SetItemString(d, "COLORSET_ACTBUTTON", PyInt_FromLong(NEWT_COLORSET_ACTBUTTON));
+    PyDict_SetItemString(d, "COLORSET_CHECKBOX", PyInt_FromLong(NEWT_COLORSET_CHECKBOX));
+    PyDict_SetItemString(d, "COLORSET_ACTCHECKBOX", PyInt_FromLong(NEWT_COLORSET_ACTCHECKBOX));
+    PyDict_SetItemString(d, "COLORSET_ENTRY", PyInt_FromLong(NEWT_COLORSET_ENTRY));
+    PyDict_SetItemString(d, "COLORSET_LABEL", PyInt_FromLong(NEWT_COLORSET_LABEL));
+    PyDict_SetItemString(d, "COLORSET_LISTBOX", PyInt_FromLong(NEWT_COLORSET_LISTBOX));
+    PyDict_SetItemString(d, "COLORSET_ACTLISTBOX", PyInt_FromLong(NEWT_COLORSET_ACTLISTBOX));
+    PyDict_SetItemString(d, "COLORSET_TEXTBOX", PyInt_FromLong(NEWT_COLORSET_TEXTBOX));
+    PyDict_SetItemString(d, "COLORSET_ACTTEXTBOX", PyInt_FromLong(NEWT_COLORSET_ACTTEXTBOX));
+    PyDict_SetItemString(d, "COLORSET_HELPLINE", PyInt_FromLong(NEWT_COLORSET_HELPLINE));
+    PyDict_SetItemString(d, "COLORSET_ROOTTEXT", PyInt_FromLong(NEWT_COLORSET_ROOTTEXT));
+    PyDict_SetItemString(d, "COLORSET_EMPTYSCALE", PyInt_FromLong(NEWT_COLORSET_EMPTYSCALE));
+    PyDict_SetItemString(d, "COLORSET_FULLSCALE", PyInt_FromLong(NEWT_COLORSET_FULLSCALE));
+    PyDict_SetItemString(d, "COLORSET_DISENTRY", PyInt_FromLong(NEWT_COLORSET_DISENTRY));
+    PyDict_SetItemString(d, "COLORSET_COMPACTBUTTON", PyInt_FromLong(NEWT_COLORSET_COMPACTBUTTON));
+    PyDict_SetItemString(d, "COLORSET_ACTSELLISTBOX", PyInt_FromLong(NEWT_COLORSET_ACTSELLISTBOX));
+    PyDict_SetItemString(d, "COLORSET_SELLISTBOX", PyInt_FromLong(NEWT_COLORSET_SELLISTBOX));
 }