6
#define NO_IMPORT_PYGOBJECT
10
#include <gconf/gconf-value.h>
12
#include <libawn/awn-applet.h>
13
#include <libawn/awn-applet-dialog.h>
14
#include <libawn/awn-applet-simple.h>
15
#include <libawn/awn-cairo-utils.h>
16
#include <libawn/awn-config-client.h>
17
#include <libawn/awn-defines.h>
18
#include <libawn/awn-effects.h>
19
#include <libawn/awn-enum-types.h>
20
#include <libawn/awn-plug.h>
21
#include <libawn/awn-title.h>
22
#include <libawn/awn-desktop-item.h>
23
#include <libawn/awn-vfs.h>
24
extern Pycairo_CAPI_t *Pycairo_CAPI;
27
_pysequence_to_gslist (PyObject *seq, AwnConfigListType list_type)
32
int len = PySequence_Length (seq);
33
for (i = 0; i < len; i++) {
34
PyObject *item = PySequence_GetItem (seq, i);
37
case AWN_CONFIG_CLIENT_LIST_TYPE_BOOL: {
38
gboolean *data = g_malloc (sizeof (gboolean));
39
*data = (gboolean)PyInt_AsLong (item);
40
list = g_slist_append (list, data);
42
} case AWN_CONFIG_CLIENT_LIST_TYPE_FLOAT: {
43
gdouble *data = g_malloc (sizeof (gdouble));
44
*data = (gdouble)PyFloat_AsDouble (item);
45
list = g_slist_append (list, data);
47
} case AWN_CONFIG_CLIENT_LIST_TYPE_INT: {
48
gint *data = g_malloc (sizeof (gint));
49
*data = (gint)PyInt_AsLong (item);
50
list = g_slist_append (list, data);
52
} case AWN_CONFIG_CLIENT_LIST_TYPE_STRING: {
53
gchar *data = g_strdup (PyString_AsString (item));
54
list = g_slist_append (list, data);
62
_gslist_to_pylist (GSList *list, AwnConfigListType list_type) {
65
gsize slist_len = g_slist_length (list);
66
py_list = PyList_New ((Py_ssize_t)slist_len);
68
for (i = 0; i < slist_len; i++) {
70
gpointer data = g_slist_nth_data (list, i);
73
case AWN_CONFIG_CLIENT_LIST_TYPE_BOOL:
74
py_data = PyBool_FromLong (*((gboolean*)data));
76
case AWN_CONFIG_CLIENT_LIST_TYPE_FLOAT:
77
py_data = PyFloat_FromDouble (*((gdouble*)data));
79
case AWN_CONFIG_CLIENT_LIST_TYPE_INT:
80
py_data = PyInt_FromLong (*((gint*)data));
82
case AWN_CONFIG_CLIENT_LIST_TYPE_STRING:
83
py_data = PyString_FromString ((gchar*)data);
86
if (PyList_SetItem (py_list, i, py_data) == -1) {
87
PyErr_SetString (PyExc_ValueError, "Could not populate the list with the configuration value.");
97
import gobject.GObject as PyGObject_Type
98
import gtk.Dialog as PyGtkDialog_Type
99
import gtk.EventBox as PyGtkEventBox_Type
100
import gtk.HBox as PyGtkHBox_Type
101
import gtk.IconTheme as PyGtkIconTheme_Type
102
import gtk.Plug as PyGtkPlug_Type
103
import gtk.Socket as PyGtkSocket_Type
104
import gtk.VBox as PyGtkVBox_Type
105
import gtk.Widget as PyGtkWidget_Type
106
import gtk.Window as PyGtkWindow_Type
107
import gtk.gdk.Pixbuf as PyGdkPixbuf_Type
112
override awn_config_client_new kwargs
114
_wrap_awn_config_client_new (PyGBoxed *self, PyObject *args, PyObject *kwargs)
116
static char *kwlist[] = { "name", "uid", NULL };
120
if (!PyArg_ParseTupleAndKeywords (args, kwargs,"|ss:AwnConfigClient.__init__", kwlist, &name, &uid)) {
123
self->gtype = AWN_TYPE_CONFIG_CLIENT;
124
self->free_on_dealloc = FALSE;
127
PyErr_SetString (PyExc_ValueError, "The uid argument needs to be defined if the name argument is defined");
130
self->boxed = awn_config_client_new_for_applet (name, uid);
132
self->boxed = awn_config_client_new ();
136
PyErr_SetString (PyExc_RuntimeError, "could not create AwnConfigClient object");
139
self->free_on_dealloc = TRUE;
143
override awn_config_client_get_list kwargs
145
_wrap_awn_config_client_get_list (PyGBoxed *self, PyObject *args, PyObject *kwargs)
147
static char *kwlist[] = { "group", "key", "list_type", NULL };
149
AwnConfigListType list_type;
151
GError *opt_error = NULL;
153
if (!PyArg_ParseTupleAndKeywords (args, kwargs, "ssi:AwnConfigClient.get_list", kwlist, &group, &key, &list_type)) {
157
ret = awn_config_client_get_list (pyg_boxed_get (self, AwnConfigClient), group, key, list_type, &opt_error);
159
if (pyg_error_check (&opt_error)) {
163
return _gslist_to_pylist (ret, list_type);
166
override awn_config_client_set_list kwargs
168
_wrap_awn_config_client_set_list (PyGBoxed *self, PyObject *args, PyObject *kwargs)
170
static char *kwlist[] = { "group", "key", "list_type", "value", NULL };
172
AwnConfigListType list_type;
174
GSList *the_list = NULL;
175
GError *opt_error = NULL;
177
if (!PyArg_ParseTupleAndKeywords (args, kwargs, "ssiO:AwnConfigClient.set_list", kwlist, &group, &key, &list_type, &py_list)) {
181
if (!PyList_Check (py_list) && !PyTuple_Check (py_list)) {
182
PyErr_SetString (PyExc_TypeError, "Fourth argument not a tuple or list");
185
the_list = _pysequence_to_gslist (py_list, list_type);
187
awn_config_client_set_list (pyg_boxed_get (self, AwnConfigClient), group, key, list_type, the_list, &opt_error);
189
g_slist_foreach (the_list, (GFunc)g_free, NULL);
190
g_slist_free (the_list);
192
if (pyg_error_check (&opt_error)) {
200
override awn_applet_simple_set_temp_icon kwargs
202
_wrap_awn_applet_simple_set_temp_icon (PyGObject *self, PyObject *args, PyObject *kwargs)
204
return _wrap_awn_applet_simple_set_icon (self, args, kwargs);
207
override awn_config_client_notify_add kwargs
208
/* Borrowed from gnome-python/trunk/gconf/gconf.override, r585 */
210
pyawn_config_client_notify_add (AwnConfigClientNotifyEntry *entry, PyObject *tuple)
213
PyObject *userdata = NULL;
214
PyObject *notify_entry;
217
PyGILState_STATE state;
219
state = pyg_gil_state_ensure ();
221
g_assert (PyTuple_Check (tuple));
222
func = PyTuple_GetItem (tuple, 0);
223
userdata = PyTuple_GetItem (tuple, 1);
225
/* build the AwnConfigClientNotifyEntry python equivalent manually, as a dictionary */
226
notify_entry = PyDict_New ();
227
PyDict_SetItemString (notify_entry, "client", pyg_boxed_new (AWN_TYPE_CONFIG_CLIENT, entry->client, TRUE, TRUE));
228
PyDict_SetItemString (notify_entry, "group", PyString_FromString (entry->group));
229
PyDict_SetItemString (notify_entry, "key", PyString_FromString (entry->key));
230
switch (awn_config_client_get_value_type (entry->client, entry->group, entry->key, NULL)) {
231
case AWN_CONFIG_VALUE_TYPE_BOOL:
232
value = PyBool_FromLong (entry->value.bool_val);
234
case AWN_CONFIG_VALUE_TYPE_FLOAT:
235
value = PyFloat_FromDouble (entry->value.float_val);
237
case AWN_CONFIG_VALUE_TYPE_INT:
238
value = PyInt_FromLong (entry->value.int_val);
240
case AWN_CONFIG_VALUE_TYPE_STRING:
241
value = PyString_FromString (entry->value.str_val);
243
case AWN_CONFIG_VALUE_TYPE_LIST_BOOL:
244
value = _gslist_to_pylist (entry->value.list_val, AWN_CONFIG_CLIENT_LIST_TYPE_BOOL);
246
case AWN_CONFIG_VALUE_TYPE_LIST_FLOAT:
247
value = _gslist_to_pylist (entry->value.list_val, AWN_CONFIG_CLIENT_LIST_TYPE_FLOAT);
249
case AWN_CONFIG_VALUE_TYPE_LIST_INT:
250
value = _gslist_to_pylist (entry->value.list_val, AWN_CONFIG_CLIENT_LIST_TYPE_INT);
252
case AWN_CONFIG_VALUE_TYPE_LIST_STRING:
253
value = _gslist_to_pylist (entry->value.list_val, AWN_CONFIG_CLIENT_LIST_TYPE_STRING);
256
PyErr_Format (PyExc_ValueError, "Could not determine the value type of the configuration key '[%s]%s'.", entry->group, entry->key);
260
PyDict_SetItemString (notify_entry, "value", value);
263
ret = PyObject_CallFunction (func, "N", notify_entry);
265
ret = PyObject_CallFunction (func, "NO", notify_entry, userdata);
274
pyg_gil_state_release (state);
278
_wrap_awn_config_client_notify_add (PyGBoxed *self, PyObject *args, PyObject *kwargs)
280
static char *kwlist[] = { "group", "key", "func", "user_data", NULL };
284
PyObject *extra = NULL;
287
if (!PyArg_ParseTupleAndKeywords (args, kwargs,
288
"ssO|O:AwnConfigClient.notify_add",
289
kwlist, &group, &key,
290
&callback, &extra)) {
294
if (!PyCallable_Check (callback)) {
295
PyErr_SetString (PyExc_TypeError, "Third argument not callable");
302
extra = PyTuple_New (0);
305
data = Py_BuildValue ("(ON)", callback, extra);
307
awn_config_client_notify_add (pyg_boxed_get(self, AwnConfigClient),
309
(AwnConfigClientNotifyFunc)pyawn_config_client_notify_add,
316
override awn_desktop_item_launch kwargs
318
_wrap_awn_desktop_item_launch (PyGBoxed *self, PyObject *args, PyObject *kwargs)
320
static char *kwlist[] = { "documents", NULL };
321
PyObject *py_documents = NULL;
322
GSList *documents = NULL;
323
GError *opt_error = NULL;
326
if (!PyArg_ParseTupleAndKeywords (args, kwargs, "|O:AwnDesktopItem.launch", kwlist, &py_documents)) {
331
if (PyList_Check (py_documents) || PyTuple_Check (py_documents)) {
332
/* abuse the utility function */
333
documents = _pysequence_to_gslist (py_documents, AWN_CONFIG_CLIENT_LIST_TYPE_STRING);
334
} else if (PyString_Check (py_documents)) {
335
/* only one argument */
336
documents = g_slist_append (documents, PyString_AsString (py_documents));
338
PyErr_SetString (PyExc_TypeError, "Argument is not a sequence");
343
pid = awn_desktop_item_launch (pyg_boxed_get (self, AwnDesktopItem), documents, &opt_error);
345
if (pyg_error_check (&opt_error)) {
349
return PyInt_FromLong (pid);
352
override awn_cairo_string_to_color kwargs
354
_wrap_awn_cairo_string_to_color (PyObject *self, PyObject *args, PyObject *kwargs)
356
static char *kwlist[] = { "color_string", NULL };
358
const gchar *color_string;
359
AwnColor *color = g_malloc (sizeof (AwnColor));
360
PyObject *color_dict;
362
if (!PyArg_ParseTupleAndKeywords (args, kwargs, "s:cairo_string_to_color", kwlist, &color_string)) {
366
awn_cairo_string_to_color (color_string, color);
368
color_dict = PyDict_New ();
369
PyDict_SetItemString (color_dict, "red", PyFloat_FromDouble (color->red));
370
PyDict_SetItemString (color_dict, "green", PyFloat_FromDouble (color->green));
371
PyDict_SetItemString (color_dict, "blue", PyFloat_FromDouble (color->blue));
372
PyDict_SetItemString (color_dict, "alpha", PyFloat_FromDouble (color->alpha));
379
override awn_config_client_key_lock_open kwargs
381
_wrap_awn_config_client_key_lock_open(PyObject *self, PyObject *args, PyObject *kwargs)
383
static char *kwlist[] = { "group", "key", NULL };
387
if (!PyArg_ParseTupleAndKeywords (args, kwargs,"ss:AwnConfigClient.lock_open", kwlist, &group, &key))
390
ret = awn_config_client_key_lock_open (group, key);
392
return PyInt_FromLong (ret);
395
override awn_config_client_key_lock kwargs
397
_wrap_awn_config_client_key_lock (PyObject *self, PyObject *args, PyObject *kwargs)
399
static char *kwlist[] = { "fd", "operation", NULL };
400
int fd, operation, ret;
402
if (!PyArg_ParseTupleAndKeywords (args, kwargs,"ii:AwnConfigClient.lock", kwlist, &fd, &operation))
405
ret = awn_config_client_key_lock (fd, operation);
408
return PyErr_SetFromErrno(PyExc_IOError);
415
override awn_config_client_key_lock_close kwargs
417
_wrap_awn_config_client_key_lock_close (PyObject *self, PyObject *args, PyObject *kwargs)
419
static char *kwlist[] = { "fd", NULL };
422
if (!PyArg_ParseTupleAndKeywords (args, kwargs,"i:AwnConfigClient.lock_close", kwlist, &fd))
425
ret = awn_config_client_key_lock_close (fd);
428
return PyErr_SetFromErrno(PyExc_IOError);