~gdesklets-desklet-team/gdesklets/0.36

« back to all changes in this revision

Viewing changes to utils/utils.c

  • Committer: Robert Pastierovic
  • Date: 2007-10-07 10:08:42 UTC
  • Revision ID: pastierovic@gmail.com-20071007100842-fdvp2vzmqgh1j87k
merged 0.3x branch and basic documentation and some other changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "utils.h"
 
2
 
 
3
#include <pygobject.h>
 
4
#include <gtk/gtk.h>
 
5
 
 
6
 
 
7
PyTypeObject *
 
8
gdesklets_get_pygobject_type (void)
 
9
{
 
10
  static PyTypeObject *PyGObject_Type = NULL;
 
11
 
 
12
  if (G_UNLIKELY (PyGObject_Type == NULL)) {
 
13
    PyObject *module = PyImport_ImportModule("gobject");
 
14
 
 
15
    if (!module) goto err_gobject;
 
16
 
 
17
    PyObject *moddict = PyModule_GetDict (module);
 
18
    PyGObject_Type = (PyTypeObject *) PyDict_GetItemString (moddict, "GObject");
 
19
 
 
20
    if (!PyGObject_Type) goto err_gobject;
 
21
  }
 
22
 
 
23
  return PyGObject_Type;
 
24
 
 
25
  err_gobject:
 
26
    PyErr_SetString (PyExc_ImportError,
 
27
                     "Cannot import name GObject from gobject");
 
28
    return NULL;
 
29
}
 
30
 
 
31
 
 
32
int
 
33
parse_gdk_window (PyObject *object, gpointer address)
 
34
{
 
35
  GdkWindow **window = address;
 
36
 
 
37
  if (!pygobject_check (object, gdesklets_get_pygobject_type ())) goto err;
 
38
  if (!GDK_IS_WINDOW (pygobject_get (object))) goto err;
 
39
 
 
40
  *window = GDK_WINDOW (pygobject_get (object));
 
41
 
 
42
  return 1;
 
43
 
 
44
  err:
 
45
    PyErr_SetString (PyExc_TypeError, "First parameter must be a GdkWindow!");
 
46
    return 0;
 
47
}
 
48
 
 
49
 
 
50
int
 
51
parse_gdk_pixmap (PyObject *object, gpointer address)
 
52
{
 
53
  GdkPixmap **pmap = address;
 
54
 
 
55
  if (!pygobject_check (object, gdesklets_get_pygobject_type ())) goto err;
 
56
  if (!GDK_IS_PIXMAP (pygobject_get (object))) goto err;
 
57
 
 
58
  *pmap = GDK_PIXMAP (pygobject_get (object));
 
59
 
 
60
  return 1;
 
61
 
 
62
  err:
 
63
    PyErr_SetString (PyExc_TypeError, "First parameter must be a GdkPixmap!");
 
64
    return 0;
 
65
}
 
66
 
 
67
 
 
68
int
 
69
parse_gdk_pixbuf (PyObject *object, gpointer address)
 
70
{
 
71
  GdkPixbuf **pixbuf = address;
 
72
 
 
73
  if (!pygobject_check (object, gdesklets_get_pygobject_type ())) goto err;
 
74
  if (!GDK_IS_PIXBUF (pygobject_get (object))) goto err;
 
75
 
 
76
  *pixbuf = GDK_PIXBUF (pygobject_get (object));
 
77
 
 
78
  return 1;
 
79
 
 
80
  err:
 
81
    PyErr_SetString (PyExc_TypeError, "First parameter must be a GdkPixbuf!");
 
82
    return 0;
 
83
}
 
84
 
 
85
 
 
86
int
 
87
parse_gtk_image (PyObject *object, gpointer address)
 
88
{
 
89
  GtkImage **image = address;
 
90
 
 
91
  if (!pygobject_check (object, gdesklets_get_pygobject_type ())) goto err;
 
92
  if (!GTK_IS_IMAGE (pygobject_get (object))) goto err;
 
93
 
 
94
  *image = GTK_IMAGE (pygobject_get (object));
 
95
 
 
96
  return 1;
 
97
 
 
98
  err:
 
99
    PyErr_SetString (PyExc_TypeError, "First parameter must be a GtkImage!");
 
100
    return 0;
 
101
}
 
102
 
 
103
 
 
104
int
 
105
parse_gtk_widget (PyObject *object, gpointer address)
 
106
{
 
107
  GtkWidget **widget = address;
 
108
 
 
109
  if (!pygobject_check (object, gdesklets_get_pygobject_type ())) goto err;
 
110
  if (!GTK_IS_WIDGET (pygobject_get (object))) goto err;
 
111
 
 
112
  *widget = GTK_WIDGET (pygobject_get (object));
 
113
 
 
114
  return 1;
 
115
 
 
116
  err:
 
117
    PyErr_SetString (PyExc_TypeError, "First parameter must be a GtkWidget!");
 
118
    return 0;
 
119
}
 
120