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
struct CheckboxTree * ct = co->data;
struct items ** item;
int i, curr, j;
+ char * spaces;
if (!co->isMapped) return ;
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,
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);
}
struct form * form = co->data;
form->timer = millisecs;
+ form->lastTimeout.tv_usec = 0;
+ form->lastTimeout.tv_sec = 0;
}
void newtFormSetHeight(newtComponent co, int height) {
} 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();
}
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) {
if (i == 0) {
done = 1;
- es->reason = NEWT_EXIT_TIMEOUT;
+ es->reason = NEWT_EXIT_TIMER;
gettimeofday(&form->lastTimeout, NULL);
} else
#ifdef USE_GPM
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;
(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]
def setCurrent (self, co):
self.w.setcurrent (co.w)
+ def setTimer (self, timer):
+ self.w.settimer (timer)
+
class Grid:
def place(self, x, y):
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)
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 },
{ "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 }
};
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);
}
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;
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));
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);
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);