From 7b03b9f3cbd3006150936bf3db5121e813ceda45 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Tue, 10 May 2011 00:22:55 +0000 Subject: Add mybutton.py and viewtoolbar.py. Update madagascaractivity.py. --- diff --git a/madagascaractivity.py b/madagascaractivity.py index c686f74..8663149 100755 --- a/madagascaractivity.py +++ b/madagascaractivity.py @@ -20,6 +20,7 @@ import gobject from sugar.activity import activity from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.toolcombobox import ToolComboBox import hulahop hulahop.startup(os.path.join(activity.get_activity_root(), 'data/gecko')) @@ -28,7 +29,7 @@ hulahop.startup(os.path.join(activity.get_activity_root(), 'data/gecko')) 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(), 'Madagascar/index.html') @@ -42,19 +43,85 @@ class MadagascarActivity(activity.Activity): self._web_view = Browser() - toolbox = activity.ActivityToolbox(self) - self.set_toolbox(toolbox) - toolbox.show() - - toolbar = Toolbar(self._web_view) - toolbox.add_toolbar(_('Navigation'), toolbar) - toolbar.show() - + try: + from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton + from sugar.activity.widgets import ActivityToolbarButton, StopButton, \ + ShareButton, KeepButton + 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) + stop_button.props.accelerator = 'Q' + 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) + self.set_canvas(self._web_view) self._web_view.show() - toolbox.set_current_toolbar(1) - self._web_view.load_uri(HOME) class Toolbar(gtk.Toolbar): @@ -77,11 +144,11 @@ class Toolbar(gtk.Toolbar): self.insert(self._forward, -1) self._forward.show() - home = ToolButton('zoom-home') - home.set_tooltip(_('Home')) - home.connect('clicked', self._go_home_cb) - self.insert(home, -1) - home.show() + self._home = ToolButton('go-home') + self._home.set_tooltip(_('Home')) + self._home.connect('clicked', self._go_home_cb) + self.insert(self._home, -1) + self._home.show() progress_listener = self._web_view.progress progress_listener.connect('location-changed', diff --git a/mybutton.py b/mybutton.py new file mode 100644 index 0000000..b1f1f84 --- /dev/null +++ b/mybutton.py @@ -0,0 +1,53 @@ +# 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/viewtoolbar.py b/viewtoolbar.py new file mode 100644 index 0000000..c5dc990 --- /dev/null +++ b/viewtoolbar.py @@ -0,0 +1,61 @@ +# Copyright (C) 2007, One Laptop Per Child +# +# 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 + +from gettext import gettext as _ + +import gtk + +from sugar.graphics.toolbutton import ToolButton + +class ViewToolbar(gtk.Toolbar): + def __init__(self, activity): + gtk.Toolbar.__init__(self) + + self._activity = activity + + self._browser = self._activity._web_view + + self.zoomout = ToolButton('zoom-out') + self.zoomout.set_tooltip(_('Zoom out')) + self.zoomout.connect('clicked', self.__zoomout_clicked_cb) + self.insert(self.zoomout, -1) + self.zoomout.show() + + self.zoomin = ToolButton('zoom-in') + self.zoomin.set_tooltip(_('Zoom in')) + self.zoomin.connect('clicked', self.__zoomin_clicked_cb) + self.insert(self.zoomin, -1) + self.zoomin.show() + + self.separator = gtk.SeparatorToolItem() + self.separator.set_draw(True) + self.insert(self.separator, -1) + self.separator.show() + + self.fullscreen = ToolButton('view-fullscreen') + self.fullscreen.set_tooltip(_('Fullscreen')) + self.fullscreen.connect('clicked', self.__fullscreen_clicked_cb) + self.insert(self.fullscreen, -1) + self.fullscreen.show() + + def __zoomin_clicked_cb(self, button): + self._browser.zoom_in() + + def __zoomout_clicked_cb(self, button): + self._browser.zoom_out() + + def __fullscreen_clicked_cb(self, button): + self._activity.fullscreen() -- cgit v0.9.1