From: ewt Date: Fri, 28 Apr 2000 15:35:55 +0000 (+0000) Subject: 1) added help support X-Git-Tag: r0-50-10~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=72b71fa65bf55b3a6117c33ccb1f19b06918342b;p=thirdparty%2Fnewt.git 1) added help support 2) version 0.50.10 --- diff --git a/CHANGES b/CHANGES index 822a03a..dc8ff60 100644 --- 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() diff --git a/configure.in b/configure.in index 30759d2..332d39e 100644 --- a/configure.in +++ b/configure.in @@ -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 dca4bbb..825fd46 100644 --- 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 635a40d..28ad8b5 100644 --- 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); diff --git a/newt.spec b/newt.spec index 4e1ce06..ee50af7 100644 --- 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 diff --git a/popcorn.py b/popcorn.py index 588574c..e1283a4 100755 --- a/popcorn.py +++ b/popcorn.py @@ -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() diff --git a/snack.py b/snack.py index 1c68600..3a46607 100644 --- 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) diff --git a/snackmodule.c b/snackmodule.c index 876ae51..cdf5d04 100644 --- a/snackmodule.c +++ b/snackmodule.c @@ -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 e9ded70..16758e4 100644 --- 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");