From b7c09785221f68a14287afc46a4cf689ec82cff3 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 08 Mar 2011 00:27:53 +0000 Subject: Added support for new toolbars. --- diff --git a/mybutton.py b/mybutton.py new file mode 100644 index 0000000..2d1677d --- /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.share.hide() + toolbar.stop.hide() + toolbar.keep.hide() + + ToolbarButton.__init__(self, page=toolbar, **kwargs) + + icon = _create_activity_icon(activity.metadata) + self.set_icon_widget(icon) + icon.show() diff --git a/typingturtle.py b/typingturtle.py index 1cf9231..5bfa31f 100755 --- a/typingturtle.py +++ b/typingturtle.py @@ -84,23 +84,43 @@ class TypingTurtle(sugar.activity.activity.Activity): self.show_all() - # Hide the sharing button from the activity toolbar since we don't support sharing. - activity_toolbar = self.tbox.get_activity_toolbar() - activity_toolbar.share.props.visible = False - - self.editorbtn = sugar.graphics.toolbutton.ToolButton('format-justify-left') - self.editorbtn.set_tooltip(_("Edit Lessons")) - self.editorbtn.connect('clicked', self.editor_clicked_cb) - - share_idx = activity_toolbar.get_item_index(activity_toolbar.share) - activity_toolbar.insert(self.editorbtn, share_idx) - self.editorbtn.show_all() def build_toolbox(self): - self.tbox = sugar.activity.activity.ActivityToolbox(self) - self.tbox.show_all() - - self.set_toolbox(self.tbox) + try: + from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton + from sugar.activity.widgets import ActivityToolbarButton, StopButton + from mybutton import MyActivityToolbarButton + + toolbar_box = ToolbarBox() + activity_button = MyActivityToolbarButton(self) + toolbar_box.toolbar.insert(activity_button, 0) + activity_button.show() + + separator = gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_expand(True) + toolbar_box.toolbar.insert(separator, -1) + separator.show() + + editorbtn = sugar.graphics.toolbutton.ToolButton('format-justify-left') + editorbtn.set_tooltip(_("Edit Lessons")) + editorbtn.connect('clicked', self.editor_clicked_cb) + toolbar_box.toolbar.insert(editorbtn, -2) + editorbtn.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() + toolbar=toolbar_box.toolbar + except ImportError: + self.tbox = sugar.activity.activity.ActivityToolbox(self) + self.tbox.show_all() + + self.set_toolbox(self.tbox) def editor_clicked_cb(self, btn): self.push_screen(editlessonlistscreen.EditLessonListScreen(self, self.mainscreen.lessons)) -- cgit v0.9.1