diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-04-24 15:13:10 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-04-24 15:13:10 (GMT) |
commit | 67252589d137e58adce9d90c97b622b9453fa739 (patch) | |
tree | 4868708f90f1b577079a28ee5ffa3ea745a6bbc2 | |
parent | 0e59b5e2f5c6235e446036d0a1e6b39a83d6e53a (diff) |
Start port to Gtk3
Signed-off-by: Manuel Kaufmann <humitos@gmail.com>
Reviewed-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | browser.py | 59 | ||||
-rwxr-xr-x | helpactivity.py | 166 | ||||
-rw-r--r-- | mybutton.py | 53 | ||||
-rw-r--r-- | progresslistener.py | 89 | ||||
-rwxr-xr-x | setup.py | 2 | ||||
-rw-r--r-- | viewtoolbar.py | 12 |
6 files changed, 100 insertions, 281 deletions
@@ -12,53 +12,32 @@ # 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 - -from progresslistener import ProgressListener +from gi.repository import WebKit _ZOOM_AMOUNT = 0.1 -class Browser(WebView): - def __init__(self): - WebView.__init__(self) - self.progress = ProgressListener() +class Browser(WebKit.WebView): + def __init__(self): + WebKit.WebView.__init__(self) def do_setup(self): - WebView.do_setup(self) - self.progress.setup(self) + WebKit.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 + # contentViewer = self.doc_shell.queryInterface( \ + # interfaces.nsIDocShell).contentViewer + # if contentViewer is not None: + # markupDocumentViewer = contentViewer.queryInterface( \ + # interfaces.nsIMarkupDocumentViewer) + # markupDocumentViewer.fullZoom += _ZOOM_AMOUNT + pass 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 - + # contentViewer = self.doc_shell.queryInterface( \ + # interfaces.nsIDocShell).contentViewer + # if contentViewer is not None: + # markupDocumentViewer = contentViewer.queryInterface( \ + # interfaces.nsIMarkupDocumentViewer) + # markupDocumentViewer.fullZoom -= _ZOOM_AMOUNT + pass diff --git a/helpactivity.py b/helpactivity.py index 210c423..f8e3435 100755 --- a/helpactivity.py +++ b/helpactivity.py @@ -15,25 +15,21 @@ import os from gettext import gettext as _ -import gtk -import gobject +from gi.repository import Gtk +from gi.repository import GObject -from sugar.activity import activity -from sugar.graphics.toolbutton import ToolButton -from sugar.graphics.toolcombobox import ToolComboBox +from sugar3.activity import activity +from sugar3.graphics.toolbutton import ToolButton +from sugar3.graphics.toolbarbox import ToolbarBox, ToolbarButton +from sugar3.activity.widgets import ActivityToolbarButton +from sugar3.activity.widgets import StopButton -import hulahop -hulahop.startup(os.path.join(activity.get_activity_root(), 'data/gecko')) - -#from hulahop.webview import WebView from browser import Browser -import xpcom -from xpcom.components import interfaces from viewtoolbar import ViewToolbar -gobject.threads_init() -HOME = os.path.join(activity.get_bundle_path(), 'help/XO_Introduction.html') -#HOME = "http://website.com/something.html" +HOME = 'file://' + os.path.join(activity.get_bundle_path(), + 'help/XO_Introduction.html') + class HelpActivity(activity.Activity): def __init__(self, handle): @@ -43,89 +39,72 @@ class HelpActivity(activity.Activity): self._web_view = Browser() - try: - from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton - from sugar.activity.widgets import ActivityToolbarButton, StopButton, \ - ShareButton - from mybutton import MyActivityToolbarButton - - toolbar_box = ToolbarBox() - activity_button = MyActivityToolbarButton(self) - toolbar_box.toolbar.insert(activity_button, 0) - activity_button.show() - - viewtoolbar = ViewToolbar(self) - viewbutton = ToolbarButton(page=viewtoolbar, \ - icon_name='camera') - toolbar_box.toolbar.insert(viewbutton, -1) - viewbutton.show() - - separator = gtk.SeparatorToolItem() - #separator.props.draw = False - #separator.set_expand(True) - toolbar_box.toolbar.insert(separator, -1) - separator.show() - - #lets reuse the code below - navtoolbar = Toolbar(self._web_view) - - toolitem = gtk.ToolItem() - navtoolbar._home.reparent(toolitem) - toolbar_box.toolbar.insert(toolitem, -1) - navtoolbar._home.show() - toolitem.show() - - toolitem = gtk.ToolItem() - navtoolbar._back.reparent(toolitem) - toolbar_box.toolbar.insert(toolitem, -1) - navtoolbar._back.show() - toolitem.show() - - toolitem = gtk.ToolItem() - navtoolbar._forward.reparent(toolitem) - toolbar_box.toolbar.insert(toolitem, -1) - navtoolbar._forward.show() - toolitem.show() - - # we do not have collaboration features - # make the share option insensitive - self.max_participants = 1 - - separator = gtk.SeparatorToolItem() - separator.props.draw = False - separator.set_expand(True) - toolbar_box.toolbar.insert(separator, -1) - separator.show() - - stop_button = StopButton(self) - toolbar_box.toolbar.insert(stop_button, -1) - stop_button.show() - - self.set_toolbar_box(toolbar_box) - toolbar_box.show() - - except ImportError: - toolbox = activity.ActivityToolbox(self) - self.set_toolbox(toolbox) - toolbox.show() - - toolbar = Toolbar(self._web_view) - toolbox.add_toolbar(_('Navigation'), toolbar) - toolbar.show() - viewtoolbar = ViewToolbar(self) - toolbox.add_toolbar(_('View'),viewtoolbar) - viewtoolbar.show() - - toolbox.set_current_toolbar(1) - + + toolbar_box = ToolbarBox() + + activity_button = ActivityToolbarButton(self) + toolbar_box.toolbar.insert(activity_button, 0) + activity_button.show() + + viewtoolbar = ViewToolbar(self) + viewbutton = ToolbarButton(page=viewtoolbar, \ + icon_name='camera') + toolbar_box.toolbar.insert(viewbutton, -1) + viewbutton.show() + + separator = Gtk.SeparatorToolItem() + #separator.props.draw = False + #separator.set_expand(True) + toolbar_box.toolbar.insert(separator, -1) + separator.show() + + #lets reuse the code below + navtoolbar = Toolbar(self._web_view) + + toolitem = Gtk.ToolItem() + navtoolbar._home.reparent(toolitem) + toolbar_box.toolbar.insert(toolitem, -1) + navtoolbar._home.show() + toolitem.show() + + toolitem = Gtk.ToolItem() + navtoolbar._back.reparent(toolitem) + toolbar_box.toolbar.insert(toolitem, -1) + navtoolbar._back.show() + toolitem.show() + + toolitem = Gtk.ToolItem() + navtoolbar._forward.reparent(toolitem) + toolbar_box.toolbar.insert(toolitem, -1) + navtoolbar._forward.show() + toolitem.show() + + # we do not have collaboration features + # make the share option insensitive + self.max_participants = 1 + + separator = Gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_expand(True) + toolbar_box.toolbar.insert(separator, -1) + separator.show() + + stop_button = StopButton(self) + toolbar_box.toolbar.insert(stop_button, -1) + stop_button.show() + + self.set_toolbar_box(toolbar_box) + toolbar_box.show() + self.set_canvas(self._web_view) self._web_view.show() self._web_view.load_uri(HOME) -class Toolbar(gtk.Toolbar): + +class Toolbar(Gtk.Toolbar): def __init__(self, web_view): - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) self._web_view = web_view @@ -149,10 +128,12 @@ class Toolbar(gtk.Toolbar): self.insert(self._home, -1) self._home.show() + """ progress_listener = self._web_view.progress progress_listener.connect('location-changed', self._location_changed_cb) progress_listener.connect('loading-stop', self._loading_stop_cb) + """ def _location_changed_cb(self, progress_listener, uri): self.update_navigation_buttons() @@ -169,10 +150,9 @@ class Toolbar(gtk.Toolbar): def _go_back_cb(self, button): self._web_view.web_navigation.goBack() - + def _go_forward_cb(self, button): self._web_view.web_navigation.goForward() def _go_home_cb(self, button): self._web_view.load_uri(HOME) - diff --git a/mybutton.py b/mybutton.py deleted file mode 100644 index b1f1f84..0000000 --- a/mybutton.py +++ /dev/null @@ -1,53 +0,0 @@ -# mybutton.py A version of ActivityToolbarButton that hides the "Keep" -# button. - -# Copyright (C) 2010 James D. Simmons -# -# 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 US -import gtk -import gconf - -from sugar.graphics.toolbarbox import ToolbarButton -from sugar.activity.widgets import ActivityToolbar -from sugar.graphics.xocolor import XoColor -from sugar.graphics.icon import Icon -from sugar.bundle.activitybundle import ActivityBundle - -def _create_activity_icon(metadata): - if metadata.get('icon-color', ''): - color = XoColor(metadata['icon-color']) - else: - client = gconf.client_get_default() - color = XoColor(client.get_string('/desktop/sugar/user/color')) - - from sugar.activity.activity import get_bundle_path - bundle = ActivityBundle(get_bundle_path()) - icon = Icon(file=bundle.get_icon(), xo_color=color) - - return icon - -class MyActivityToolbarButton(ToolbarButton): - - def __init__(self, activity, **kwargs): - toolbar = ActivityToolbar(activity, orientation_left=True) - toolbar.stop.hide() - toolbar.keep.hide() - toolbar.title.unset_flags(gtk.CAN_FOCUS) - - ToolbarButton.__init__(self, page=toolbar, **kwargs) - - icon = _create_activity_icon(activity.metadata) - self.set_icon_widget(icon) - icon.show() diff --git a/progresslistener.py b/progresslistener.py deleted file mode 100644 index cf3cb43..0000000 --- a/progresslistener.py +++ /dev/null @@ -1,89 +0,0 @@ -# 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 gobject -import xpcom -from xpcom.components import interfaces - -class ProgressListener(gobject.GObject): - _com_interfaces_ = interfaces.nsIWebProgressListener - - __gsignals__ = { - 'location-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([object])), - 'loading-start': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([])), - 'loading-stop': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([])), - 'loading-progress': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([float])) - } - - def __init__(self): - gobject.GObject.__init__(self) - - self.total_requests = 0 - self.completed_requests = 0 - - self._wrapped_self = xpcom.server.WrapObject( \ - self, interfaces.nsIWebProgressListener) - weak_ref = xpcom.client.WeakReference(self._wrapped_self) - - self._reset_requests_count() - - def setup(self, browser): - mask = interfaces.nsIWebProgress.NOTIFY_STATE_NETWORK | \ - interfaces.nsIWebProgress.NOTIFY_STATE_REQUEST | \ - interfaces.nsIWebProgress.NOTIFY_LOCATION - - browser.web_progress.addProgressListener(self._wrapped_self, mask) - - def _reset_requests_count(self): - self.total_requests = 0 - self.completed_requests = 0 - - def onLocationChange(self, webProgress, request, location): - self.emit('location-changed', location) - - def onProgressChange(self, webProgress, request, curSelfProgress, - maxSelfProgress, curTotalProgress, maxTotalProgress): - pass - - def onSecurityChange(self, webProgress, request, state): - pass - - def onStateChange(self, webProgress, request, stateFlags, status): - if stateFlags & interfaces.nsIWebProgressListener.STATE_IS_REQUEST: - if stateFlags & interfaces.nsIWebProgressListener.STATE_START: - self.total_requests += 1 - elif stateFlags & interfaces.nsIWebProgressListener.STATE_STOP: - self.completed_requests += 1 - - if stateFlags & interfaces.nsIWebProgressListener.STATE_IS_NETWORK: - if stateFlags & interfaces.nsIWebProgressListener.STATE_START: - self.emit('loading-start') - self._reset_requests_count() - elif stateFlags & interfaces.nsIWebProgressListener.STATE_STOP: - self.emit('loading-stop') - - if self.total_requests < self.completed_requests: - self.emit('loading-progress', 1.0) - elif self.total_requests > 0: - self.emit('loading-progress', float(self.completed_requests) / - float(self.total_requests)) - else: - self.emit('loading-progress', 0.0) - - def onStatusChange(self, webProgress, request, status, message): - pass @@ -14,6 +14,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -from sugar.activity import bundlebuilder +from sugar3.activity import bundlebuilder bundlebuilder.start() diff --git a/viewtoolbar.py b/viewtoolbar.py index c5dc990..13a1ce5 100644 --- a/viewtoolbar.py +++ b/viewtoolbar.py @@ -16,13 +16,15 @@ from gettext import gettext as _ -import gtk +from gi.repository import Gtk +from gi.repository import GObject -from sugar.graphics.toolbutton import ToolButton +from sugar3.graphics.toolbutton import ToolButton -class ViewToolbar(gtk.Toolbar): + +class ViewToolbar(Gtk.Toolbar): def __init__(self, activity): - gtk.Toolbar.__init__(self) + GObject.GObject.__init__(self) self._activity = activity @@ -40,7 +42,7 @@ class ViewToolbar(gtk.Toolbar): self.insert(self.zoomin, -1) self.zoomin.show() - self.separator = gtk.SeparatorToolItem() + self.separator = Gtk.SeparatorToolItem() self.separator.set_draw(True) self.insert(self.separator, -1) self.separator.show() |