diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index 6c86b26f..6aae75db 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -25,6 +25,7 @@ #include #include "plugins/api.h" +#include "plugins/python_api.h" #include "plugins/callbacks.h" #include "profanity.h" #include "ui/notifier.h" @@ -48,53 +49,6 @@ python_api_cons_show(PyObject *self, PyObject *args) return Py_BuildValue(""); } -void -python_command_callback(PluginCommand *command, gchar **args) -{ - PyObject *p_args = NULL; - int num_args = g_strv_length(args); - if (num_args == 0) { - if (command->max_args == 1) { - p_args = Py_BuildValue("(O)", Py_BuildValue("")); - PyObject_CallObject(command->callback, p_args); - Py_XDECREF(p_args); - } else { - PyObject_CallObject(command->callback, p_args); - } - } else if (num_args == 1) { - p_args = Py_BuildValue("(s)", args[0]); - PyObject_CallObject(command->callback, p_args); - Py_XDECREF(p_args); - } else if (num_args == 2) { - p_args = Py_BuildValue("ss", args[0], args[1]); - PyObject_CallObject(command->callback, p_args); - Py_XDECREF(p_args); - } else if (num_args == 3) { - p_args = Py_BuildValue("sss", args[0], args[1], args[2]); - PyObject_CallObject(command->callback, p_args); - Py_XDECREF(p_args); - } else if (num_args == 4) { - p_args = Py_BuildValue("ssss", args[0], args[1], args[2], args[3]); - PyObject_CallObject(command->callback, p_args); - Py_XDECREF(p_args); - } else if (num_args == 5) { - p_args = Py_BuildValue("sssss", args[0], args[1], args[2], args[3], args[4]); - PyObject_CallObject(command->callback, p_args); - Py_XDECREF(p_args); - } - - if (PyErr_Occurred()) { - PyErr_Print(); - PyErr_Clear(); - } -} - -void -python_timed_callback(PluginTimedFunction *timed_function) -{ - PyObject_CallObject(timed_function->callback, NULL); -} - static PyObject* python_api_register_command(PyObject *self, PyObject *args) { @@ -176,6 +130,53 @@ python_api_get_current_recipient(PyObject *self, PyObject *args) } } +void +python_command_callback(PluginCommand *command, gchar **args) +{ + PyObject *p_args = NULL; + int num_args = g_strv_length(args); + if (num_args == 0) { + if (command->max_args == 1) { + p_args = Py_BuildValue("(O)", Py_BuildValue("")); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } else { + PyObject_CallObject(command->callback, p_args); + } + } else if (num_args == 1) { + p_args = Py_BuildValue("(s)", args[0]); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } else if (num_args == 2) { + p_args = Py_BuildValue("ss", args[0], args[1]); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } else if (num_args == 3) { + p_args = Py_BuildValue("sss", args[0], args[1], args[2]); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } else if (num_args == 4) { + p_args = Py_BuildValue("ssss", args[0], args[1], args[2], args[3]); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } else if (num_args == 5) { + p_args = Py_BuildValue("sssss", args[0], args[1], args[2], args[3], args[4]); + PyObject_CallObject(command->callback, p_args); + Py_XDECREF(p_args); + } + + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + } +} + +void +python_timed_callback(PluginTimedFunction *timed_function) +{ + PyObject_CallObject(timed_function->callback, NULL); +} + static PyMethodDef apiMethods[] = { { "cons_alert", python_api_cons_alert, METH_NOARGS, "Highlight the console window in the status bar." }, { "cons_show", python_api_cons_show, METH_VARARGS, "Print a line to the console." }, diff --git a/src/plugins/python_api.h b/src/plugins/python_api.h index 4eaa59e1..68025845 100644 --- a/src/plugins/python_api.h +++ b/src/plugins/python_api.h @@ -27,4 +27,7 @@ void python_init(void); void python_api_init(void); void python_shutdown(void); +void python_command_callback(PluginCommand *command, gchar **args); +void python_timed_callback(PluginTimedFunction *timed_function); + #endif