From e4a8e189e7cf25236ffebc72ac8d7bed6893b70d Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 21 May 2007 12:41:16 +0000 Subject: Split the python bindings to their own directory --- (limited to 'python') diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 0000000..3f9c71f --- /dev/null +++ b/python/.gitignore @@ -0,0 +1 @@ +hulahop.c diff --git a/python/Makefile.am b/python/Makefile.am new file mode 100644 index 0000000..c91d3db --- /dev/null +++ b/python/Makefile.am @@ -0,0 +1,39 @@ +sugardir = $(pythondir)/hulahop +sugar_PYTHON = \ + __init__.py \ + webview.py + +INCLUDES = \ + $(DEPS_CFLAGS) \ + $(PYTHON_INCLUDES) \ + $(PYGTK_CFLAGS) \ + -I$(top_srcdir)/src + +pkgpyexec_LTLIBRARIES = _hulahop.la + +_hulahop_la_LDFLAGS = -module -avoid-version -R$(MOZILLA_HOME) -dlopen self +_hulahop_la_LIBADD = \ + $(GECKO_LIBS) \ + $(DEPS_LIBS) \ + $(MOZILLA_EXTRA_LIBS) \ + $(MOZILLA_GLUE_LIBS) \ + $(top_builddir)/src/libhulahop.la + +_hulahop_la_SOURCES = \ + hulahop.c \ + hulahopmodule.c + +hulahop.c: hulahop.defs hulahop.override + +CLEANFILES = hulahop.c +EXTRA_DIST = hulahop.override hulahop.defs + +.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 diff --git a/python/__init__.py b/python/__init__.py new file mode 100644 index 0000000..aaa29a9 --- /dev/null +++ b/python/__init__.py @@ -0,0 +1,27 @@ +# Copyright (C) 2007, Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +from hulahop._hulahop import shutdown +from hulahop import _hulahop + +def startup(profile_path, components_dirs=[]): + _hulahop.set_profile_path(profile_path) + + for path in components_dirs: + _hulahop.add_components_path(path) + + _hulahop.startup() diff --git a/python/hulahop.defs b/python/hulahop.defs new file mode 100644 index 0000000..811b6c5 --- /dev/null +++ b/python/hulahop.defs @@ -0,0 +1,44 @@ +(define-object WebView + (in-module "Hulahop") + (parent "GtkBin") + (c-name "HulahopWebView") + (gtype-id "HULAHOP_TYPE_WEB_VIEW") +) + +(define-method get_browser + (of-object "HulahopWebView") + (c-name "hulahop_web_view_get_browser") + (return-type "none") +) + +(define-method get_window_root + (of-object "HulahopWebView") + (c-name "hulahop_web_view_get_window_root") + (return-type "none") +) + +(define-function startup + (c-name "hulahop_startup") + (return-type "gboolean") +) + +(define-function shutdown + (c-name "hulahop_shutdown") + (return-type "none") +) + +(define-function set_profile_path + (c-name "hulahop_set_profile_path") + (parameters + '("gchar*" "path") + ) + (return-type "none") +) + +(define-function add_components_path + (c-name "hulahop_add_components_path") + (parameters + '("gchar*" "path") + ) + (return-type "none") +) diff --git a/python/hulahop.override b/python/hulahop.override new file mode 100644 index 0000000..d846c64 --- /dev/null +++ b/python/hulahop.override @@ -0,0 +1,31 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- */ +%% +headers +#include +#include + +#include "hulahop-web-view.h" + +%% +modulename _hulahop +%% +import gtk.Bin as PyGtkBin_Type +%% +ignore-glob + *_get_type + _* +%% +override hulahop_web_view_get_browser noargs +static PyObject * +_wrap_hulahop_web_view_get_browser(PyGObject *self) +{ + return hulahop_web_view_get_browser(HULAHOP_WEB_VIEW(self->obj)); +} +%% +override hulahop_web_view_get_window_root noargs +static PyObject * +_wrap_hulahop_web_view_get_window_root(PyGObject *self) +{ + return hulahop_web_view_get_window_root(HULAHOP_WEB_VIEW(self->obj)); +} +%% diff --git a/python/hulahopmodule.c b/python/hulahopmodule.c new file mode 100644 index 0000000..ccbb773 --- /dev/null +++ b/python/hulahopmodule.c @@ -0,0 +1,26 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +void py_hulahop_register_classes (PyObject *d); + +extern PyMethodDef pyhulahop_functions[]; + +DL_EXPORT(void) +init_hulahop(void) +{ + PyObject *m, *d; + + init_pygobject (); + + m = Py_InitModule ("_hulahop", pyhulahop_functions); + d = PyModule_GetDict (m); + + pyhulahop_register_classes (d); + + if (PyErr_Occurred ()) { + Py_FatalError ("can't initialise module hulahop"); + } +} diff --git a/python/webview.py b/python/webview.py new file mode 100644 index 0000000..3b5e380 --- /dev/null +++ b/python/webview.py @@ -0,0 +1,43 @@ +# Copyright (C) 2007, Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +from hulahop import _hulahop + +from xpcom import components +from xpcom.components import interfaces + +class WebView(_hulahop.WebView): + def __init__(self): + _hulahop.WebView.__init__(self) + + def get_window_root(self): + return _hulahop.WebView.get_window_root(self) + + def get_browser(self): + return _hulahop.WebView.get_browser(self) + + def get_window(self): + return self.browser.contentDOMWindow + + def load_uri(self, uri): + web_nav = self.browser.queryInterface(interfaces.nsIWebNavigation) + web_nav.loadURI(uri, interfaces.nsIWebNavigation.LOAD_FLAGS_NONE, + None, None, None) + + window = property(get_window) + browser = property(get_browser) + window_root = property(get_window_root) -- cgit v0.9.1