summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/wx/bindings/python
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit/wx/bindings/python')
-rw-r--r--Source/WebKit/wx/bindings/python/samples/simple.py162
-rw-r--r--Source/WebKit/wx/bindings/python/webview.i182
-rw-r--r--Source/WebKit/wx/bindings/python/wscript93
3 files changed, 437 insertions, 0 deletions
diff --git a/Source/WebKit/wx/bindings/python/samples/simple.py b/Source/WebKit/wx/bindings/python/samples/simple.py
new file mode 100644
index 0000000..2756760
--- /dev/null
+++ b/Source/WebKit/wx/bindings/python/samples/simple.py
@@ -0,0 +1,162 @@
+#!/usr/bin/python
+
+# Copyright (C) 2007 Kevin Ollivier All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+import wx
+import wx.webview
+
+class TestPanel(wx.Panel):
+ def __init__(self, parent, log, frame=None):
+ wx.Panel.__init__(
+ self, parent, -1,
+ style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE
+ )
+
+ self.log = log
+ self.current = "http://wxPython.org/"
+ self.frame = frame
+
+ if frame:
+ self.titleBase = frame.GetTitle()
+
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ btnSizer = wx.BoxSizer(wx.HORIZONTAL)
+
+ self.webview = wx.webview.WebView(self, -1)
+
+
+ btn = wx.Button(self, -1, "Open", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnOpenButton, btn)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
+
+ btn = wx.Button(self, -1, "<--", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnPrevPageButton, btn)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
+
+ btn = wx.Button(self, -1, "-->", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnNextPageButton, btn)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
+
+ btn = wx.Button(self, -1, "Stop", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnStopButton, btn)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
+
+ btn = wx.Button(self, -1, "Refresh", style=wx.BU_EXACTFIT)
+ self.Bind(wx.EVT_BUTTON, self.OnRefreshPageButton, btn)
+ btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)
+
+ txt = wx.StaticText(self, -1, "Location:")
+ btnSizer.Add(txt, 0, wx.CENTER|wx.ALL, 2)
+
+ self.location = wx.ComboBox(
+ self, -1, "", style=wx.CB_DROPDOWN|wx.PROCESS_ENTER
+ )
+
+ self.Bind(wx.EVT_COMBOBOX, self.OnLocationSelect, self.location)
+ self.location.Bind(wx.EVT_KEY_UP, self.OnLocationKey)
+ self.location.Bind(wx.EVT_CHAR, self.IgnoreReturn)
+ btnSizer.Add(self.location, 1, wx.EXPAND|wx.ALL, 2)
+
+ sizer.Add(btnSizer, 0, wx.EXPAND)
+ sizer.Add(self.webview, 1, wx.EXPAND)
+
+ self.webview.LoadURL(self.current)
+ self.location.Append(self.current)
+
+ self.webview.Bind(wx.webview.EVT_WEBVIEW_LOAD, self.OnStateChanged)
+
+ self.SetSizer(sizer)
+
+ def OnStateChanged(self, event):
+ statusbar = self.GetParent().GetStatusBar()
+ if statusbar:
+ if event.GetState() == wx.webview.WEBVIEW_LOAD_NEGOTIATING:
+ statusbar.SetStatusText("Contacting " + event.GetURL())
+ elif event.GetState() == wx.webview.WEBVIEW_LOAD_TRANSFERRING:
+ statusbar.SetStatusText("Loading " + event.GetURL())
+ elif event.GetState() == wx.webview.WEBVIEW_LOAD_DOC_COMPLETED:
+ statusbar.SetStatusText("")
+ self.location.SetValue(event.GetURL())
+ self.GetParent().SetTitle("wxWebView - " + self.webview.GetPageTitle())
+
+ def OnLocationKey(self, evt):
+ if evt.GetKeyCode() == wx.WXK_RETURN:
+ URL = self.location.GetValue()
+ self.location.Append(URL)
+ self.webview.LoadURL(URL)
+ else:
+ evt.Skip()
+
+ def IgnoreReturn(self, evt):
+ if evt.GetKeyCode() != wx.WXK_RETURN:
+ evt.Skip()
+
+ def OnLocationSelect(self, evt):
+ url = self.location.GetStringSelection()
+ self.webview.LoadURL(url)
+
+ def OnOpenButton(self, event):
+ dlg = wx.TextEntryDialog(self, "Open Location",
+ "Enter a full URL or local path",
+ self.current, wx.OK|wx.CANCEL)
+ dlg.CentreOnParent()
+
+ if dlg.ShowModal() == wx.ID_OK:
+ self.current = dlg.GetValue()
+ self.webview.LoadURL(self.current)
+
+ dlg.Destroy()
+
+ def OnPrevPageButton(self, event):
+ self.webview.GoBack()
+
+ def OnNextPageButton(self, event):
+ self.webview.GoForward()
+
+ def OnStopButton(self, evt):
+ self.webview.Stop()
+
+ def OnRefreshPageButton(self, evt):
+ self.webview.Reload()
+
+
+class wkFrame(wx.Frame):
+ def __init__(self):
+ wx.Frame.__init__(self, None, -1, "WebKit in wxPython!")
+
+ self.panel = TestPanel(self, -1)
+ self.panel.webview.LoadURL("http://www.wxwidgets.org/")
+ self.CreateStatusBar()
+
+class wkApp(wx.App):
+ def OnInit(self):
+ self.webFrame = wkFrame()
+ self.SetTopWindow(self.webFrame)
+ self.webFrame.Show()
+
+ return True
+
+app = wkApp(redirect=False)
+app.MainLoop()
diff --git a/Source/WebKit/wx/bindings/python/webview.i b/Source/WebKit/wx/bindings/python/webview.i
new file mode 100644
index 0000000..f1621b0
--- /dev/null
+++ b/Source/WebKit/wx/bindings/python/webview.i
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2007 Kevin Ollivier All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+%module webview
+
+%{
+#include "config.h"
+
+#include "wx/wxPython/wxPython.h"
+#include "wx/wxPython/pyclasses.h"
+#include "WebBrowserShell.h"
+#include "WebDOMSelection.h"
+#include "WebEdit.h"
+#include "WebFrame.h"
+#include "WebSettings.h"
+#include "WebView.h"
+
+#include "WebDOMAttr.h"
+#include "WebDOMCSSStyleDeclaration.h"
+#include "WebDOMDocument.h"
+#include "WebDOMDocumentFragment.h"
+#include "WebDOMDOMSelection.h"
+#include "WebDOMElement.h"
+#include "WebDOMEventListener.h"
+#include "WebDOMNamedNodeMap.h"
+#include "WebDOMNode.h"
+#include "WebDOMNodeList.h"
+#include "WebDOMObject.h"
+#include "WebDOMRange.h"
+
+#ifndef __WXMSW__
+PyObject* createDOMNodeSubtype(WebDOMNode* ptr, bool setThisOwn, bool isValueObject)
+{
+ //static wxPyTypeInfoHashMap* typeInfoCache = NULL;
+
+ //if (typeInfoCache == NULL)
+ // typeInfoCache = new wxPyTypeInfoHashMap;
+
+ swig_type_info* swigType = 0; //(*typeInfoCache)[name];
+ char* name = 0;
+ if (ptr) {
+ // it wasn't in the cache, so look it up from SWIG
+ switch (ptr->nodeType()) {
+ case WebDOMNode::WEBDOM_ELEMENT_NODE:
+ name = "WebDOMElement*";
+ break;
+ case WebDOMNode::WEBDOM_ATTRIBUTE_NODE:
+ name = "WebDOMAttr*";
+ break;
+ default:
+ name = "WebDOMNode*";
+ }
+ swigType = SWIG_TypeQuery(name);
+ if (swigType) {
+ if (isValueObject) {
+ return SWIG_Python_NewPointerObj(new WebDOMNode(*ptr), swigType, setThisOwn);
+ }
+
+ return SWIG_Python_NewPointerObj(ptr, swigType, setThisOwn);
+ }
+ // if it still wasn't found, try looking for a mapped name
+ //if (swigType) {
+ // and add it to the map if found
+ // (*typeInfoCache)[className] = swigType;
+ //}
+ }
+
+ Py_INCREF(Py_None);
+
+ return Py_None;
+}
+
+WebDOMString* createWebDOMString(PyObject* source)
+{
+ if (!PyString_Check(source) && !PyUnicode_Check(source)) {
+ PyErr_SetString(PyExc_TypeError, "String or Unicode type required");
+ return new WebDOMString();
+ }
+
+ char* tmpPtr;
+ Py_ssize_t tmpSize;
+
+ if (PyString_Check(source))
+ PyString_AsStringAndSize(source, &tmpPtr, &tmpSize);
+ else {
+ PyObject* str = PyUnicode_AsUTF8String(source);
+ PyString_AsStringAndSize(str, &tmpPtr, &tmpSize);
+ Py_DECREF(str);
+ }
+
+ WebDOMString temp = WebDOMString::fromUTF8(tmpPtr);
+
+ return new WebDOMString(temp);
+}
+
+#endif
+
+
+
+%}
+//---------------------------------------------------------------------------
+
+%import core.i
+%import windows.i
+
+#ifndef __WXMSW__
+%typemap(out) WebDOMNode* { $result = createDOMNodeSubtype($1, (bool)$owner, 0); }
+%typemap(out) WebDOMElement* { $result = createDOMNodeSubtype($1, (bool)$owner, 0); }
+%typemap(out) WebDOMNode { $result = createDOMNodeSubtype(&$1, (bool)$owner, 1); }
+%typemap(out) WebDOMElement { $result = createDOMNodeSubtype(&$1, (bool)$owner, 1); }
+%typemap(in) WebDOMString& { $1 = createWebDOMString($input); }
+%typemap(out) WebDOMString { $result = PyUnicode_DecodeUTF8($1.utf8().data(), $1.utf8().length(), NULL); }
+%typemap(out) WebDOMString& { $result = PyUnicode_DecodeUTF8($1.utf8().data(), $1.utf8().length(), NULL); }
+#endif
+
+MAKE_CONST_WXSTRING(WebViewNameStr);
+
+MustHaveApp(wxWebBrowserShell);
+MustHaveApp(wxWebFrame);
+MustHaveApp(wxWebView);
+
+%include WebKitDefines.h
+
+#ifndef __WXMSW__
+%include WebDOMObject.h
+%include WebDOMNode.h
+
+%include WebDOMAttr.h
+%include WebDOMDOMSelection.h
+%include WebDOMElement.h
+%include WebDOMNodeList.h
+%include WebDOMRange.h
+#endif
+
+%include WebBrowserShell.h
+%include WebDOMSelection.h
+%include WebEdit.h
+%include WebFrame.h
+%include WebSettings.h
+%include WebView.h
+
+%constant wxEventType wxEVT_WEBVIEW_BEFORE_LOAD;
+%constant wxEventType wxEVT_WEBVIEW_LOAD;
+%constant wxEventType wxEVT_WEBVIEW_NEW_WINDOW;
+%constant wxEventType wxEVT_WEBVIEW_RIGHT_CLICK;
+%constant wxEventType wxEVT_WEBVIEW_CONSOLE_MESSAGE;
+%constant wxEventType wxEVT_WEBVIEW_RECEIVED_TITLE;
+%constant wxEventType wxEVT_WEBVIEW_CONTENTS_CHANGED;
+%constant wxEventType wxEVT_WEBVIEW_SELECTION_CHANGED;
+
+%pythoncode {
+EVT_WEBVIEW_BEFORE_LOAD = wx.PyEventBinder( wxEVT_WEBVIEW_BEFORE_LOAD, 1 )
+EVT_WEBVIEW_LOAD = wx.PyEventBinder( wxEVT_WEBVIEW_LOAD, 1 )
+EVT_WEBVIEW_NEW_WINDOW = wx.PyEventBinder( wxEVT_WEBVIEW_NEW_WINDOW, 1 )
+EVT_WEBVIEW_RIGHT_CLICK = wx.PyEventBinder( wxEVT_WEBVIEW_RIGHT_CLICK, 1 )
+EVT_WEBVIEW_CONSOLE_MESSAGE = wx.PyEventBinder( wxEVT_WEBVIEW_CONSOLE_MESSAGE, 1 )
+EVT_WEBVIEW_RECEIVED_TITLE = wx.PyEventBinder( wxEVT_WEBVIEW_RECEIVED_TITLE, 1 )
+EVT_WEBVIEW_CONTENTS_CHANGED = wx.PyEventBinder( wxEVT_WEBVIEW_CONTENTS_CHANGED, 1 )
+EVT_WEBVIEW_SELECTION_CHANGED = wx.PyEventBinder( wxEVT_WEBVIEW_SELECTION_CHANGED, 1 )
+}
diff --git a/Source/WebKit/wx/bindings/python/wscript b/Source/WebKit/wx/bindings/python/wscript
new file mode 100644
index 0000000..0a1df31
--- /dev/null
+++ b/Source/WebKit/wx/bindings/python/wscript
@@ -0,0 +1,93 @@
+#! /usr/bin/env python
+
+# Copyright (C) 2009 Kevin Ollivier All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# wxWebKit Python bindings build script for the waf build system
+
+from settings import *
+import Logs
+import Options
+
+include_paths = [
+ os.path.join(wk_root, 'Source', 'JavaScriptCore'),
+ os.path.join(wk_root, 'Source', 'WebCore', 'bindings', 'cpp'),
+ os.path.join(wk_root, 'Source', 'WebCore', 'DerivedSources'),
+ os.path.join(wk_root, 'WebKit', 'wx'),
+ os.path.join(wx_root, 'wxPython', 'include'),
+ os.path.join(wx_root, '..', 'wxPython', 'include'),
+ ]
+
+def wxpy_swig_include():
+ dirs = [
+ 'include/wx-2.9/wx/wxPython/i_files',
+ 'include/wx-2.8/wx/wxPython/i_files',
+ 'include/wx/wxPython/i_files',
+ 'wxPython/src',
+ '../wxPython/src',
+ ]
+
+ for adir in dirs:
+ fullpath = os.path.join(wx_root, adir)
+ if os.path.exists(fullpath):
+ return fullpath
+
+ return ''
+
+def build(bld):
+ if Options.options.wxpython:
+ defines = ['SWIG_TYPE_TABLE=_wxPython_table', 'WXP_USE_THREAD=1', 'SWIG_PYTHON_OUTPUT_TUPLE']
+ wx_swig_args = []
+ for define in defines:
+ wx_swig_args.append('-D%s' % define)
+
+ try:
+ import wx.build.config
+ wx_swig_args += wx.build.config.swig_args
+ except:
+ Logs.warn("Cannot find wxPython, wxPython extension will not be built.")
+ return
+
+ wxpy_include = wxpy_swig_include()
+ if os.path.exists(wxpy_include):
+ include_paths.append(wxpy_include)
+ else:
+ Logs.warn("Cannot find location of wxPython .i files, wxPython extension will not be built.")
+ return
+
+ for inc_path in include_paths:
+ wx_swig_args.append('-I' + inc_path)
+
+ obj = bld.new_task_gen(
+ features = 'cxx cshlib pyext',
+ includes = ' '.join(include_paths),
+ source = 'webview.i',
+ swig_flags = ' '.join(wx_swig_args),
+ defines = defines,
+ target = '_webview',
+ uselib = 'WX CURL ICU XSLT XML SQLITE3 ' + get_config(),
+
+ libpath = [output_dir],
+ uselib_local = 'wxwebkit',
+ install_path = output_dir
+ )