1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Moved python callbacks

This commit is contained in:
James Booth 2013-08-18 00:12:29 +01:00
parent f15b61e4cb
commit 9ca23ed24e
2 changed files with 51 additions and 47 deletions

View File

@ -25,6 +25,7 @@
#include <glib.h>
#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." },

View File

@ -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