Support new toolbars widgets in activity.py

This commit is contained in:
Aleksey Lim 2009-07-13 01:40:23 +00:00
parent 55609885de
commit 442034bb8b
2 changed files with 63 additions and 24 deletions

View File

@ -73,6 +73,7 @@ from sugar.graphics.toolcombobox import ToolComboBox
from sugar.graphics.alert import Alert from sugar.graphics.alert import Alert
from sugar.graphics.icon import Icon from sugar.graphics.icon import Icon
from sugar.graphics.xocolor import XoColor from sugar.graphics.xocolor import XoColor
from sugar.graphics.toolbar import Toolbar, ToolbarButton
from sugar.datastore import datastore from sugar.datastore import datastore
from sugar.session import XSMPClient from sugar.session import XSMPClient
from sugar import wm from sugar import wm
@ -94,7 +95,7 @@ class ActivityToolbar(gtk.Toolbar):
All activities should have this toolbar. It is easiest to add it to your All activities should have this toolbar. It is easiest to add it to your
Activity by using the ActivityToolbox. Activity by using the ActivityToolbox.
""" """
def __init__(self, activity): def __init__(self, activity, hide_stop=False):
gtk.Toolbar.__init__(self) gtk.Toolbar.__init__(self)
self._activity = activity self._activity = activity
@ -141,11 +142,9 @@ class ActivityToolbar(gtk.Toolbar):
self.insert(self.keep, -1) self.insert(self.keep, -1)
self.keep.show() self.keep.show()
self.stop = ToolButton('activity-stop', tooltip=_('Stop')) if not hide_stop:
self.stop.props.accelerator = '<Ctrl>Q' stop = stop_button(activity)
self.stop.connect('clicked', self.__stop_clicked_cb) self.insert(stop, -1)
self.insert(self.stop, -1)
self.stop.show()
self._update_title_sid = None self._update_title_sid = None
@ -177,9 +176,6 @@ class ActivityToolbar(gtk.Toolbar):
def __keep_clicked_cb(self, button): def __keep_clicked_cb(self, button):
self._activity.copy() self._activity.copy()
def __stop_clicked_cb(self, button):
self._activity.close()
def __jobject_updated_cb(self, jobject): def __jobject_updated_cb(self, jobject):
self.title.set_text(jobject['title']) self.title.set_text(jobject['title'])
@ -254,30 +250,20 @@ class EditToolbar(gtk.Toolbar):
def __init__(self): def __init__(self):
gtk.Toolbar.__init__(self) gtk.Toolbar.__init__(self)
self.undo = ToolButton('edit-undo') self.undo = undo_button()
self.undo.set_tooltip(_('Undo'))
self.insert(self.undo, -1) self.insert(self.undo, -1)
self.undo.show()
self.redo = ToolButton('edit-redo') self.redo = redo_button()
self.redo.set_tooltip(_('Redo'))
self.insert(self.redo, -1) self.insert(self.redo, -1)
self.redo.show()
self.separator = gtk.SeparatorToolItem() self.separator = separator()
self.separator.set_draw(True)
self.insert(self.separator, -1) self.insert(self.separator, -1)
self.separator.show()
self.copy = ToolButton('edit-copy') self.copy = copy_button()
self.copy.set_tooltip(_('Copy'))
self.insert(self.copy, -1) self.insert(self.copy, -1)
self.copy.show()
self.paste = ToolButton('edit-paste') self.paste = paste_button()
self.paste.set_tooltip(_('Paste'))
self.insert(self.paste, -1) self.insert(self.paste, -1)
self.paste.show()
class ActivityToolbox(Toolbox): class ActivityToolbox(Toolbox):
"""Creates the Toolbox for the Activity """Creates the Toolbox for the Activity
@ -1061,3 +1047,54 @@ def show_object_in_journal(object_id):
obj = bus.get_object(J_DBUS_SERVICE, J_DBUS_PATH) obj = bus.get_object(J_DBUS_SERVICE, J_DBUS_PATH)
journal = dbus.Interface(obj, J_DBUS_INTERFACE) journal = dbus.Interface(obj, J_DBUS_INTERFACE)
journal.ShowObject(object_id) journal.ShowObject(object_id)
def toolbar(activity):
activity_button = ToolbarButton(
page=ActivityToolbar(activity, hide_stop=True),
icon_name='computer-xo')
activity_button.show()
return activity_button
def expander():
separator = gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
separator.show()
return separator
def stop_button(activity, **kwargs):
stop = ToolButton('activity-stop', tooltip=_('Stop'), **kwargs)
stop.props.accelerator = '<Ctrl>Q'
stop.connect('clicked', lambda button: activity.close())
stop.show()
return stop
def undo_button(**kwargs):
undo = ToolButton('edit-undo', **kwargs)
undo.set_tooltip(_('Undo'))
undo.show()
return undo
def redo_button(**kwargs):
redo = ToolButton('edit-redo', **kwargs)
redo.set_tooltip(_('Redo'))
redo.show()
return redo
def separator(**kwargs):
separator = gtk.SeparatorToolItem(**kwargs)
separator.set_draw(True)
separator.show()
return separator
def copy_button(**kwargs):
copy = ToolButton('edit-copy', **kwargs)
copy.set_tooltip(_('Copy'))
copy.show()
return copy
def paste_button(**kwargs):
paste = ToolButton('edit-paste', **kwargs)
paste.set_tooltip(_('Paste'))
paste.show()
return paste

View File

@ -107,6 +107,8 @@ class RadioPalette(Palette):
if not children: if not children:
self.__toggled_cb(button, True) self.__toggled_cb(button, True)
return button
def update_button(self): def update_button(self):
for i in self.top.get_children(): for i in self.top.get_children():
self.__toggled_cb(i, True) self.__toggled_cb(i, True)