diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2006-02-19 10:43:47 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2006-02-19 10:43:47 +0000 |
commit | 3a213f38eca02f158169afd2f140050930f5cdc3 (patch) | |
tree | d46434e51141bb415e90afbdd9a76e65a4249549 /src/plugins/scripts/python/weechat-python.c | |
parent | 484274d65f27d21e8da1823f36fefd67e8bed67b (diff) | |
download | weechat-3a213f38eca02f158169afd2f140050930f5cdc3.zip |
Added timer handler for plugins
Diffstat (limited to 'src/plugins/scripts/python/weechat-python.c')
-rw-r--r-- | src/plugins/scripts/python/weechat-python.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index e3faa6274..07576f1a0 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -417,6 +417,46 @@ weechat_python_add_command_handler (PyObject *self, PyObject *args) } /* + * weechat_python_add_timer_handler: add a timer handler + */ + +static PyObject * +weechat_python_add_timer_handler (PyObject *self, PyObject *args) +{ + int interval; + char *function; + + /* make gcc happy */ + (void) self; + + if (!python_current_script) + { + python_plugin->print_server (python_plugin, + "Python error: unable to add timer handler, " + "script not initialized"); + return Py_BuildValue ("i", 0); + } + + interval = 10; + function = NULL; + + if (!PyArg_ParseTuple (args, "is", &interval, &function)) + { + python_plugin->print_server (python_plugin, + "Python error: wrong parameters for " + "\"add_timer_handler\" function"); + return Py_BuildValue ("i", 0); + } + + if (python_plugin->timer_handler_add (python_plugin, interval, + weechat_python_handler, function, + (void *)python_current_script)) + return Py_BuildValue ("i", 1); + + return Py_BuildValue ("i", 0); +} + +/* * weechat_python_remove_handler: remove a handler */ @@ -454,6 +494,42 @@ weechat_python_remove_handler (PyObject *self, PyObject *args) } /* + * weechat_python_remove_timer_handler: remove a timer handler + */ + +static PyObject * +weechat_python_remove_timer_handler (PyObject *self, PyObject *args) +{ + char *function; + + /* make gcc happy */ + (void) self; + + if (!python_current_script) + { + python_plugin->print_server (python_plugin, + "Python error: unable to remove timer handler, " + "script not initialized"); + return Py_BuildValue ("i", 0); + } + + function = NULL; + + if (!PyArg_ParseTuple (args, "s", &function)) + { + python_plugin->print_server (python_plugin, + "Python error: wrong parameters for " + "\"remove_timer_handler\" function"); + return Py_BuildValue ("i", 0); + } + + weechat_script_remove_timer_handler (python_plugin, python_current_script, + function); + + return Py_BuildValue ("i", 1); +} + +/* * weechat_python_get_info: get various infos */ @@ -1019,7 +1095,9 @@ PyMethodDef weechat_python_funcs[] = { { "command", weechat_python_command, METH_VARARGS, "" }, { "add_message_handler", weechat_python_add_message_handler, METH_VARARGS, "" }, { "add_command_handler", weechat_python_add_command_handler, METH_VARARGS, "" }, + { "add_timer_handler", weechat_python_add_timer_handler, METH_VARARGS, "" }, { "remove_handler", weechat_python_remove_handler, METH_VARARGS, "" }, + { "remove_timer_handler", weechat_python_remove_timer_handler, METH_VARARGS, "" }, { "get_info", weechat_python_get_info, METH_VARARGS, "" }, { "get_dcc_info", weechat_python_get_dcc_info, METH_VARARGS, "" }, { "get_config", weechat_python_get_config, METH_VARARGS, "" }, @@ -1328,6 +1406,25 @@ weechat_python_cmd (t_weechat_plugin *plugin, } if (!handler_found) plugin->print_server (plugin, " (none)"); + + /* list Python timer handlers */ + plugin->print_server (plugin, ""); + plugin->print_server (plugin, "Python timer handlers:"); + handler_found = 0; + for (ptr_handler = plugin->handlers; + ptr_handler; ptr_handler = ptr_handler->next_handler) + { + if ((ptr_handler->type == HANDLER_TIMER) + && (ptr_handler->handler_args)) + { + handler_found = 1; + plugin->print_server (plugin, " %d seconds => Python(%s)", + ptr_handler->interval, + ptr_handler->handler_args); + } + } + if (!handler_found) + plugin->print_server (plugin, " (none)"); break; case 1: if (plugin->ascii_strcasecmp (plugin, argv[0], "autoload") == 0) |