File: applet.override

package info (click to toggle)
gnome-python-desktop 2.32.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 4,528 kB
  • ctags: 983
  • sloc: sh: 10,214; xml: 8,851; ansic: 3,428; python: 1,457; makefile: 664
file content (282 lines) | stat: -rw-r--r-- 7,780 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/* -*- Mode: C; c-basic-offset: 4 -*- */
%%
headers
#include <Python.h>
#include <panel-applet.h>
#include <bonobo/bonobo-ui-util.h>
#include <libgnome/gnome-program.h>
#include <libgnomeui/libgnomeui.h>

#define NO_IMPORT_PYGOBJECT
#include "pygobject.h"

#include "config.h"


%%
modulename gnome.applet
%%
import gobject.GObject as PyGObject_Type
import gtk.EventBox as PyGtkEventBox_Type
import gtk.Widget as PyGtkWidget_Type
%%
ignore-glob
  *_get_type
%%
override panel_applet_factory_main_closure kwargs
static PyObject*
_wrap_panel_applet_factory_main_closure (PyGObject * self,
			                 PyObject *  args,
					 PyObject * kwargs)
{
    static char *kwlist[] = { "iid", "applet_type", "func", "extra_data", NULL };
    gchar *iid;
    PyObject *pytype;
    PyObject *callback;
    PyObject *params = NULL;
    GType type;
    int retval;
    
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
				     "sOO|O:PanelAppletFactory.__init__",
				     kwlist, &iid, &pytype, &callback, &params)) {
        return NULL;
    }

    if (!PyCallable_Check (callback)) {
        PyErr_SetString (PyExc_TypeError, "second arg not callable");
	return NULL;
    }
    
    type = pyg_type_from_object (pytype);
    
    pyg_begin_allow_threads;
    retval = panel_applet_factory_main_closure (iid,
    	     				       	type,
                                                pyg_closure_new (callback, params, NULL));
    pyg_end_allow_threads;
    return PyInt_FromLong (retval);
}
%%
override panel__applet_bonobo_factory kwargs
static PyObject *
_wrap_panel__applet_bonobo_factory (PyGObject * self,
 			            PyObject *  args,
				    PyObject * kwargs)
{
	static char *kwlist[] = { "iid", "type", "name", "version", "func", "extra_data", NULL };
	gchar *iid;
	PyObject *pytype;
	gchar *name;
	gchar *version;
	PyObject *callback;
	PyObject *params = NULL;
	GType type;
	PyObject *av;
	int argc;
	char **argv;
	int i;
	
	if (!PyArg_ParseTupleAndKeywords(args, kwargs,
					 "sOssO|O:gnome.applet.bonobo_factory",
					 kwlist, &iid, &pytype, &name, &version, &callback, &params)) {
		return NULL;
	}
	
	if (!PyCallable_Check (callback)) {
		PyErr_SetString (PyExc_TypeError, "second arg not callable");
		return NULL;
	}
	
	type = pyg_type_from_object (pytype);
	
	/* get argc and argv */
	av = PySys_GetObject ("argv");
	argc = PyList_Size (av);
	argv = g_new (char *, argc);
	for (i = 0; i < argc; i++) {
		argv[i] = g_strdup (PyString_AsString (PyList_GetItem (av, i)));
	}
	
	gnome_program_init (name, version,     
			    LIBGNOMEUI_MODULE,             
			    argc, argv,                                         
			    GNOME_PARAM_NONE,
                            GNOME_CLIENT_PARAM_SM_CONNECT, FALSE,
			    NULL);            

        pyg_begin_allow_threads;
        panel_applet_factory_main_closure (iid,
	                                   type,
					   pyg_closure_new (callback, params, NULL));
        pyg_end_allow_threads;
	
	/* TODO: Check if it's really neccessary to set argc and argv here */
	PySys_SetArgv (argc, argv);
	if (argv != NULL) {
		for (i = 0; i < argc; i++)
			g_free (argv[i]);
		g_free (argv);
	}
	
	Py_INCREF (Py_None);
	return Py_None;
}
%%
override panel_applet_setup_menu kwargs
static PyObject *
_wrap_panel_applet_setup_menu (PyGObject * self,
			       PyObject *  args,
			       PyObject *  kwargs)
{
    static char *kwlist[] = { "xml", "list", "extra_data", NULL };
    gchar *             xml;
    PyObject *          list;
    PyObject *          params = NULL;
    BonoboUIComponent * popup_component;
    int                 len, i;
    PyObject *          item;
    char *              cname;
    PyObject *          callback;
    
    if (!PyArg_ParseTupleAndKeywords (args, kwargs,
				      "sO|O:PanelApplet.setup_menu", 
				      kwlist, &xml, &list, &params)) {
	return NULL;
    }

    if (!PySequence_Check (list)) {
	PyErr_SetString (PyExc_TypeError, "entries must be a sequence");
	return NULL;
    }
    
    /* Copied from panel-applet.c */
    popup_component = panel_applet_get_popup_component (PANEL_APPLET (self->obj));
	    
    bonobo_ui_component_set (popup_component, "/", "<popups/>", NULL);
 
    bonobo_ui_component_set_translate (popup_component, "/popups", xml, NULL);
    /* end copy */
    
    len = PySequence_Size (list);
    for (i = 0; i < len; i++) {
	item = PySequence_GetItem (list, i);
	Py_DECREF (item);
	
	if (!PyArg_ParseTuple (item, "sO", &cname, &callback)) {
	    return NULL;
	}

	bonobo_ui_component_add_verb_full (popup_component, cname,
					   pyg_closure_new (callback, params, NULL));
    }

    Py_INCREF(Py_None);
    return Py_None;
}
%%
override panel_applet_setup_menu_from_file kwargs
static PyObject *
_wrap_panel_applet_setup_menu_from_file (PyGObject * self,
					 PyObject *  args,
					 PyObject *  kwargs)
{
    static char *kwlist[] = { "opt_datadir", "file", "opt_app_name", "list", "extra_data", NULL };
    gchar *             opt_datadir;
    gchar *             file;
    gchar *             opt_app_name;
    PyObject *          list;
    PyObject *          params = NULL;
    BonoboUIComponent * popup_component;
    gchar *             app_name = NULL;
    int                 len, i;
    PyObject *          item;
    char *              cname;
    PyObject *          callback;
    
    if (!PyArg_ParseTupleAndKeywords (args, kwargs,
				      "zszO|O:PanelApplet.setup_menu_from_file", 
				      kwlist, &opt_datadir, &file, &opt_app_name, &list, &params)) {
	return NULL;
    }

    if (!PySequence_Check (list)) {
	PyErr_SetString (PyExc_TypeError, "entries must be a sequence");
	return NULL;
    }
    
    /* Copied from panel-applet.c */
    if (!opt_app_name)
	opt_app_name = app_name = g_strdup_printf ("%d", getpid ());

    popup_component = panel_applet_get_popup_component (PANEL_APPLET (self->obj));

    bonobo_ui_util_set_ui (popup_component, opt_datadir, file, opt_app_name, NULL);
    /* end copy */
    
    len = PySequence_Size (list);
    for (i = 0; i < len; i++) {
	item = PySequence_GetItem (list, i);
	Py_DECREF (item);
	
	if (!PyArg_ParseTuple (item, "sO", &cname, &callback)) {
	    return NULL;
	}

	bonobo_ui_component_add_verb_full (popup_component, cname,
					   pyg_closure_new (callback, params, NULL));
    }
    
    if (app_name) {
	g_free (app_name);
    }
    
    Py_INCREF(Py_None);
    return Py_None;
}
%%
override panel_applet_new noargs
static int
_wrap_panel_applet_new(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    GType obj_type = pyg_type_from_object((PyObject *) self);

    if (obj_type != PANEL_TYPE_APPLET) {
        PyErr_SetString(PyExc_RuntimeError, "cannot subclass gnome.applet.Applet");
        return -1;
    }
    self->obj = (GObject *) panel_applet_new();
    if (!self->obj) {
        PyErr_SetString(PyExc_RuntimeError, "could not create gnome.applet.Applet object");
        return -1;
    }
    pygobject_register_wrapper((PyObject *)self);
    return 0;
}
%%
override panel_applet_get_background noargs
static PyObject *
_wrap_panel_applet_get_background(PyGObject *self)
{
    PanelAppletBackgroundType ret;
    GdkColor color;
    GdkPixmap *pixmap = NULL;
    PyObject *pyretval = NULL;

    ret = panel_applet_get_background(PANEL_APPLET(self->obj), &color, &pixmap);

    switch (ret)
    {
    case PANEL_COLOR_BACKGROUND:
        return pyg_boxed_new(GDK_TYPE_COLOR, &color, TRUE, TRUE);
    case PANEL_NO_BACKGROUND:
        Py_INCREF(Py_None);
        return Py_None;
    case PANEL_PIXMAP_BACKGROUND:
        pyretval = pygobject_new(G_OBJECT(pixmap));
        g_object_unref(G_OBJECT(pixmap));
        return pyretval;
    }
    PyErr_SetString(PyExc_RuntimeError, "strange value returned by panel_applet_get_background");
    return NULL;
}