2006-09-26 21:58:54 +02:00
|
|
|
/* -*- Mode: C; c-basic-offset: 4 -*- */
|
|
|
|
%%
|
|
|
|
headers
|
|
|
|
#include <Python.h>
|
|
|
|
|
2006-09-27 14:45:55 +02:00
|
|
|
#include "pygobject.h"
|
2006-10-13 01:04:01 +02:00
|
|
|
#include "sugar-browser.h"
|
2006-10-12 12:47:17 +02:00
|
|
|
#include "sugar-key-grabber.h"
|
2006-10-12 15:49:11 +02:00
|
|
|
#include "sugar-address-entry.h"
|
2006-10-17 21:53:29 +02:00
|
|
|
#include "sugar-push-scroller.h"
|
2006-11-15 13:56:19 +01:00
|
|
|
#include "sugar-download-manager.h"
|
|
|
|
#include "sugar-download.h"
|
2007-01-05 02:19:52 +01:00
|
|
|
#include "sugar-audio-manager.h"
|
2006-09-27 14:45:55 +02:00
|
|
|
|
2007-01-07 07:20:42 +01:00
|
|
|
#include "pycairo.h"
|
2006-12-21 08:09:05 +01:00
|
|
|
#include <pygtk/pygtk.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
2007-01-07 07:20:42 +01:00
|
|
|
extern Pycairo_CAPI_t *Pycairo_CAPI;
|
2006-12-21 08:09:05 +01:00
|
|
|
|
2006-09-27 14:45:55 +02:00
|
|
|
%%
|
2007-03-13 12:51:15 +01:00
|
|
|
modulename gecko
|
2006-09-27 14:45:55 +02:00
|
|
|
%%
|
|
|
|
import gobject.GObject as PyGObject_Type
|
2006-10-12 15:49:11 +02:00
|
|
|
import gtk.Entry as PyGtkEntry_Type
|
2006-10-16 18:43:04 +02:00
|
|
|
import gtk.gdk.Screen as PyGdkScreen_Type
|
2006-12-21 08:09:05 +01:00
|
|
|
import gtk.gdk.Pixbuf as PyGdkPixbuf_Type
|
|
|
|
import hippo.CanvasImage as HippoCanvasImage_Type
|
2006-09-27 14:45:55 +02:00
|
|
|
%%
|
|
|
|
ignore-glob
|
|
|
|
*_get_type
|
|
|
|
_*
|
2006-09-26 21:58:54 +02:00
|
|
|
%%
|
2007-01-23 20:33:56 +01:00
|
|
|
include
|
|
|
|
gtkmozembed.override
|
|
|
|
%%
|
2006-12-21 08:09:05 +01:00
|
|
|
override sugar_hippo_canvas_image_set_image_from_gdk_pixbuf kwargs
|
|
|
|
static cairo_surface_t *
|
|
|
|
_cairo_surface_from_pixbuf (GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
/* Ripped from GooCanvas */
|
|
|
|
gint width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
gint height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
|
|
|
|
int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
|
|
|
int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
|
|
|
|
guchar *cairo_pixels;
|
|
|
|
cairo_format_t format;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
static const cairo_user_data_key_t key;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
if (n_channels == 3)
|
|
|
|
format = CAIRO_FORMAT_RGB24;
|
|
|
|
else
|
|
|
|
format = CAIRO_FORMAT_ARGB32;
|
|
|
|
|
|
|
|
cairo_pixels = g_malloc (4 * width * height);
|
|
|
|
surface = cairo_image_surface_create_for_data ((unsigned char *)cairo_pixels,
|
|
|
|
format,
|
|
|
|
width, height, 4 * width);
|
|
|
|
cairo_surface_set_user_data (surface, &key,
|
|
|
|
cairo_pixels, (cairo_destroy_func_t)g_free);
|
|
|
|
|
|
|
|
for (j = height; j; j--)
|
|
|
|
{
|
|
|
|
guchar *p = gdk_pixels;
|
|
|
|
guchar *q = cairo_pixels;
|
|
|
|
|
|
|
|
if (n_channels == 3)
|
|
|
|
{
|
|
|
|
guchar *end = p + 3 * width;
|
|
|
|
|
|
|
|
while (p < end)
|
|
|
|
{
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
q[0] = p[2];
|
|
|
|
q[1] = p[1];
|
|
|
|
q[2] = p[0];
|
|
|
|
#else
|
|
|
|
q[1] = p[0];
|
|
|
|
q[2] = p[1];
|
|
|
|
q[3] = p[2];
|
|
|
|
#endif
|
|
|
|
p += 3;
|
|
|
|
q += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
guchar *end = p + 4 * width;
|
|
|
|
guint t1,t2,t3;
|
|
|
|
|
|
|
|
#define MULT(d,c,a,t) G_STMT_START { t = c * a; d = ((t >> 8) + t) >> 8; } G_STMT_END
|
|
|
|
|
|
|
|
while (p < end)
|
|
|
|
{
|
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
|
|
|
MULT(q[0], p[2], p[3], t1);
|
|
|
|
MULT(q[1], p[1], p[3], t2);
|
|
|
|
MULT(q[2], p[0], p[3], t3);
|
|
|
|
q[3] = p[3];
|
|
|
|
#else
|
|
|
|
q[0] = p[3];
|
|
|
|
MULT(q[1], p[0], p[3], t1);
|
|
|
|
MULT(q[2], p[1], p[3], t2);
|
|
|
|
MULT(q[3], p[2], p[3], t3);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
p += 4;
|
|
|
|
q += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef MULT
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_pixels += gdk_rowstride;
|
|
|
|
cairo_pixels += 4 * width;
|
|
|
|
}
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
static PyObject*
|
|
|
|
_wrap_sugar_hippo_canvas_image_set_image_from_gdk_pixbuf(PyGObject *self, PyObject *args, PyObject *kwargs)
|
|
|
|
{
|
|
|
|
static char *kwlist[] = { "image", "pixbuf", NULL };
|
|
|
|
PyGObject *py_pixbuf;
|
|
|
|
PyGObject *py_image;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
GObject *image;
|
|
|
|
GValue val = {0,};
|
|
|
|
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
|
|
|
"O!O!:_sugar.hippo_canvas_image_set_image_from_gdk_pixbuf",
|
|
|
|
kwlist, &HippoCanvasImage_Type, &py_image, &PyGdkPixbuf_Type, &py_pixbuf)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface = _cairo_surface_from_pixbuf(GDK_PIXBUF (py_pixbuf->obj));
|
|
|
|
if (surface == NULL) {
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "pixbuf could not be converted");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: This has to be a GObject (and not a real HippoCanvasImage object)
|
|
|
|
* for now until the HippoCanvas includes situation gets sorted out.
|
|
|
|
*/
|
|
|
|
image = G_OBJECT (py_image->obj);
|
|
|
|
if (image == NULL) {
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "invalid HippoCanvasImage object");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_init (&val, G_TYPE_POINTER);
|
|
|
|
g_value_set_pointer (&val, surface);
|
|
|
|
g_object_set_property (image, "image", &val);
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
%%
|
2007-01-07 07:20:42 +01:00
|
|
|
override sugar_cairo_surface_from_gdk_pixbuf kwargs
|
|
|
|
static PyObject*
|
|
|
|
_wrap_sugar_cairo_surface_from_gdk_pixbuf(PyGObject *self, PyObject *args, PyObject *kwargs)
|
|
|
|
{
|
|
|
|
static char *kwlist[] = { "pixbuf", NULL };
|
|
|
|
PyGObject *child;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:sugar.cairo_surface_from_gdk_pixbuf", kwlist, &PyGdkPixbuf_Type, &child))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
surface = _cairo_surface_from_pixbuf(GDK_PIXBUF (child->obj));
|
|
|
|
if (surface == NULL) {
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "pixbuf could not be converted");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PycairoSurface_FromSurface(surface, NULL);
|
|
|
|
}
|
|
|
|
%%
|
2007-03-13 11:41:27 +01:00
|
|
|
override-slot SugarBrowserEvent.tp_getattr
|
|
|
|
static PyObject *
|
|
|
|
_wrap_sugar_browser_event_tp_getattr(PyObject *self, char *attr)
|
|
|
|
{
|
|
|
|
SugarBrowserEvent *event = pyg_boxed_get(self, SugarBrowserEvent);
|
|
|
|
|
|
|
|
if (!strcmp(attr, "__members__"))
|
2007-03-16 15:05:44 +01:00
|
|
|
return Py_BuildValue("[ss]", "image_uri", "button");
|
2007-03-13 12:51:15 +01:00
|
|
|
if (!strcmp(attr, "image_uri")) {
|
|
|
|
if (event->image_uri) {
|
|
|
|
return PyString_FromString(event->image_uri);
|
|
|
|
} else {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
}
|
2007-03-16 15:05:44 +01:00
|
|
|
else if (!strcmp(attr, "button"))
|
|
|
|
return PyInt_FromLong(event->button);
|
2007-03-13 11:41:27 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
%%
|