]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
1) fixed some timer issues
authorewt <ewt>
Sat, 11 Dec 1999 21:04:21 +0000 (21:04 +0000)
committerewt <ewt>
Sat, 11 Dec 1999 21:04:21 +0000 (21:04 +0000)
2) checkboxtree's could improperly leave info from closed trees
  at the end of the display

CHANGES
checkboxtree.c
form.c
newt.h
snack.py
snackmodule.c
test.c
testtree.c

diff --git a/CHANGES b/CHANGES
index 36a8aa6933ad2f6a5f9a917a216c3fd583676fab..691712aa47277c5e73a2f617da95d8406188fbdf 100644 (file)
--- 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
index 5b7ee50cefe75f56d9d59986701c2183b0d29a85..7b4e4dab8205b3720c346795c8fd1c5b3ef342a7 100644 (file)
@@ -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 d4a966b7d5d409ec41f3f2fd54d56081fb80fa88..dca4bbb78bd5034040cae8f6db0812a0db26ac65 100644 (file)
--- 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 4511df39d1ca970255c80b5db4297a26f99c1ff5..7f396fbf60976e17b5c77ed38c500b3245e8e40e 100644 (file)
--- 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;
index f43ab9006bcb34671f5fd2605b601e3821bfa591..a8820e942a2bda228b5be4d3dc541a372254af40 100644 (file)
--- 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)
index 800ee5ddb596ddf037e955dcbed79ae1601f1b91..ff0392e02c5eeb84016aa28dfa3e1c5c9ed27c39 100644 (file)
@@ -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 1455b98c4dffd0dba6edc3fee6c21ef7b62c4d6f..e9ded703ee00c309945cd22e709e358e05c99d20 100644 (file)
--- 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);
index 54254e383e668c278b7f3bc9a0238114475924ff..4beecc4d717310b6efe3e4124f969aeaeb212fe1 100644 (file)
@@ -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);