diff options
| author | Christopher Davis <loafier@gmail.com> | 2006-07-14 10:02:13 +0000 |
|---|---|---|
| committer | Christopher Davis <loafier@gmail.com> | 2006-07-14 10:02:13 +0000 |
| commit | 5eaed0dbf78fca2bcf185da0abf1dbf41722deb2 (patch) | |
| tree | 2ff9c8bc5c8d206f2b7a852609d1eac6bd377d27 /objects | |
| parent | 34cdeaae9369af5dce3ce3a4a7756c033bc44cc5 (diff) | |
| download | irssi-python-5eaed0dbf78fca2bcf185da0abf1dbf41722deb2.tar.gz irssi-python-5eaed0dbf78fca2bcf185da0abf1dbf41722deb2.tar.xz irssi-python-5eaed0dbf78fca2bcf185da0abf1dbf41722deb2.zip | |
finished up themes. time for textui stuff
git-svn-id: http://svn.irssi.org/repos/irssi-python@4297 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'objects')
| -rw-r--r-- | objects/Makefile | 3 | ||||
| -rw-r--r-- | objects/factory.c | 3 | ||||
| -rw-r--r-- | objects/factory.h | 1 | ||||
| -rw-r--r-- | objects/theme-object.c | 195 | ||||
| -rw-r--r-- | objects/theme-object.h | 18 |
5 files changed, 219 insertions, 1 deletions
diff --git a/objects/Makefile b/objects/Makefile index 8ebf7c1..39f6195 100644 --- a/objects/Makefile +++ b/objects/Makefile @@ -15,7 +15,8 @@ chatnet-object.o reconnect-object.o window-object.o textdest-object.o \ rawlog-object.o log-object.o logitem-object.o ignore-object.o \ dcc-object.o dcc-chat-object.o dcc-get-object.o dcc-send-object.o \ netsplit-object.o netsplit-server-object.o netsplit-channel-object.o \ -notifylist-object.o process-object.o command-object.o factory.o +notifylist-object.o process-object.o command-object.o theme-object.o \ +factory.o pyobjects.a: $(OBJ) ar r pyobjects.a $(OBJ) diff --git a/objects/factory.c b/objects/factory.c index 5b77427..bfc19ab 100644 --- a/objects/factory.c +++ b/objects/factory.c @@ -119,6 +119,9 @@ static int init_objects(void) if (!command_object_init()) return 0; + if (!theme_object_init()) + return 0; + return 1; } diff --git a/objects/factory.h b/objects/factory.h index 14a3b7c..b7eb0e7 100644 --- a/objects/factory.h +++ b/objects/factory.h @@ -32,6 +32,7 @@ #include "notifylist-object.h" #include "process-object.h" #include "command-object.h" +#include "theme-object.h" int factory_init(void); void factory_deinit(void); diff --git a/objects/theme-object.c b/objects/theme-object.c new file mode 100644 index 0000000..0f12217 --- /dev/null +++ b/objects/theme-object.c @@ -0,0 +1,195 @@ +#include <Python.h> +#include "pyirssi.h" +#include "pymodule.h" +#include "theme-object.h" +#include "factory.h" +#include "pycore.h" + +/* monitor "theme destroyed" signal */ +static void theme_cleanup(THEME_REC *rec) +{ + PyTheme *pytheme = signal_get_user_data(); + if (pytheme->data == rec) + { + pytheme->data = NULL; + pytheme->cleanup_installed = 0; + signal_remove_data("theme destroyed", theme_cleanup, pytheme); + } +} + +static void PyTheme_dealloc(PyTheme *self) +{ + if (self->cleanup_installed) + signal_remove_data("theme destroyed", theme_cleanup, self); + + self->ob_type->tp_free((PyObject*)self); +} + +static PyObject *PyTheme_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyTheme *self; + + self = (PyTheme *)type->tp_alloc(type, 0); + if (!self) + return NULL; + + return (PyObject *)self; +} + +/* Getters */ +/* specialized getters/setters */ +static PyGetSetDef PyTheme_getseters[] = { + {NULL} +}; + +/* Methods */ +PyDoc_STRVAR(PyTheme_format_expand_doc, + "format_expand(format, flags=0) -> str or None\n" +); +static PyObject *PyTheme_format_expand(PyTheme *self, PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {"format", "flags", NULL}; + char *format = ""; + int flags = 0; + char *ret; + PyObject *pyret; + + RET_NULL_IF_INVALID(self->data); + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|i", kwlist, + &format, &flags)) + return NULL; + + if (flags == 0) + ret = theme_format_expand(self->data, format); + else + ret = theme_format_expand_data(self->data, (const char **)&format, 'n', 'n', + NULL, NULL, EXPAND_FLAG_ROOT | flags); + + if (ret) + { + pyret = PyString_FromString(ret); + g_free(ret); + return pyret; + } + + Py_RETURN_NONE; +} + +PyDoc_STRVAR(PyTheme_get_format_doc, + "get_format(module, tag) -> str\n" +); +static PyObject *PyTheme_get_format(PyTheme *self, PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {"module", "tag", NULL}; + char *module = ""; + char *tag = ""; + THEME_REC *theme = self->data; + FORMAT_REC *formats; + MODULE_THEME_REC *modtheme; + int i; + + RET_NULL_IF_INVALID(self->data); + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss", kwlist, + &module, &tag)) + return NULL; + + formats = g_hash_table_lookup(default_formats, module); + if (!formats) + return PyErr_Format(PyExc_KeyError, "unknown module, %s", module); + + for (i = 0; formats[i].def; i++) + { + if (formats[i].tag && !g_strcasecmp(formats[i].tag, tag)) + { + modtheme = g_hash_table_lookup(theme->modules, module); + if (modtheme && modtheme->formats[i]) + return PyString_FromString(modtheme->formats[i]); + else + return PyString_FromString(formats[i].def); + } + } + + return PyErr_Format(PyExc_KeyError, "unknown format tag, %s", tag); +} + +/* Methods for object */ +static PyMethodDef PyTheme_methods[] = { + {"format_expand", (PyCFunction)PyTheme_format_expand, METH_VARARGS | METH_KEYWORDS, + PyTheme_format_expand_doc}, + {"get_format", (PyCFunction)PyTheme_get_format, METH_VARARGS | METH_KEYWORDS, + PyTheme_get_format_doc}, + {NULL} /* Sentinel */ +}; + +PyTypeObject PyThemeType = { + PyObject_HEAD_INIT(NULL) + 0, /*ob_size*/ + "Theme", /*tp_name*/ + sizeof(PyTheme), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor)PyTheme_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + PyTheme_methods, /* tp_methods */ + 0, /* tp_members */ + PyTheme_getseters, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + PyTheme_new, /* tp_new */ +}; + +/* Theme factory function */ +PyObject *pytheme_new(void *td) +{ + PyTheme *pytheme; + + pytheme = py_inst(PyTheme, PyThemeType); + if (!pytheme) + return NULL; + + pytheme->data = td; + signal_add_last_data("theme destroyed", theme_cleanup, pytheme); + pytheme->cleanup_installed = 1; + + return (PyObject *)pytheme; +} + +int theme_object_init(void) +{ + g_return_val_if_fail(py_module != NULL, 0); + + if (PyType_Ready(&PyThemeType) < 0) + return 0; + + Py_INCREF(&PyThemeType); + PyModule_AddObject(py_module, "Theme", (PyObject *)&PyThemeType); + + return 1; +} diff --git a/objects/theme-object.h b/objects/theme-object.h new file mode 100644 index 0000000..299d54d --- /dev/null +++ b/objects/theme-object.h @@ -0,0 +1,18 @@ +#ifndef _THEME_OBJECT_H_ +#define _THEME_OBJECT_H_ + +#include <Python.h> +#include "base-objects.h" + +typedef struct +{ + PyIrssiFinal_HEAD(void) +} PyTheme; + +extern PyTypeObject PyThemeType; + +int theme_object_init(void); +PyObject *pytheme_new(void *td); +#define pytheme_check(op) PyObject_TypeCheck(op, &PyThemeType) + +#endif |
