From: ewt Date: Sat, 11 Dec 1999 21:04:21 +0000 (+0000) Subject: 1) fixed some timer issues X-Git-Tag: r0-50~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=733908603084936bdef34321436eff17d8a645e6;p=thirdparty%2Fnewt.git 1) fixed some timer issues 2) checkboxtree's could improperly leave info from closed trees at the end of the display --- diff --git a/CHANGES b/CHANGES index 36a8aa6..691712a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,7 @@ 0.50 -> 0.51 - added newtFormSetTimer() (and test case, and python) + - checkboxtree's could improperly leave info from closed trees + at the end of the display 0.40 -> 0.50 - added CheckboxTree widget diff --git a/checkboxtree.c b/checkboxtree.c index 5b7ee50..7b4e4da 100644 --- a/checkboxtree.c +++ b/checkboxtree.c @@ -399,6 +399,7 @@ static void ctDraw(newtComponent co) { struct CheckboxTree * ct = co->data; struct items ** item; int i, curr, j; + char * spaces; if (!co->isMapped) return ; @@ -440,6 +441,20 @@ static void ctDraw(newtComponent co) { item++; i++; } + + /* There could be empty lines left (i.e. if the user closes an expanded + list which is the last thing in the tree, and whose elements are + displayed at the bottom of the screen */ + if (i < co->height) { + spaces = alloca(co->width); + memset(spaces, ' ', co->width); + SLsmg_set_color(NEWT_COLORSET_LISTBOX); + } + while (i < co->height) { + newtGotorc(co->top + i, co->left); + SLsmg_write_nstring(spaces, co->width); + i++; + } if(ct->sb) { newtScrollbarSet(ct->sb, ct->currItem - ct->flatList, diff --git a/form.c b/form.c index d4a966b..dca4bbb 100644 --- a/form.c +++ b/form.c @@ -458,6 +458,8 @@ newtComponent newtForm(newtComponent vertBar, const char * help, int flags) { form->background = COLORSET_WINDOW; form->hotKeys = malloc(sizeof(int)); form->numHotKeys = 0; + form->timer = 0; + form->lastTimeout.tv_sec = form->lastTimeout.tv_usec = 0; if (!(form->flags & NEWT_FLAG_NOF12)) { newtFormAddHotKey(co, NEWT_KEY_F12); } @@ -501,6 +503,8 @@ void newtFormSetTimer(newtComponent co, int millisecs) { struct form * form = co->data; form->timer = millisecs; + form->lastTimeout.tv_usec = 0; + form->lastTimeout.tv_sec = 0; } void newtFormSetHeight(newtComponent co, int height) { @@ -897,16 +901,6 @@ void newtFormRun(newtComponent co, struct newtExitStruct * es) { } else gotoComponent(form, form->currComp); - /* Calculate when we next need to return with a timeout */ - if (form->timer) { - if (!form->lastTimeout.tv_sec && !form->lastTimeout.tv_usec) - gettimeofday(&form->lastTimeout, NULL); - - nextTimeout.tv_sec = form->lastTimeout.tv_sec + (form->timer / 1000); - nextTimeout.tv_usec = form->lastTimeout.tv_usec + - (form->timer % 1000) * 1000; - } - while (!done) { newtRefresh(); @@ -930,6 +924,16 @@ void newtFormRun(newtComponent co, struct newtExitStruct * es) { } if (form->timer) { + /* Calculate when we next need to return with a timeout. Do + this inside the loop in case a callback resets the timer. */ + if (!form->lastTimeout.tv_sec && !form->lastTimeout.tv_usec) + gettimeofday(&form->lastTimeout, NULL); + + nextTimeout.tv_sec = form->lastTimeout.tv_sec + + (form->timer / 1000); + nextTimeout.tv_usec = form->lastTimeout.tv_usec + + (form->timer % 1000) * 1000; + gettimeofday(&now, 0); if (now.tv_sec > nextTimeout.tv_sec) { @@ -959,7 +963,7 @@ void newtFormRun(newtComponent co, struct newtExitStruct * es) { if (i == 0) { done = 1; - es->reason = NEWT_EXIT_TIMEOUT; + es->reason = NEWT_EXIT_TIMER; gettimeofday(&form->lastTimeout, NULL); } else #ifdef USE_GPM diff --git a/newt.h b/newt.h index 4511df3..7f396fb 100644 --- a/newt.h +++ b/newt.h @@ -190,7 +190,7 @@ char * newtReflowText(char * text, int width, int flexDown, int flexUp, struct newtExitStruct { enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY, - NEWT_EXIT_TIMEOUT } reason; + NEWT_EXIT_TIMER } reason; union { int key; newtComponent co; diff --git a/snack.py b/snack.py index f43ab90..a8820e9 100644 --- a/snack.py +++ b/snack.py @@ -173,6 +173,8 @@ class Form: (what, which) = self.w.run() if (what == _snack.FORM_EXIT_WIDGET): return self.trans[which] + elif (what == _snack.FORM_EXIT_TIMER): + return "TIMER" return hotkeys[which] @@ -187,6 +189,9 @@ class Form: def setCurrent (self, co): self.w.setcurrent (co.w) + def setTimer (self, timer): + self.w.settimer (timer) + class Grid: def place(self, x, y): @@ -381,6 +386,9 @@ class GridForm(Grid): def addHotKey(self, keyname): self.form.addHotKey(keyname) + def setTimer(self, keyname): + self.form.setTimer(keyname) + def create(self): if not self.form_created: self.place(1,1) diff --git a/snackmodule.c b/snackmodule.c index 800ee5d..ff0392e 100644 --- a/snackmodule.c +++ b/snackmodule.c @@ -127,6 +127,7 @@ static PyObject * formDraw(snackForm * s, PyObject * args); static PyObject * formRun(snackForm * s, PyObject * args); static PyObject * formHotKey(snackForm * s, PyObject * args); static PyObject * formSetCurrent(snackForm * form, PyObject * args); +static PyObject * formSetTimer(snackForm * form, PyObject * args); static PyMethodDef formMethods[] = { { "add", (PyCFunction) formAdd, METH_VARARGS, NULL }, @@ -134,6 +135,7 @@ static PyMethodDef formMethods[] = { { "run", (PyCFunction) formRun, METH_VARARGS, NULL }, { "addhotkey", (PyCFunction) formHotKey, METH_VARARGS, NULL }, { "setcurrent", (PyCFunction) formSetCurrent, METH_VARARGS, NULL }, + { "settimer", (PyCFunction) formSetTimer, METH_VARARGS, NULL }, { NULL } }; @@ -739,6 +741,8 @@ static PyObject * formRun(snackForm * s, PyObject * args) { if (result.reason == NEWT_EXIT_HOTKEY) return Py_BuildValue("(si)", "hotkey", result.u.key); + else if (result.reason == NEWT_EXIT_TIMER) + return Py_BuildValue("(si)", "timer", 0); else return Py_BuildValue("(si)", "widget", result.u.co); } @@ -755,6 +759,18 @@ static PyObject * formHotKey(snackForm * s, PyObject * args) { return Py_None; } +static PyObject * formSetTimer(snackForm * form, PyObject * args) { + int millisecs; + + if (!PyArg_ParseTuple(args, "i", &millisecs)) + return NULL; + + newtFormSetTimer(form->fo, millisecs); + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject * formSetCurrent(snackForm * form, PyObject * args) { snackWidget * w; @@ -983,6 +999,7 @@ void init_snack(void) { PyDict_SetItemString(d, "FORM_EXIT_HOTKEY", PyString_FromString("hotkey")); PyDict_SetItemString(d, "FORM_EXIT_WIDGET", PyString_FromString("widget")); + PyDict_SetItemString(d, "FORM_EXIT_TIMER", PyString_FromString("timer")); PyDict_SetItemString(d, "KEY_F1", PyInt_FromLong(NEWT_KEY_F1)); PyDict_SetItemString(d, "KEY_F2", PyInt_FromLong(NEWT_KEY_F2)); diff --git a/test.c b/test.c index 1455b98..e9ded70 100644 --- a/test.c +++ b/test.c @@ -124,7 +124,7 @@ int main(void) { newtScaleSet(scale, atoi(scaleVal)); newtRefresh(); answer = NULL; - } else if (es.reason == NEWT_EXIT_TIMEOUT) { + } else if (es.reason == NEWT_EXIT_TIMER) { spinState++; if (!*spinState) spinState = spinner; sprintf(buf, "Spinner: %c", *spinState); diff --git a/testtree.c b/testtree.c index 54254e3..4beecc4 100644 --- a/testtree.c +++ b/testtree.c @@ -40,9 +40,18 @@ int main(void) { NEWT_ARG_APPEND, NEWT_ARG_LAST); newtCheckboxTreeAddItem(checktree, "number 11", (void *) 11, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST); - newtCheckboxTreeAddItem(checktree, "number 12", (void *) 12, + newtCheckboxTreeAddItem(checktree, "Donuts", (void *) 12, NEWT_FLAG_SELECTED, NEWT_ARG_APPEND, NEWT_ARG_LAST); + newtCheckboxTreeAddItem(checktree, "Bavarian Cream", (void *) 12, + NEWT_FLAG_SELECTED, + 9, NEWT_ARG_APPEND, NEWT_ARG_LAST); + newtCheckboxTreeAddItem(checktree, "Honey dipped", (void *) 12, + NEWT_FLAG_SELECTED, + 9, NEWT_ARG_APPEND, NEWT_ARG_LAST); + newtCheckboxTreeAddItem(checktree, "Jelly", (void *) 12, + NEWT_FLAG_SELECTED, + 9, NEWT_ARG_APPEND, NEWT_ARG_LAST); newtCheckboxTreeAddItem(checktree, "Colors", (void *) 1, 0, 0, NEWT_ARG_LAST);