]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
1) added scale support
authorewt <ewt>
Thu, 6 May 1999 17:08:06 +0000 (17:08 +0000)
committerewt <ewt>
Thu, 6 May 1999 17:08:06 +0000 (17:08 +0000)
2) added (but didn't complete) suspend callback support

newt.c
newt.h
snack.py
snackmodule.c
test.c

diff --git a/newt.c b/newt.c
index c52a4cdbff6debc28f7c794bfb1536912d7a79b9..330ce85db2c722691b739cfd440bd515acb9ac36 100644 (file)
--- 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 88c07c38c89c408fbea25216b3d9c17bd37f9c49..1bf72030cb8da98aef2179582bb8548dade6fe89 100644 (file)
--- 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);
index f5d407d863bc7646ae9d12e1373dfa9e7f48e092..09fbc3d20d257cbd1268c5e1cffdbbc165847b73 100644 (file)
--- 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))
-   
index 7a897fba153d435e3abca8168e6db4679ebda0e2..b6b5d2ed6088e04c44eabed434b1f9937e443d35 100644 (file)
@@ -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 3e6eed6c0cc48bd3e6e67452359a1bf2527edb37..e88a279ce8222e8e73e3589ffb85b42f1110144d 100644 (file)
--- 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);