]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
1) added help support
authorewt <ewt>
Fri, 28 Apr 2000 15:35:55 +0000 (15:35 +0000)
committerewt <ewt>
Fri, 28 Apr 2000 15:35:55 +0000 (15:35 +0000)
2) version 0.50.10

CHANGES
configure.in
form.c
newt.h
newt.spec
popcorn.py
snack.py
snackmodule.c
test.c

diff --git a/CHANGES b/CHANGES
index 822a03a092df63fde0a84f3b36ea422573a809b4..dc8ff60709943fec13c30851e8e1d38f32dbd874 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,9 @@
+0.59 -> 0.50.10
+       - added support for help
+
+0.57 -> 0.59
+       - minor fixes
+
 0.55 -> 0.56
        - added newtCheckboxTreeSetEntry(), newtCheckboxTreeGetEntryValue()
          and newtCheckboxTreeSetEntryValue()
index 30759d24678783765973fc1c879f210e94661e43..332d39eefeddc82ad39ddd353af4182a5597e286 100644 (file)
@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script.
 
 AC_INIT(newt_pr.h)
 AC_CONFIG_HEADER(config.h)
-VERSION=0.50.9
+VERSION=0.50.10
 SONAME=0.50
 AC_SUBST(VERSION)
 AC_SUBST(SONAME)
diff --git a/form.c b/form.c
index dca4bbb78bd5034040cae8f6db0812a0db26ac65..825fd46bf7de79a30cb18a224fe02a998951d752 100644 (file)
--- a/form.c
+++ b/form.c
@@ -398,6 +398,8 @@ struct form {
     int maxFd;
     int timer;    /* in milliseconds */
     struct timeval lastTimeout;
+    void * helpTag;
+    newtCallback helpCb;
 };
 
 static void gotoComponent(struct form * form, int newComp);
@@ -405,6 +407,9 @@ static struct eventResult formEvent(newtComponent co, struct event ev);
 static struct eventResult sendEvent(newtComponent comp, struct event ev);
 static void formPlace(newtComponent co, int left, int top);
 
+/* Global, ick */
+static newtCallback helpCallback;
+
 /* this isn't static as grid.c tests against it to find forms */
 struct componentOps formOps = {
     newtDrawForm,
@@ -425,7 +430,7 @@ static inline int componentFits(newtComponent co, int compNum) {
     return 1;
 }
 
-newtComponent newtForm(newtComponent vertBar, const char * help, int flags) {
+newtComponent newtForm(newtComponent vertBar, void * help, int flags) {
     newtComponent co;
     struct form * form;
 
@@ -469,6 +474,9 @@ newtComponent newtForm(newtComponent vertBar, const char * help, int flags) {
     else
        form->vertBar = NULL;
 
+    form->helpTag = help;
+    form->helpCb = helpCallback;
+
     return co;
 }
 
@@ -1010,6 +1018,9 @@ void newtFormRun(newtComponent co, struct newtExitStruct * es) {
                    }
                }
 
+               if (key == NEWT_KEY_F1 && form->helpTag && form->helpCb)
+                   form->helpCb(co, form->helpTag);
+
                if (!done) {
                    ev.event = EV_KEYPRESS;
                    ev.u.key = key;
@@ -1093,3 +1104,7 @@ void newtFormWatchFd(newtComponent co, int fd, int fdFlags) {
     form->fds[form->numFds++].flags = fdFlags;
     if (form->maxFd < fd) form->maxFd = fd;
 }
+
+void newtSetHelpCallback(newtCallback cb) {
+    helpCallback = cb;
+}
diff --git a/newt.h b/newt.h
index 635a40ddbced0252d38e1ee17fa9423f00b50cb5..28ad8b59a08a443d826c9436b303a08232bd72ae 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -118,6 +118,7 @@ void newtSetColors(struct newtColors colors);
 void newtRefresh(void);
 void newtSuspend(void);
 void newtSetSuspendCallback(newtSuspendCallback cb, void * data);
+void newtSetHelpCallback(newtCallback cb);
 void newtResume(void);
 void newtPushHelpLine(const char * text);
 void newtRedrawHelpLine(void);
@@ -208,7 +209,7 @@ struct newtExitStruct {
     } u;
 } ;
 
-newtComponent newtForm(newtComponent vertBar, const char * help, int flags);
+newtComponent newtForm(newtComponent vertBar, void * helpTag, int flags);
 void newtFormSetTimer(newtComponent form, int millisecs);
 void newtFormWatchFd(newtComponent form, int fd, int fdFlags);
 void newtFormSetSize(newtComponent co);
index 4e1ce067e2b9c5071bade6cf413200de58be13c5..ee50af7e17f9bf8b563aa45a2a397e771bf17196 100644 (file)
--- 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.9
+%define version 0.50.10
 Version: %{version}
 Release: 1
 Copyright: LGPL
index 588574cc64b06d69029380dd343d4b7fd8905aac..e1283a40c4d10a591be05357552b105b3c171a4d 100755 (executable)
@@ -3,6 +3,9 @@
 from snack import *
 import sys
 
+def help(screen, text):
+    ButtonChoiceWindow(screen, "Help", text)
+
 t = TextboxReflowed(25, "Some text which needs to be wrapped at a good place.")
 li = Listbox(5, width = 20, returnExit = 1)
 li.append("First", "f")
@@ -48,6 +51,8 @@ e.setCallback(sys.exit, 1)
 
 screen = SnackScreen()
 
+screen.helpCallback(help)
+
 foo = EntryWindow(screen, 'Title', 'This is some text for the entry window',
            ['prompt', 'more', 'info'])
 
@@ -73,7 +78,7 @@ g.place(1, 1)
 
 screen.gridWrappedWindow(g, "title")
 
-f = Form()
+f = Form("This is some help")
 f.add(li)
 f.add(b)
 f.add(e)
@@ -83,8 +88,6 @@ f.add(r1)
 f.add(r2)
 f.add(t)
 
-f.addHotKey("F1")
-
 res = f.run()
 
 screen.popWindow()
index 1c68600b9c5212195f2b07774c2c3791ce6a5944..3a46607676852a2ebe6d289fd97821ee882e1997 100644 (file)
--- a/snack.py
+++ b/snack.py
@@ -183,9 +183,11 @@ class Form:
        self.w.draw()
        return None
 
-    def __init__(self):
+    def __init__(self, helpArg = None):
        self.trans = {}
-       self.w = _snack.form()
+       self.w = _snack.form(helpArg)
+       # we do the reference count for the helpArg in python! gross
+       self.helpArg = helpArg
 
     def setCurrent (self, co):
         self.w.setcurrent (co.w)
@@ -245,6 +247,13 @@ class SnackScreen:
     def suspend(self):
        _snack.suspend()
 
+    def doHelpCallback(self, arg):
+       self.helpCb(self, arg)
+
+    def helpCallback(self, cb):
+       self.helpCb = cb
+       return _snack.helpcallback(self.doHelpCallback)
+
     def suspendCallback(self, cb, data = None):
         if data:
             return _snack.suspendcallback(cb, data)
index 876ae51679e0de04c326dd4f29ed1f9c9c8b14f8..cdf5d0441bd6e1b4dee668a85c35f9064ee07226 100644 (file)
@@ -16,6 +16,7 @@ struct callbackStruct {
 };
 
 static struct callbackStruct suspend;
+static struct callbackStruct helpCallback;
 
 static void emptyDestructor(PyObject * s);
 
@@ -46,6 +47,7 @@ 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 * 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);
@@ -62,6 +64,7 @@ static PyMethodDef snackModuleMethods[] = {
     { "form", (PyCFunction) formCreate, METH_VARARGS, NULL },
     { "grid", (PyCFunction) gridCreate, METH_VARARGS, NULL },
     { "gridwrappedwindow", gridWrappedWindow, METH_VARARGS, NULL },
+    { "helpcallback", setHelpCallback, METH_VARARGS, NULL },
     { "init", initScreen, METH_VARARGS, NULL },
     { "label", (PyCFunction) labelWidget, METH_VARARGS, NULL },
     { "listbox", (PyCFunction) listboxWidget, METH_VARARGS, NULL },
@@ -303,6 +306,17 @@ static PyObject * screenSize(PyObject * s, PyObject * args) {
     return Py_BuildValue("(ii)", width, height);
 }
 
+static void helpCallbackMarshall(newtComponent co, void * data) {
+    PyObject * args, * result;
+
+    args = Py_BuildValue("(O)", data);
+    result = PyEval_CallObject(helpCallback.cb, args);
+    Py_DECREF (args);
+    Py_XDECREF(result);
+
+    return;
+}
+
 static void suspendCallbackMarshall(void * data) {
     struct callbackStruct * scs = data;
     PyObject * args, * result;
@@ -358,6 +372,22 @@ static PyObject * setSuspendCallback(PyObject * s, PyObject * args) {
     return Py_None;
 }
 
+static PyObject * setHelpCallback(PyObject * s, PyObject * args) {
+    if (!PyArg_ParseTuple(args, "O", &helpCallback.cb))
+       return NULL;
+
+    /*if (helpCallback.cb) {
+       Py_DECREF (helpCallback.cb);
+    }*/
+
+    Py_INCREF (helpCallback.cb);
+
+    newtSetHelpCallback(helpCallbackMarshall);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
 static PyObject * drawRootText(PyObject * s, PyObject * args) {
     int left, top;
     char * text;
@@ -660,9 +690,15 @@ static snackWidget * entryWidget(PyObject * s, PyObject * args) {
 
 static snackForm * formCreate(PyObject * s, PyObject * args) {
     snackForm * form;
+    PyObject * help = Py_None;
+
+    if (!PyArg_ParseTuple(args, "|O", &help)) return NULL;
+
+    if (help == Py_None)
+       help = NULL;
 
     form = PyObject_NEW(snackForm, &snackFormType);
-    form->fo = newtForm(NULL, NULL, 0);
+    form->fo = newtForm(NULL, help, 0);
 
     return form;
 }
@@ -913,7 +949,7 @@ static PyObject * widgetListboxSet(snackWidget * s, PyObject * args) {
     if (!PyArg_ParseTuple(args, "i", &index))
        return NULL;
 
-    newtListboxSetCurrentByKey(s->co, index);
+    newtListboxSetCurrentByKey(s->co, (void *) index);
 
     Py_INCREF(Py_None);
     return Py_None;
@@ -1046,7 +1082,7 @@ static PyObject * widgetCheckboxTreeGetSel(snackWidget * s,
     if (!PyArg_ParseTuple(args, ""))
        return NULL;
 
-    selection = newtCheckboxTreeGetSelection(s->co, &numselected);
+    selection = (void **) newtCheckboxTreeGetSelection(s->co, &numselected);
 
     sel = PyList_New(0);
     
diff --git a/test.c b/test.c
index e9ded703ee00c309945cd22e709e358e05c99d20..16758e416ec13df0db15840fb0d15e86e38b2936 100644 (file)
--- a/test.c
+++ b/test.c
@@ -28,6 +28,10 @@ void suspend(void * d) {
     newtResume();
 }
 
+void helpCallback(newtComponent co, void * tag) {
+    newtWinMessage("Help", "Ok", tag);
+}
+
 int main(void) {
     newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale;
     newtComponent lb, t, rsf, answer, timeLabel;
@@ -47,6 +51,7 @@ int main(void) {
     newtCls();
 
     newtSetSuspendCallback(suspend, NULL);
+    newtSetHelpCallback(helpCallback);
 
     newtDrawRootText(0, 0, "Newt test program");
     newtPushHelpLine(NULL);
@@ -55,7 +60,7 @@ int main(void) {
     newtOpenWindow(2, 2, 30, 10, "first window");
     newtOpenWindow(10, 5, 65, 16, "window 2");
 
-    f = newtForm(NULL, NULL, 0);
+    f = newtForm(NULL, "This is some help text", 0);
     chklist = newtForm(NULL, NULL, 0);
 
     b1 = newtButton(3, 1, "Exit");