~ubuntu-branches/debian/wheezy/avant-window-navigator/wheezy

« back to all changes in this revision

Viewing changes to bindings/python/awn.override

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2008-05-24 14:42:01 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080524144201-r3v8e4g2hv2q1i9x
Tags: 0.2.6-6
* debian/patches/04-fix-colormap.patch
 - Fix crash in awn-manager if colormap == None. Thanks Emme for the 
   patch. (Closes: #482030) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
headers
 
3
#ifdef HAVE_CONFIG_H
 
4
#include "config.h"
 
5
#endif
 
6
#define NO_IMPORT_PYGOBJECT
 
7
#include "pygobject.h"
 
8
#include <pycairo.h>
 
9
#ifdef USE_GCONF
 
10
#include <gconf/gconf-value.h>
 
11
#endif
 
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;
 
25
 
 
26
static GSList *
 
27
_pysequence_to_gslist (PyObject *seq, AwnConfigListType list_type)
 
28
{
 
29
  GSList *list = NULL;
 
30
 
 
31
  int i;
 
32
  int len = PySequence_Length (seq);
 
33
  for (i = 0; i < len; i++) {
 
34
    PyObject *item = PySequence_GetItem (seq, i);
 
35
    Py_DECREF(item);
 
36
    switch (list_type) {
 
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);
 
41
        break;
 
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);
 
46
        break;
 
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);
 
51
        break;
 
52
      } case AWN_CONFIG_CLIENT_LIST_TYPE_STRING: {
 
53
        gchar *data = g_strdup (PyString_AsString (item));
 
54
        list = g_slist_append (list, data);
 
55
        break;
 
56
      }
 
57
    }
 
58
  }
 
59
  return list;
 
60
}
 
61
static PyObject *
 
62
_gslist_to_pylist (GSList *list, AwnConfigListType list_type) {
 
63
  PyObject *py_list;
 
64
  guint i;
 
65
  gsize slist_len = g_slist_length (list);
 
66
  py_list = PyList_New ((Py_ssize_t)slist_len);
 
67
 
 
68
  for (i = 0; i < slist_len; i++) {
 
69
    PyObject *py_data;
 
70
    gpointer data = g_slist_nth_data (list, i);
 
71
    if (data) {
 
72
      switch (list_type) {
 
73
        case AWN_CONFIG_CLIENT_LIST_TYPE_BOOL:
 
74
          py_data = PyBool_FromLong (*((gboolean*)data));
 
75
          break;
 
76
        case AWN_CONFIG_CLIENT_LIST_TYPE_FLOAT:
 
77
          py_data = PyFloat_FromDouble (*((gdouble*)data));
 
78
          break;
 
79
        case AWN_CONFIG_CLIENT_LIST_TYPE_INT:
 
80
          py_data = PyInt_FromLong (*((gint*)data));
 
81
          break;
 
82
        case AWN_CONFIG_CLIENT_LIST_TYPE_STRING:
 
83
          py_data = PyString_FromString ((gchar*)data);
 
84
          break;
 
85
      }
 
86
      if (PyList_SetItem (py_list, i, py_data) == -1) {
 
87
        PyErr_SetString (PyExc_ValueError, "Could not populate the list with the configuration value.");
 
88
        return NULL;
 
89
      }
 
90
    }
 
91
  }
 
92
  return py_list;
 
93
}
 
94
%%
 
95
modulename awn
 
96
%%
 
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
 
108
%%
 
109
ignore-glob
 
110
  *_get_type
 
111
%%
 
112
override awn_config_client_new kwargs
 
113
static int
 
114
_wrap_awn_config_client_new (PyGBoxed *self, PyObject *args, PyObject *kwargs)
 
115
{
 
116
  static char *kwlist[] = { "name", "uid", NULL };
 
117
  gchar *name = NULL;
 
118
  gchar *uid = NULL;
 
119
 
 
120
  if (!PyArg_ParseTupleAndKeywords (args, kwargs,"|ss:AwnConfigClient.__init__", kwlist, &name, &uid)) {
 
121
    return -1;
 
122
  }
 
123
  self->gtype = AWN_TYPE_CONFIG_CLIENT;
 
124
  self->free_on_dealloc = FALSE;
 
125
  if (name) {
 
126
    if (!uid) {
 
127
      PyErr_SetString (PyExc_ValueError, "The uid argument needs to be defined if the name argument is defined");
 
128
      return -1;
 
129
    }
 
130
    self->boxed = awn_config_client_new_for_applet (name, uid);
 
131
  } else {
 
132
    self->boxed = awn_config_client_new ();
 
133
  }
 
134
 
 
135
  if (!self->boxed) {
 
136
    PyErr_SetString (PyExc_RuntimeError, "could not create AwnConfigClient object");
 
137
    return -1;
 
138
  }
 
139
  self->free_on_dealloc = TRUE;
 
140
  return 0;
 
141
}
 
142
%%
 
143
override awn_config_client_get_list kwargs
 
144
static PyObject *
 
145
_wrap_awn_config_client_get_list (PyGBoxed *self, PyObject *args, PyObject *kwargs)
 
146
{
 
147
  static char *kwlist[] = { "group", "key", "list_type", NULL };
 
148
  char *group, *key;
 
149
  AwnConfigListType list_type;
 
150
  GSList *ret = NULL;
 
151
  GError *opt_error = NULL;
 
152
 
 
153
  if (!PyArg_ParseTupleAndKeywords (args, kwargs, "ssi:AwnConfigClient.get_list", kwlist, &group, &key, &list_type)) {
 
154
    return NULL;
 
155
  }
 
156
 
 
157
  ret = awn_config_client_get_list (pyg_boxed_get (self, AwnConfigClient), group, key, list_type, &opt_error);
 
158
 
 
159
  if (pyg_error_check (&opt_error)) {
 
160
    return NULL;
 
161
  }
 
162
 
 
163
  return _gslist_to_pylist (ret, list_type);
 
164
}
 
165
%%
 
166
override awn_config_client_set_list kwargs
 
167
static PyObject *
 
168
_wrap_awn_config_client_set_list (PyGBoxed *self, PyObject *args, PyObject *kwargs)
 
169
{
 
170
  static char *kwlist[] = { "group", "key", "list_type", "value", NULL };
 
171
  char *group, *key;
 
172
  AwnConfigListType list_type;
 
173
  PyObject *py_list;
 
174
  GSList *the_list = NULL;
 
175
  GError *opt_error = NULL;
 
176
 
 
177
  if (!PyArg_ParseTupleAndKeywords (args, kwargs, "ssiO:AwnConfigClient.set_list", kwlist, &group, &key, &list_type, &py_list)) {
 
178
    return NULL;
 
179
  }
 
180
 
 
181
  if (!PyList_Check (py_list) && !PyTuple_Check (py_list)) {
 
182
    PyErr_SetString (PyExc_TypeError, "Fourth argument not a tuple or list");
 
183
    return NULL;
 
184
  }
 
185
  the_list = _pysequence_to_gslist (py_list, list_type);
 
186
 
 
187
  awn_config_client_set_list (pyg_boxed_get (self, AwnConfigClient), group, key, list_type, the_list, &opt_error);
 
188
 
 
189
  g_slist_foreach (the_list, (GFunc)g_free, NULL);
 
190
  g_slist_free (the_list);
 
191
 
 
192
  if (pyg_error_check (&opt_error)) {
 
193
    return NULL;
 
194
  }
 
195
 
 
196
  Py_INCREF (Py_None);
 
197
  return Py_None;
 
198
}
 
199
%%
 
200
override awn_applet_simple_set_temp_icon kwargs
 
201
static PyObject *
 
202
_wrap_awn_applet_simple_set_temp_icon (PyGObject *self, PyObject *args, PyObject *kwargs)
 
203
{
 
204
    return _wrap_awn_applet_simple_set_icon (self, args, kwargs);
 
205
}
 
206
%%
 
207
override awn_config_client_notify_add kwargs
 
208
/* Borrowed from gnome-python/trunk/gconf/gconf.override, r585 */
 
209
void
 
210
pyawn_config_client_notify_add (AwnConfigClientNotifyEntry *entry, PyObject *tuple)
 
211
{
 
212
    PyObject *func;
 
213
    PyObject *userdata = NULL;
 
214
    PyObject *notify_entry;
 
215
    PyObject *value;
 
216
    PyObject *ret;
 
217
    PyGILState_STATE state;
 
218
 
 
219
    state = pyg_gil_state_ensure ();
 
220
 
 
221
    g_assert (PyTuple_Check (tuple));
 
222
    func = PyTuple_GetItem (tuple, 0);
 
223
    userdata = PyTuple_GetItem (tuple, 1);
 
224
 
 
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);
 
233
            break;
 
234
        case AWN_CONFIG_VALUE_TYPE_FLOAT:
 
235
            value = PyFloat_FromDouble (entry->value.float_val);
 
236
            break;
 
237
        case AWN_CONFIG_VALUE_TYPE_INT:
 
238
            value = PyInt_FromLong (entry->value.int_val);
 
239
            break;
 
240
        case AWN_CONFIG_VALUE_TYPE_STRING:
 
241
            value = PyString_FromString (entry->value.str_val);
 
242
            break;
 
243
        case AWN_CONFIG_VALUE_TYPE_LIST_BOOL:
 
244
            value = _gslist_to_pylist (entry->value.list_val, AWN_CONFIG_CLIENT_LIST_TYPE_BOOL);
 
245
            break;
 
246
        case AWN_CONFIG_VALUE_TYPE_LIST_FLOAT:
 
247
            value = _gslist_to_pylist (entry->value.list_val, AWN_CONFIG_CLIENT_LIST_TYPE_FLOAT);
 
248
            break;
 
249
        case AWN_CONFIG_VALUE_TYPE_LIST_INT:
 
250
            value = _gslist_to_pylist (entry->value.list_val, AWN_CONFIG_CLIENT_LIST_TYPE_INT);
 
251
            break;
 
252
        case AWN_CONFIG_VALUE_TYPE_LIST_STRING:
 
253
            value = _gslist_to_pylist (entry->value.list_val, AWN_CONFIG_CLIENT_LIST_TYPE_STRING);
 
254
            break;
 
255
        default:
 
256
            PyErr_Format (PyExc_ValueError, "Could not determine the value type of the configuration key '[%s]%s'.", entry->group, entry->key);
 
257
            return;
 
258
            break;
 
259
    }
 
260
    PyDict_SetItemString (notify_entry, "value", value);
 
261
 
 
262
    if (!userdata) {
 
263
        ret = PyObject_CallFunction (func, "N",  notify_entry);
 
264
    } else {
 
265
        ret = PyObject_CallFunction (func, "NO", notify_entry, userdata);
 
266
    }
 
267
 
 
268
    if (ret == NULL) {
 
269
            PyErr_Print ();
 
270
    } else {
 
271
            Py_DECREF (ret);
 
272
    }
 
273
 
 
274
    pyg_gil_state_release (state);
 
275
}
 
276
 
 
277
static PyObject *
 
278
_wrap_awn_config_client_notify_add (PyGBoxed *self, PyObject *args, PyObject *kwargs)
 
279
{
 
280
    static char *kwlist[] = { "group", "key", "func",  "user_data", NULL };
 
281
    gchar *group;
 
282
    gchar *key;
 
283
    PyObject *callback;
 
284
    PyObject *extra = NULL;
 
285
    PyObject *data;
 
286
 
 
287
    if (!PyArg_ParseTupleAndKeywords (args, kwargs,
 
288
                                      "ssO|O:AwnConfigClient.notify_add",
 
289
                                      kwlist, &group, &key,
 
290
                                      &callback, &extra)) {
 
291
        return NULL;
 
292
    }
 
293
 
 
294
    if (!PyCallable_Check (callback)) {
 
295
        PyErr_SetString (PyExc_TypeError, "Third argument not callable");
 
296
        return NULL;
 
297
    }
 
298
 
 
299
    if (extra) {
 
300
        Py_INCREF (extra);
 
301
    } else {
 
302
        extra = PyTuple_New (0);
 
303
    }
 
304
 
 
305
    data = Py_BuildValue ("(ON)", callback, extra);
 
306
 
 
307
    awn_config_client_notify_add (pyg_boxed_get(self, AwnConfigClient),
 
308
                                  group, key,
 
309
                                  (AwnConfigClientNotifyFunc)pyawn_config_client_notify_add,
 
310
                                  data);
 
311
 
 
312
    Py_INCREF (Py_None);
 
313
    return Py_None;
 
314
}
 
315
%%
 
316
override awn_desktop_item_launch kwargs
 
317
static PyObject *
 
318
_wrap_awn_desktop_item_launch (PyGBoxed *self, PyObject *args, PyObject *kwargs)
 
319
{
 
320
    static char *kwlist[] = { "documents", NULL };
 
321
    PyObject *py_documents = NULL;
 
322
    GSList *documents = NULL;
 
323
    GError *opt_error = NULL;
 
324
    gint pid;
 
325
 
 
326
    if (!PyArg_ParseTupleAndKeywords (args, kwargs, "|O:AwnDesktopItem.launch", kwlist, &py_documents)) {
 
327
        return NULL;
 
328
    }
 
329
 
 
330
    if (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));
 
337
        } else {
 
338
            PyErr_SetString (PyExc_TypeError, "Argument is not a sequence");
 
339
            return NULL;
 
340
        }
 
341
    }
 
342
 
 
343
    pid = awn_desktop_item_launch (pyg_boxed_get (self, AwnDesktopItem), documents, &opt_error);
 
344
 
 
345
    if (pyg_error_check (&opt_error)) {
 
346
        return NULL;
 
347
    }
 
348
 
 
349
    return PyInt_FromLong (pid);
 
350
}
 
351
%%
 
352
override awn_cairo_string_to_color kwargs
 
353
static PyObject *
 
354
_wrap_awn_cairo_string_to_color (PyObject *self, PyObject *args, PyObject *kwargs)
 
355
{
 
356
    static char *kwlist[] = { "color_string", NULL };
 
357
 
 
358
    const gchar *color_string;
 
359
    AwnColor *color = g_malloc (sizeof (AwnColor));
 
360
    PyObject *color_dict;
 
361
 
 
362
    if (!PyArg_ParseTupleAndKeywords (args, kwargs, "s:cairo_string_to_color", kwlist, &color_string)) {
 
363
        return NULL;
 
364
    }
 
365
 
 
366
    awn_cairo_string_to_color (color_string, color);
 
367
 
 
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));
 
373
 
 
374
    g_free (color);
 
375
 
 
376
    return color_dict;
 
377
}
 
378
%%
 
379
override awn_config_client_key_lock_open kwargs
 
380
static PyObject *
 
381
_wrap_awn_config_client_key_lock_open(PyObject *self, PyObject *args, PyObject *kwargs)
 
382
{
 
383
    static char *kwlist[] = { "group", "key", NULL };
 
384
    char *group, *key;
 
385
    int ret;
 
386
 
 
387
    if (!PyArg_ParseTupleAndKeywords (args, kwargs,"ss:AwnConfigClient.lock_open", kwlist, &group, &key))
 
388
        return NULL;
 
389
    
 
390
    ret = awn_config_client_key_lock_open (group, key);
 
391
    
 
392
    return PyInt_FromLong (ret);
 
393
}
 
394
%%
 
395
override awn_config_client_key_lock kwargs
 
396
static PyObject *
 
397
_wrap_awn_config_client_key_lock (PyObject *self, PyObject *args, PyObject *kwargs)
 
398
{
 
399
    static char *kwlist[] = { "fd", "operation", NULL };
 
400
    int fd, operation, ret;
 
401
 
 
402
    if (!PyArg_ParseTupleAndKeywords (args, kwargs,"ii:AwnConfigClient.lock", kwlist, &fd, &operation))
 
403
        return NULL;
 
404
    
 
405
    ret = awn_config_client_key_lock (fd, operation);
 
406
 
 
407
    if (ret != 0) {
 
408
        return PyErr_SetFromErrno(PyExc_IOError);
 
409
    }
 
410
    
 
411
    Py_INCREF(Py_None);
 
412
    return Py_None;
 
413
}
 
414
%%
 
415
override awn_config_client_key_lock_close kwargs
 
416
static PyObject *
 
417
_wrap_awn_config_client_key_lock_close (PyObject *self, PyObject *args, PyObject *kwargs)
 
418
{
 
419
    static char *kwlist[] = { "fd", NULL };
 
420
    int fd, ret;
 
421
 
 
422
    if (!PyArg_ParseTupleAndKeywords (args, kwargs,"i:AwnConfigClient.lock_close", kwlist, &fd))
 
423
        return NULL;
 
424
    
 
425
    ret = awn_config_client_key_lock_close (fd);
 
426
 
 
427
    if (ret != 0) {
 
428
        return PyErr_SetFromErrno(PyExc_IOError);
 
429
    }
 
430
    
 
431
    Py_INCREF(Py_None);
 
432
    return Py_None;
 
433
}