From: ewt Date: Thu, 6 May 1999 17:08:06 +0000 (+0000) Subject: 1) added scale support X-Git-Tag: r0-50~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06cf519e227bd5c6ef3f1d506603254c1c87810b;p=thirdparty%2Fnewt.git 1) added scale support 2) added (but didn't complete) suspend callback support --- diff --git a/newt.c b/newt.c index c52a4cd..330ce85 100644 --- a/newt.c +++ b/newt.c @@ -116,9 +116,11 @@ static const char * version = "Newt windowing library version " VERSION "Written by Erik Troan\n"; static newtSuspendCallback suspendCallback = NULL; +static void * suspendCallbackData = NULL; -void newtSetSuspendCallback(newtSuspendCallback cb) { +void newtSetSuspendCallback(newtSuspendCallback cb, void * data) { suspendCallback = cb; + suspendCallbackData = data; } static void handleSigwinch(int signum) { @@ -280,7 +282,7 @@ int newtGetKey(void) { } if (key == NEWT_KEY_SUSPEND && suspendCallback) - suspendCallback(); + suspendCallback(suspendCallbackData); } while (key == NEWT_KEY_SUSPEND); switch (key) { diff --git a/newt.h b/newt.h index 88c07c3..1bf7203 100644 --- a/newt.h +++ b/newt.h @@ -91,7 +91,7 @@ typedef struct newtComponent_struct * newtComponent; extern const struct newtColors newtDefaultColorPalette; typedef void (*newtCallback)(newtComponent, void *); -typedef void (*newtSuspendCallback)(void); +typedef void (*newtSuspendCallback)(void * data); int newtInit(void); int newtFinished(void); @@ -108,7 +108,7 @@ void newtPopWindow(void); void newtSetColors(struct newtColors colors); void newtRefresh(void); void newtSuspend(void); -void newtSetSuspendCallback(newtSuspendCallback cb); +void newtSetSuspendCallback(newtSuspendCallback cb, void * data); void newtResume(void); void newtPushHelpLine(const char * text); void newtRedrawHelpLine(void); diff --git a/snack.py b/snack.py index f5d407d..09fbc3d 100644 --- a/snack.py +++ b/snack.py @@ -100,6 +100,14 @@ class Label(Widget): def __init__(self, text): self.w = _snack.label(text) +class Scale(Widget): + + def set(self, amount): + self.w.scaleSet(amount) + + def __init__(self, width, total): + self.w = _snack.scale(width, total) + class Entry(Widget): def value(self): @@ -202,6 +210,9 @@ class SnackScreen: def finish(self): return _snack.finish() + def suspendCallback(self, cb, data): + return _snack.suspendcallback(cb, data) + def openWindow(self, left, top, width, height, title): return _snack.openwindow(left, top, width, height, title) @@ -437,4 +448,3 @@ def EntryWindow(screen, title, text, prompts, allowCancel = 1, width = 40, count = count + 1 return (bb.buttonPressed(result), tuple(entryValues)) - diff --git a/snackmodule.c b/snackmodule.c index 7a897fb..b6b5d2e 100644 --- a/snackmodule.c +++ b/snackmodule.c @@ -11,6 +11,10 @@ typedef struct snackWidget_s snackWidget; typedef struct snackGrid_s snackGrid; typedef struct snackForm_s snackForm; +struct suspendCallbackStruct { + PyObject * cb, * data; +}; + static void emptyDestructor(PyObject * s); static snackWidget * buttonWidget(PyObject * s, PyObject * args); @@ -33,7 +37,10 @@ static PyObject * popWindow(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 * scaleWidget(PyObject * s, PyObject * args); +static PyObject * scaleSet(snackWidget * s, PyObject * args); static PyObject * screenSize(PyObject * s, PyObject * args); +static PyObject * setSuspendCallback(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); @@ -60,7 +67,9 @@ static PyMethodDef snackModuleMethods[] = { { "radiobutton", (PyCFunction) radioButtonWidget, METH_VARARGS, NULL }, { "reflow", (PyCFunction) reflowText, METH_VARARGS, NULL }, { "refresh", refreshScreen, METH_VARARGS, NULL }, + { "scale", scaleWidget, METH_VARARGS, NULL }, { "size", screenSize, METH_VARARGS, NULL }, + { "suspendcallback", setSuspendCallback, METH_VARARGS, NULL }, { "ternary", ternaryWindow, METH_VARARGS, NULL }, { "textbox", (PyCFunction) textWidget, METH_VARARGS, NULL }, { NULL } @@ -161,6 +170,7 @@ static PyMethodDef widgetMethods[] = { { "listboxGetCurrent", (PyCFunction) widgetListboxGet, METH_VARARGS, NULL }, { "listboxSetWidth", (PyCFunction) widgetListboxSetW, METH_VARARGS, NULL }, { "listboxDeleteItem", (PyCFunction) widgetListboxDel, METH_VARARGS, NULL }, + { "scaleSet", (PyCFunction) scaleSet, METH_VARARGS, NULL }, { NULL } }; @@ -205,6 +215,29 @@ static PyObject * refreshScreen(PyObject * s, PyObject * args) { return Py_None; } +static PyObject * scaleWidget(PyObject * s, PyObject * args) { + snackWidget * widget; + int width, fullAmount; + + if (!PyArg_ParseTuple(args, "ii", &width, &fullAmount)) return NULL; + + widget = PyObject_NEW(snackWidget, &snackWidgetType); + widget->co = newtScale(-1, -1, width, fullAmount); + + return (PyObject *) widget; +} + +static PyObject * scaleSet(snackWidget * s, PyObject * args) { + int amount; + + if (!PyArg_ParseTuple(args, "i", &amount)) return NULL; + + newtScaleSet(s->co, amount); + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject * screenSize(PyObject * s, PyObject * args) { int width, height; @@ -216,6 +249,30 @@ static PyObject * screenSize(PyObject * s, PyObject * args) { return Py_BuildValue("(ii)", width, height); } +static void suspendCallback(void * data) { + struct suspendCallbackStruct * scs = data; + PyObject * args, * result; + + args = Py_BuildValue("(OO)", scs->data); + result = PyEval_CallObject(scs->cb, args); + Py_DECREF(args); + Py_DECREF(result); + + return ; +} + +static PyObject * setSuspendCallback(PyObject * s, PyObject * args) { + static struct suspendCallbackStruct scs; + + if (!PyArg_ParseTuple(args, "OO", &scs.cb, &scs.data)) + return NULL; + + newtSetSuspendCallback(suspendCallback, &scs); + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject * drawRootText(PyObject * s, PyObject * args) { int left, top; char * text; diff --git a/test.c b/test.c index 3e6eed6..e88a279 100644 --- a/test.c +++ b/test.c @@ -22,7 +22,7 @@ void disableCallback(newtComponent co, void * data) { newtRefresh(); } -void suspend(void) { +void suspend(void * d) { newtSuspend(); raise(SIGTSTP); newtResume(); @@ -43,7 +43,7 @@ int main(void) { newtInit(); newtCls(); - newtSetSuspendCallback(suspend); + newtSetSuspendCallback(suspend, NULL); newtDrawRootText(0, 0, "Newt test program"); newtPushHelpLine(NULL);