+void eMainloop::reset()
+{
+ app_quit_now=false;
+}
+
+PyObject *eMainloop::poll(ePyObject timeout, ePyObject dict)
+{
+ PyObject *res=0;
+
+ if (app_quit_now)
+ Py_RETURN_NONE;
+
+ int twisted_timeout = (timeout == Py_None) ? 0 : PyInt_AsLong(timeout);
+
+ iterate(twisted_timeout, &res, dict);
+ if (res)
+ return res;
+
+ return PyList_New(0); /* return empty list on timeout */
+}
+
+void eMainloop::interruptPoll()
+{
+ m_interrupt_requested = 1;
+}
+
+void eMainloop::quit(int ret)
+{
+ retval = ret;
+ app_quit_now = true;
+}
+
+eApplication* eApp = 0;
+
+#include "structmember.h"
+
+extern "C" {
+
+// eTimer replacement
+
+struct eTimerPy
+{
+ PyObject_HEAD
+ eTimer *tm;
+ PyObject *in_weakreflist; /* List of weak references */
+};
+
+static int
+eTimerPy_traverse(eTimerPy *self, visitproc visit, void *arg)
+{
+ PyObject *obj = self->tm->timeout.getSteal();
+ if (obj) {
+ Py_VISIT(obj);
+ }
+ return 0;
+}
+
+static int
+eTimerPy_clear(eTimerPy *self)
+{
+ PyObject *obj = self->tm->timeout.getSteal(true);
+ if (obj)
+ Py_CLEAR(obj);
+ return 0;
+}
+
+static void
+eTimerPy_dealloc(eTimerPy* self)
+{
+ if (self->in_weakreflist != NULL)
+ PyObject_ClearWeakRefs((PyObject *) self);
+ eTimerPy_clear(self);
+ self->tm->Release();
+ self->ob_type->tp_free((PyObject*)self);
+}
+
+static PyObject *
+eTimerPy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ eTimerPy *self = (eTimerPy *)type->tp_alloc(type, 0);
+ self->tm = eTimer::create(eApp);
+ self->tm->AddRef();
+ self->in_weakreflist = NULL;
+ return (PyObject *)self;
+}
+
+static PyObject *
+eTimerPy_is_active(eTimerPy* self)
+{
+ PyObject *ret = NULL;
+ ret = self->tm->isActive() ? Py_True : Py_False;
+ Org_Py_INCREF(ret);
+ return ret;
+}
+
+static PyObject *
+eTimerPy_start(eTimerPy* self, PyObject *args)
+{
+ long v=0;
+ long singleShot=0;
+ if (PyTuple_Size(args) > 1)
+ {
+ if (!PyArg_ParseTuple(args, "ll", &v, &singleShot)) // when 2nd arg is a value
+ {
+ PyObject *obj=0;
+ if (!PyArg_ParseTuple(args, "lO", &v, &obj)) // get 2nd arg as python object
+ return NULL;
+ else if (obj == Py_True)
+ singleShot=1;
+ else if (obj != Py_False)
+ return NULL;
+ }
+ }
+ else if (!PyArg_ParseTuple(args, "l", &v))
+ return NULL;
+ self->tm->start(v, singleShot);
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+eTimerPy_start_long(eTimerPy* self, PyObject *args)
+{
+ int v=0;
+ if (!PyArg_ParseTuple(args, "i", &v)) {
+ return NULL;
+ }
+ self->tm->startLongTimer(v);
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+eTimerPy_change_interval(eTimerPy* self, PyObject *args)
+{
+ long v=0;
+ if (!PyArg_ParseTuple(args, "l", &v)) {
+ return NULL;
+ }
+ self->tm->changeInterval(v);
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+eTimerPy_stop(eTimerPy* self)
+{
+ self->tm->stop();
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+eTimerPy_get_callback_list(eTimerPy *self)
+{ //used for compatibilty with the old eTimer
+ return self->tm->timeout.get();
+}
+
+static PyMethodDef eTimerPy_methods[] = {
+ {"isActive", (PyCFunction)eTimerPy_is_active, METH_NOARGS,
+ "returns the timer state"
+ },
+ {"start", (PyCFunction)eTimerPy_start, METH_VARARGS,
+ "start timer with interval in msecs"
+ },
+ {"startLongTimer", (PyCFunction)eTimerPy_start_long, METH_VARARGS,
+ "start timer with interval in secs"
+ },
+ {"changeInterval", (PyCFunction)eTimerPy_change_interval, METH_VARARGS,
+ "change interval of a timer (in msecs)"
+ },
+ {"stop", (PyCFunction)eTimerPy_stop, METH_NOARGS,
+ "stops the timer"
+ },
+ //used for compatibilty with the old eTimer
+ {"get", (PyCFunction)eTimerPy_get_callback_list, METH_NOARGS,
+ "get timeout callback list"
+ },
+ {NULL} /* Sentinel */
+};
+
+static PyObject *
+eTimerPy_get_cb_list(eTimerPy *self, void *closure)