Make browser a modules inside sugar library

This commit is contained in:
Marco Pesenti Gritti 2007-04-07 13:17:36 +02:00
parent 4828870afd
commit 5343752c35
33 changed files with 173 additions and 344 deletions

View File

@ -1,4 +1,4 @@
SUBDIRS = bin data lib po shell sugar services SUBDIRS = bin browser data po shell sugar services
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4

View File

@ -1,4 +1,4 @@
libsugarprivate_la_CPPFLAGS = \ libsugarbrowser_la_CPPFLAGS = \
$(WARN_CFLAGS) \ $(WARN_CFLAGS) \
$(LIB_CFLAGS) \ $(LIB_CFLAGS) \
$(GECKO_CFLAGS) \ $(GECKO_CFLAGS) \
@ -18,13 +18,13 @@ libsugarprivate_la_CPPFLAGS = \
-DPLUGIN_DIR=\"$(libdir)/mozilla/plugins\" \ -DPLUGIN_DIR=\"$(libdir)/mozilla/plugins\" \
-DSHARE_DIR=\"$(pkgdatadir)\" -DSHARE_DIR=\"$(pkgdatadir)\"
noinst_LTLIBRARIES = libsugarprivate.la noinst_LTLIBRARIES = libsugarbrowser.la
libsugarprivate_la_LIBADD = \ libsugarbrowser_la_LIBADD = \
$(LIB_LIBS) \ $(LIB_LIBS) \
$(GECKO_LIBS) $(GECKO_LIBS)
libsugarprivate_la_SOURCES = \ libsugarbrowser_la_SOURCES = \
$(BUILT_SOURCES) \ $(BUILT_SOURCES) \
GeckoContentHandler.h \ GeckoContentHandler.h \
GeckoContentHandler.cpp \ GeckoContentHandler.cpp \

View File

@ -120,9 +120,7 @@ AC_OUTPUT([
Makefile Makefile
bin/Makefile bin/Makefile
data/Makefile data/Makefile
lib/Makefile browser/Makefile
lib/src/Makefile
lib/python/Makefile
services/Makefile services/Makefile
services/presence/Makefile services/presence/Makefile
services/presence2/Makefile services/presence2/Makefile
@ -155,6 +153,7 @@ services/console/interface/logviewer/Makefile
services/console/interface/terminal/Makefile services/console/interface/terminal/Makefile
sugar/Makefile sugar/Makefile
sugar/activity/Makefile sugar/activity/Makefile
sugar/browser/Makefile
sugar/clipboard/Makefile sugar/clipboard/Makefile
sugar/graphics/Makefile sugar/graphics/Makefile
sugar/p2p/Makefile sugar/p2p/Makefile

View File

@ -1 +0,0 @@
SUBDIRS = src python

View File

@ -1,43 +0,0 @@
INCLUDES = \
$(PYTHON_INCLUDES) \
$(PYGTK_CFLAGS) \
$(PYCAIRO_CFLAGS) \
$(LIB_CFLAGS) \
$(GECKO_CFLAGS) \
$(NSPR_CFLAGS) \
-I$(MOZILLA_INCLUDE_DIR)/gtkembedmoz \
-I$(top_srcdir)/lib/src
pkgpyexecdir = $(pythondir)
pkgpyexec_LTLIBRARIES = _sugar.la
_sugar_la_LDFLAGS = -module -avoid-version $(GECKO_LDFLAGS)
_sugar_la_LIBADD = \
$(LIB_LIBS) \
$(PYCAIRO_LIBS) \
$(GECKO_LIBS) \
$(XPCOMGLUE_LIBS) \
$(top_builddir)/lib/src/libsugarprivate.la
_sugar_la_SOURCES = \
_sugarmodule.c \
xulrunner.cpp \
xulrunner.h
nodist__sugar_la_SOURCES = _sugar.c
_sugar.c: _sugar.defs gtkmozembed.defs _sugar.override gtkmozembed.override
CLEANFILES = _sugar.c
EXTRA_DIST = _sugar.override _sugar.defs gtkmozembed.defs gtkmozembed.override
.defs.c:
(cd $(srcdir)\
&& $(PYGTK_CODEGEN) \
--register $(PYGTK_DEFSDIR)/gdk-types.defs \
--register $(PYGTK_DEFSDIR)/gtk-types.defs \
--override $*.override \
--prefix py$* $*.defs) > gen-$*.c \
&& cp gen-$*.c $*.c \
&& rm -f gen-$*.c

View File

@ -1,228 +0,0 @@
/* -*- Mode: C; c-basic-offset: 4 -*- */
%%
headers
#include <Python.h>
#include "pygobject.h"
#include "sugar-browser.h"
#include "sugar-address-entry.h"
#include "sugar-download-manager.h"
#include "sugar-download.h"
#include "pycairo.h"
#include <pygtk/pygtk.h>
#include <glib.h>
extern Pycairo_CAPI_t *Pycairo_CAPI;
%%
modulename gecko
%%
import gobject.GObject as PyGObject_Type
import gtk.Entry as PyGtkEntry_Type
import gtk.gdk.Screen as PyGdkScreen_Type
import gtk.gdk.Pixbuf as PyGdkPixbuf_Type
import hippo.CanvasImage as HippoCanvasImage_Type
%%
ignore-glob
*_get_type
_*
%%
include
gtkmozembed.override
%%
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;
}
%%
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);
}
%%
override-slot SugarBrowserMetadata.tp_getattr
static PyObject *
_wrap_sugar_browser_metadata_tp_getattr(PyObject *self, char *attr)
{
SugarBrowserMetadata *metadata = pyg_boxed_get(self, SugarBrowserMetadata);
if (!strcmp(attr, "__members__"))
return Py_BuildValue("[s]", "filename");
else if (!strcmp(attr, "filename")) {
if (metadata->filename) {
return PyString_FromString(metadata->filename);
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
return NULL;
}
%%
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__"))
return Py_BuildValue("[sss]", "image_uri", "button", "image_name");
else if (!strcmp(attr, "image_uri")) {
if (event->image_uri) {
return PyString_FromString(event->image_uri);
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
else if (!strcmp(attr, "image_name")) {
if (event->image_name) {
return PyString_FromString(event->image_name);
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
else if (!strcmp(attr, "button"))
return PyInt_FromLong(event->button);
return NULL;
}
%%

View File

@ -1,37 +0,0 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "xulrunner.h"
/* include this first, before NO_IMPORT_PYGOBJECT is defined */
#include <pygobject.h>
#include <pycairo.h>
Pycairo_CAPI_t *Pycairo_CAPI;
void py_sugar_register_classes (PyObject *d);
extern PyMethodDef py_sugar_functions[];
DL_EXPORT(void)
init_sugar(void)
{
PyObject *m, *d;
xulrunner_startup();
init_pygobject ();
Pycairo_IMPORT;
m = Py_InitModule ("_sugar", py_sugar_functions);
d = PyModule_GetDict (m);
py_sugar_register_classes (d);
py_sugar_add_constants(m, "GTK_MOZ_EMBED_");
if (PyErr_Occurred ()) {
Py_FatalError ("can't initialise module _sugar");
}
}

View File

@ -23,7 +23,6 @@ from sugar.graphics.menu import Menu, MenuItem
from sugar.graphics.canvasicon import CanvasIcon from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import units from sugar.graphics import units
from sugar.presence import PresenceService from sugar.presence import PresenceService
import _sugar
class BuddyMenu(Menu): class BuddyMenu(Menu):
ACTION_MAKE_FRIEND = 0 ACTION_MAKE_FRIEND = 0
@ -49,7 +48,7 @@ class BuddyMenu(Menu):
# FIXME: have to set the image _after_ adding the HippoCanvasImage # FIXME: have to set the image _after_ adding the HippoCanvasImage
# to it's parent item, because that sets the HippoCanvasImage's context, # to it's parent item, because that sets the HippoCanvasImage's context,
# which resets the object's 'image' property. Grr. # which resets the object's 'image' property. Grr.
_sugar.hippo_canvas_image_set_image_from_gdk_pixbuf(icon_item, scaled_pixbuf) #_sugar.hippo_canvas_image_set_image_from_gdk_pixbuf(icon_item, scaled_pixbuf)
self._buddy.connect('icon-changed', self.__buddy_icon_changed_cb) self._buddy.connect('icon-changed', self.__buddy_icon_changed_cb)

View File

@ -26,7 +26,6 @@ import gtk
import gobject import gobject
from sugar import env from sugar import env
import _sugar
def _get_display_number(): def _get_display_number():
"""Find a free display number trying to connect to 6000+ ports""" """Find a free display number trying to connect to 6000+ ports"""

View File

@ -1,4 +1,4 @@
SUBDIRS = activity clipboard graphics p2p presence datastore SUBDIRS = activity browser clipboard graphics p2p presence datastore
sugardir = $(pythondir)/sugar sugardir = $(pythondir)/sugar
sugar_PYTHON = \ sugar_PYTHON = \

View File

@ -21,7 +21,6 @@ import os
import gtk import gtk
import hippo import hippo
import _sugar
from sugar.presence import PresenceService from sugar.presence import PresenceService
from sugar.activity.activityservice import ActivityService from sugar.activity.activityservice import ActivityService
from sugar.graphics.window import Window from sugar.graphics.window import Window

47
sugar/browser/Makefile.am Normal file
View File

@ -0,0 +1,47 @@
sugardir = $(pythondir)/sugar/browser
sugar_PYTHON = \
__init__.py
INCLUDES = \
$(PYTHON_INCLUDES) \
$(PYGTK_CFLAGS) \
$(PYCAIRO_CFLAGS) \
$(LIB_CFLAGS) \
$(GECKO_CFLAGS) \
$(NSPR_CFLAGS) \
-I$(MOZILLA_INCLUDE_DIR)/gtkembedmoz \
-I$(top_srcdir)/browser
pkgpyexecdir = $(pythondir)/sugar/browser
pkgpyexec_LTLIBRARIES = _sugarbrowser.la
_sugarbrowser_la_LDFLAGS = -module -avoid-version $(GECKO_LDFLAGS)
_sugarbrowser_la_LIBADD = \
$(LIB_LIBS) \
$(PYCAIRO_LIBS) \
$(GECKO_LIBS) \
$(XPCOMGLUE_LIBS) \
$(top_builddir)/browser/libsugarbrowser.la
_sugarbrowser_la_SOURCES = \
_sugarbrowsermodule.c \
xulrunner.cpp \
xulrunner.h
nodist__sugarbrowser_la_SOURCES = _sugarbrowser.c
_sugar.c: _sugarbrowser.defs gtkmozembed.defs _sugarbrowser.override gtkmozembed.override
CLEANFILES = _sugar.c
EXTRA_DIST = _sugarbrowser.override _sugarbrowser.defs gtkmozembed.defs gtkmozembed.override
.defs.c:
(cd $(srcdir)\
&& $(PYGTK_CODEGEN) \
--register $(PYGTK_DEFSDIR)/gdk-types.defs \
--register $(PYGTK_DEFSDIR)/gtk-types.defs \
--override $*.override \
--prefix py$* $*.defs) > gen-$*.c \
&& cp gen-$*.c $*.c \
&& rm -f gen-$*.c

View File

@ -62,7 +62,7 @@
(return-type "GType") (return-type "GType")
) )
(define-function browser_startup (define-function startup
(c-name "sugar_browser_startup") (c-name "sugar_browser_startup")
(parameters (parameters
'("const-char*" "profile_path") '("const-char*" "profile_path")
@ -71,7 +71,7 @@
(return-type "gboolean") (return-type "gboolean")
) )
(define-function browser_shutdown (define-function shutdown
(c-name "sugar_browser_shutdown") (c-name "sugar_browser_shutdown")
(return-type "none") (return-type "none")
) )
@ -182,21 +182,4 @@
(return-type "gint") (return-type "gint")
) )
(define-function hippo_canvas_image_set_image_from_gdk_pixbuf
(c-name "sugar_hippo_canvas_image_set_image_from_gdk_pixbuf")
(return-type "none")
(parameters
'("GObject*" "image")
'("GdkPixbuf*" "pixbuf")
)
)
(define-function cairo_surface_from_gdk_pixbuf
(c-name "sugar_cairo_surface_from_gdk_pixbuf")
(return-type "cairo_surface_t*")
(parameters
'("GdkPixbuf*" "pixbuf")
)
)
(include "gtkmozembed.defs") (include "gtkmozembed.defs")

View File

@ -0,0 +1,80 @@
/* -*- Mode: C; c-basic-offset: 4 -*- */
%%
headers
#include <Python.h>
#include "pygobject.h"
#include "sugar-browser.h"
#include "sugar-address-entry.h"
#include "sugar-download-manager.h"
#include "sugar-download.h"
#include <pygtk/pygtk.h>
#include <glib.h>
%%
modulename _sugarbrowser
%%
import gobject.GObject as PyGObject_Type
import gtk.Entry as PyGtkEntry_Type
import gtk.gdk.Screen as PyGdkScreen_Type
import gtk.gdk.Pixbuf as PyGdkPixbuf_Type
import hippo.CanvasImage as HippoCanvasImage_Type
%%
ignore-glob
*_get_type
_*
%%
include
gtkmozembed.override
%%
override-slot SugarBrowserMetadata.tp_getattr
static PyObject *
_wrap_sugar_browser_metadata_tp_getattr(PyObject *self, char *attr)
{
SugarBrowserMetadata *metadata = pyg_boxed_get(self, SugarBrowserMetadata);
if (!strcmp(attr, "__members__"))
return Py_BuildValue("[s]", "filename");
else if (!strcmp(attr, "filename")) {
if (metadata->filename) {
return PyString_FromString(metadata->filename);
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
return NULL;
}
%%
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__"))
return Py_BuildValue("[sss]", "image_uri", "button", "image_name");
else if (!strcmp(attr, "image_uri")) {
if (event->image_uri) {
return PyString_FromString(event->image_uri);
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
else if (!strcmp(attr, "image_name")) {
if (event->image_name) {
return PyString_FromString(event->image_name);
} else {
Py_INCREF(Py_None);
return Py_None;
}
}
else if (!strcmp(attr, "button"))
return PyInt_FromLong(event->button);
return NULL;
}
%%

View File

@ -0,0 +1,32 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "xulrunner.h"
/* include this first, before NO_IMPORT_PYGOBJECT is defined */
#include <pygobject.h>
void py_sugarbrowser_register_classes (PyObject *d);
extern PyMethodDef py_sugarbrowser_functions[];
DL_EXPORT(void)
init_sugarbrowser(void)
{
PyObject *m, *d;
xulrunner_startup();
init_pygobject ();
m = Py_InitModule ("_sugarbrowser", py_sugarbrowser_functions);
d = PyModule_GetDict (m);
py_sugarbrowser_register_classes (d);
py_sugarbrowser_add_constants(m, "GTK_MOZ_EMBED_");
if (PyErr_Occurred ()) {
Py_FatalError ("can't initialise module _sugarbrowser");
}
}

View File

@ -22,15 +22,15 @@ import pygtk
pygtk.require('2.0') pygtk.require('2.0')
import gtk import gtk
import _sugar import sugar.browser
# Main window # Main window
window = gtk.Window() window = gtk.Window()
window.connect("destroy", lambda w: gtk.main_quit()) window.connect("destroy", lambda w: gtk.main_quit())
_sugar.browser_startup(os.path.expanduser('~/.sugar-browser-test'), 'test') sugar.browser.startup(os.path.expanduser('~/.sugar-browser-test'), 'test')
browser = _sugar.Browser() browser = sugar.browser.Browser()
window.add(browser) window.add(browser)
browser.show() browser.show()