Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/websdk
diff options
context:
space:
mode:
authorSebastian Silva <sebastian@sugarlabs.org>2011-10-12 00:54:31 (GMT)
committer Sebastian Silva <sebastian@sugarlabs.org>2011-10-12 00:54:31 (GMT)
commitfe1a1eb79bf0f1df8bbc56d2402e32061af79d06 (patch)
treed39e3b7780e4b6949250d490a4a7a874f788981c /websdk
parent5861585e94a32b3032ac473804bf90c6e1363940 (diff)
Tidy up code a bit - added documentation
Diffstat (limited to 'websdk')
-rw-r--r--websdk/browser.py59
-rw-r--r--websdk/inspector.py79
-rw-r--r--websdk/skel.py30
3 files changed, 168 insertions, 0 deletions
diff --git a/websdk/browser.py b/websdk/browser.py
new file mode 100644
index 0000000..e6ad639
--- /dev/null
+++ b/websdk/browser.py
@@ -0,0 +1,59 @@
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import os
+import time
+import logging
+from gettext import gettext as _
+
+import gobject
+import gtk
+import hulahop
+import xpcom
+from xpcom.nsError import *
+from xpcom import components
+from xpcom.components import interfaces
+from hulahop.webview import WebView
+
+from sugar.datastore import datastore
+from sugar import profile
+from sugar import env
+from sugar.activity import activity
+from sugar.graphics import style
+
+_ZOOM_AMOUNT = 0.1
+
+class Browser(WebView):
+ def __init__(self):
+ WebView.__init__(self)
+
+ def do_setup(self):
+ WebView.do_setup(self)
+
+ def zoom_in(self):
+ contentViewer = self.doc_shell.queryInterface( \
+ interfaces.nsIDocShell).contentViewer
+ if contentViewer is not None:
+ markupDocumentViewer = contentViewer.queryInterface( \
+ interfaces.nsIMarkupDocumentViewer)
+ markupDocumentViewer.fullZoom += _ZOOM_AMOUNT
+
+ def zoom_out(self):
+ contentViewer = self.doc_shell.queryInterface( \
+ interfaces.nsIDocShell).contentViewer
+ if contentViewer is not None:
+ markupDocumentViewer = contentViewer.queryInterface( \
+ interfaces.nsIMarkupDocumentViewer)
+ markupDocumentViewer.fullZoom -= _ZOOM_AMOUNT
+
diff --git a/websdk/inspector.py b/websdk/inspector.py
new file mode 100644
index 0000000..df3db38
--- /dev/null
+++ b/websdk/inspector.py
@@ -0,0 +1,79 @@
+# Copyright (C) 2008 Jan Alonzo <jmalonzo@unpluggable.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import gtk
+import webkit
+
+class Inspector (gtk.Window):
+ def __init__ (self, inspector):
+ """initialize the WebInspector class"""
+ gtk.Window.__init__(self)
+ self.set_default_size(600, 480)
+
+ self._web_inspector = inspector
+
+ self._web_inspector.connect("inspect-web-view",
+ self._inspect_web_view_cb)
+ self._web_inspector.connect("show-window",
+ self._show_window_cb)
+ self._web_inspector.connect("attach-window",
+ self._attach_window_cb)
+ self._web_inspector.connect("detach-window",
+ self._detach_window_cb)
+ self._web_inspector.connect("close-window",
+ self._close_window_cb)
+ self._web_inspector.connect("finished",
+ self._finished_cb)
+
+ self.connect("delete-event", self._close_window_cb)
+
+ def _inspect_web_view_cb (self, inspector, web_view):
+ """Called when the 'inspect' menu item is activated"""
+ scrolled_window = gtk.ScrolledWindow()
+ scrolled_window.props.hscrollbar_policy = gtk.POLICY_AUTOMATIC
+ scrolled_window.props.vscrollbar_policy = gtk.POLICY_AUTOMATIC
+ webview = webkit.WebView()
+ scrolled_window.add(webview)
+ scrolled_window.show_all()
+
+ self.add(scrolled_window)
+ return webview
+
+ def _show_window_cb (self, inspector):
+ """Called when the inspector window should be displayed"""
+ self.present()
+ return True
+
+ def _attach_window_cb (self, inspector):
+ """Called when the inspector should displayed in the same
+ window as the WebView being inspected
+ """
+ return False
+
+ def _detach_window_cb (self, inspector):
+ """Called when the inspector should appear in a separate window"""
+ return False
+
+ def _close_window_cb (self, inspector, view):
+ """Called when the inspector window should be closed"""
+ self.hide()
+ return True
+
+ def _finished_cb (self, inspector):
+ """Called when inspection is done"""
+ self._web_inspector = 0
+ self.destroy()
+ return False
diff --git a/websdk/skel.py b/websdk/skel.py
new file mode 100644
index 0000000..9336a07
--- /dev/null
+++ b/websdk/skel.py
@@ -0,0 +1,30 @@
+import os
+import sys
+from flask import Flask
+from flaskext.genshi import Genshi, render_response
+from werkzeug.utils import redirect
+from flask import request,url_for
+
+app = Flask(__name__)
+app.debug = True
+genshi = Genshi(app)
+
+def shutdown_server():
+ func = request.environ.get('werkzeug.server.shutdown')
+ if func is None:
+ raise RuntimeError('Not running with the Werkzeug Server')
+ func()
+
+@app.route('/')
+def index():
+ return render_response('index.html')
+
+@app.route('/shutdown')
+def shutdown():
+ shutdown_server()
+ return 'Server shutting down...'
+
+if __name__=="__main__":
+ port=int(sys.argv[1])
+ app.run(port=port)
+ #or app.run(host='0.0.0.0')