diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2011-08-02 15:38:37 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2011-08-02 15:38:37 (GMT) |
commit | a031bd7be6c895899b05d1eff0acd42ca71d3b07 (patch) | |
tree | 0dbd4731666e0502b815f45a3b8a97c35a5dc0c7 | |
parent | 3bf11567e27e6975ab816d57fd2fc7b0e75c8074 (diff) |
Implement new toolbars - OLPC #10867
Signed-of-by: Manuel QuiƱones <manuq@laptop.org>
Reviewed-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | ControlToolbar.py | 64 | ||||
-rw-r--r-- | jukeboxactivity.py | 112 |
2 files changed, 119 insertions, 57 deletions
diff --git a/ControlToolbar.py b/ControlToolbar.py index b9b80e1..0943180 100644 --- a/ControlToolbar.py +++ b/ControlToolbar.py @@ -28,8 +28,8 @@ from sugar.graphics import iconentry from sugar.activity import activity -class ControlToolbar(gtk.Toolbar): - """Class to create the Control (play )toolbar""" +class ViewToolbar(gtk.Toolbar): + __gtype_name__ = 'ViewToolbar' __gsignals__ = { 'go-fullscreen': (gobject.SIGNAL_RUN_FIRST, @@ -37,22 +37,38 @@ class ControlToolbar(gtk.Toolbar): ([])) } - - def __init__(self, toolbox, jukebox): + def __init__(self): gtk.Toolbar.__init__(self) - self.toolbox = toolbox + + self._fullscreen = ToolButton('view-fullscreen') + self._fullscreen.set_tooltip(_('Fullscreen')) + self._fullscreen.connect('clicked', self._fullscreen_cb) + self.insert(self._fullscreen, -1) + self._fullscreen.show() + + def _fullscreen_cb(self, button): + self.emit('go-fullscreen') + + +class Control(gobject.GObject): + """Class to create the Control (play) toolbar""" + + def __init__(self, toolbar, jukebox): + gobject.GObject.__init__(self) + + self.toolbar = toolbar self.jukebox = jukebox - self.open_button = gtk.ToolButton(gtk.STOCK_FILE) + self.open_button = ToolButton('sound') self.open_button.show() self.open_button.connect('clicked', jukebox.open_button_clicked_cb) - self.insert(self.open_button, -1) + self.toolbar.insert(self.open_button, -1) - self.prev_button = gtk.ToolButton(gtk.STOCK_MEDIA_PREVIOUS) + self.prev_button = ToolButton('player_rew') + self.prev_button.set_tooltip(_('Previous')) self.prev_button.show() self.prev_button.connect('clicked', self.prev_button_clicked_cb) - self.insert(self.prev_button, -1) - + self.toolbar.insert(self.prev_button, -1) self.pause_image = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_BUTTON) @@ -67,13 +83,13 @@ class ControlToolbar(gtk.Toolbar): self.button.show() self.button.connect('clicked', self._button_clicked_cb) - self.insert(self.button, -1) + self.toolbar.insert(self.button, -1) - self.next_button = gtk.ToolButton(gtk.STOCK_MEDIA_NEXT) + self.next_button = ToolButton('player_fwd') + self.next_button.set_tooltip(_('Next')) self.next_button.show() self.next_button.connect('clicked', self.next_button_clicked_cb) - self.insert(self.next_button, -1) - + self.toolbar.insert(self.next_button, -1) self.adjustment = gtk.Adjustment(0.0, 0.00, 100.0, 0.1, 1.0, 1.0) self.hscale = gtk.HScale(self.adjustment) @@ -81,15 +97,15 @@ class ControlToolbar(gtk.Toolbar): self.hscale.set_update_policy(gtk.UPDATE_CONTINUOUS) self.hscale.connect('button-press-event', jukebox.scale_button_press_cb) self.hscale.connect('button-release-event', jukebox.scale_button_release_cb) - + self.scale_item = gtk.ToolItem() self.scale_item.set_expand(True) self.scale_item.add(self.hscale) - self.insert(self.scale_item, -1) + self.toolbar.insert(self.scale_item, -1) spacer = gtk.SeparatorToolItem() spacer.props.draw = False - self.insert(spacer, -1) + self.toolbar.insert(spacer, -1) spacer.show() self.audioscale = gtk.VolumeButton() @@ -99,18 +115,13 @@ class ControlToolbar(gtk.Toolbar): self.audio_scale_item = gtk.ToolItem() self.audio_scale_item.set_expand(False) self.audio_scale_item.add(self.audioscale) - self.insert(self.audio_scale_item, -1) + self.toolbar.insert(self.audio_scale_item, -1) spacer = gtk.SeparatorToolItem() spacer.props.draw = False - self.insert(spacer, -1) + self.toolbar.insert(spacer, -1) spacer.show() - self._fullscreen = ToolButton('view-fullscreen') - self._fullscreen.set_tooltip(_('Fullscreen')) - self._fullscreen.connect('clicked', self._fullscreen_cb) - self.insert(self._fullscreen, -1) - self._fullscreen.show() - + def prev_button_clicked_cb(self,widget): self.jukebox.songchange('prev') @@ -130,6 +141,3 @@ class ControlToolbar(gtk.Toolbar): self.button.set_sensitive(False) self.scale_item.set_sensitive(False) self.hscale.set_sensitive(False) - - def _fullscreen_cb(self, button): - self.emit('go-fullscreen') diff --git a/jukeboxactivity.py b/jukeboxactivity.py index 9366fb5..0ba3f4c 100644 --- a/jukeboxactivity.py +++ b/jukeboxactivity.py @@ -30,6 +30,20 @@ from sugar.activity import activity from sugar.graphics.objectchooser import ObjectChooser from sugar import mime +OLD_TOOLBAR = False +try: + from sugar.graphics.toolbarbox import ToolbarBox + from sugar.graphics.toolbarbox import ToolbarButton + from sugar.activity.widgets import StopButton +except ImportError: + OLD_TOOLBAR = True + +from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.xocolor import XoColor +from sugar import profile +from sugar.bundle.activitybundle import ActivityBundle +from sugar.graphics.icon import Icon + import pygtk pygtk.require('2.0') @@ -44,7 +58,7 @@ import gst.interfaces import gtk import urllib -from ControlToolbar import ControlToolbar +from ControlToolbar import Control, ViewToolbar from ConfigParser import ConfigParser cf = ConfigParser() @@ -58,23 +72,65 @@ class JukeboxActivity(activity.Activity): self.set_title(_('Jukebox Activity')) self.player = None - toolbox = activity.ActivityToolbox(self) - self.set_toolbox(toolbox) + if OLD_TOOLBAR: + toolbox = activity.ActivityToolbox(self) + self.set_toolbox(toolbox) + toolbar = gtk.Toolbar() + self.control = Control(toolbar, self) + toolbox.add_toolbar(_('Play'), toolbar) + + toolbar.show() + + _view_toolbar = ViewToolbar() + _view_toolbar.connect('go-fullscreen', + self.__go_fullscreen_cb) + toolbox.add_toolbar(_('View'), _view_toolbar) + _view_toolbar.show() - self.toolbar = toolbar = ControlToolbar(toolbox, self) - toolbox.add_toolbar(_('Play'), toolbar) + toolbox.show() - toolbar.show() - toolbox.show() - self.toolbar.connect('go-fullscreen', self.__go_fullscreen_cb) + toolbox.connect("key_press_event", self._key_press_event_cb) - self.toolbar.grab_focus() - #self.connect("shared", self._shared_cb) - activity_toolbar = toolbox.get_activity_toolbar() - activity_toolbar.remove(activity_toolbar.share) - activity_toolbar.share = None - activity_toolbar.remove(activity_toolbar.keep) - activity_toolbar.keep = None + toolbar.grab_focus() + #self.connect("shared", self._shared_cb) + activity_toolbar = toolbox.get_activity_toolbar() + activity_toolbar.remove(activity_toolbar.share) + activity_toolbar.share = None + activity_toolbar.remove(activity_toolbar.keep) + activity_toolbar.keep = None + + else: + toolbar_box = ToolbarBox() + activity_button = ToolButton() + color = XoColor(profile.get_color()) + bundle = ActivityBundle(activity.get_bundle_path()) + icon = Icon(file=bundle.get_icon(), xo_color=color) + activity_button.set_icon_widget(icon) + activity_button.show() + toolbar_box.toolbar.insert(activity_button, 0) + + _view_toolbar = ViewToolbar() + _view_toolbar.connect('go-fullscreen', + self.__go_fullscreen_cb) + view_toolbar_button = ToolbarButton( + page=_view_toolbar, + icon_name='toolbar-view') + _view_toolbar.show() + toolbar_box.toolbar.insert(view_toolbar_button, -1) + view_toolbar_button.show() + + self.control = Control(toolbar_box.toolbar, self) + + separator = gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_expand(True) + toolbar_box.toolbar.insert(separator, -1) + + toolbar_box.toolbar.insert(StopButton(self), -1) + + self.set_toolbar_box(toolbar_box) + toolbar_box.show_all() + toolbar_box.connect("key_press_event", self._key_press_event_cb) if handle.uri: pass @@ -117,8 +173,6 @@ class JukeboxActivity(activity.Activity): self.uri = handle.uri gobject.idle_add(self._start, self.uri) - self.toolbox.connect("key_press_event", self._key_press_event_cb) - def open_button_clicked_cb(self, widget): """ To open the dialog to select a new file""" #self.player.seek(0L) @@ -142,13 +196,13 @@ class JukeboxActivity(activity.Activity): def check_if_next_prev(self): if self.currentplaying == 0: - self.toolbar.prev_button.set_sensitive(False) + self.control.prev_button.set_sensitive(False) else: - self.toolbar.prev_button.set_sensitive(True) + self.control.prev_button.set_sensitive(True) if self.currentplaying == len(self.playlist) - 1: - self.toolbar.next_button.set_sensitive(False) + self.control.next_button.set_sensitive(False) else: - self.toolbar.next_button.set_sensitive(True) + self.control.next_button.set_sensitive(True) def songchange(self,direction): @@ -193,7 +247,7 @@ class JukeboxActivity(activity.Activity): def _player_error_cb(self, widget, message, detail): self.player.stop() self.player.set_uri(None) - self.toolbar.set_disabled() + self.control.set_disabled() self.bin.remove(self.videowidget) text = gtk.Label("Error: %s - %s" % (message, detail)) text.show_all() @@ -330,23 +384,23 @@ class JukeboxActivity(activity.Activity): def play_toggled(self): if self.player.is_playing(): self.player.pause() - self.toolbar.set_button_play() + self.control.set_button_play() else: if self.player.error: - self.toolbar.set_disabled() + self.control.set_disabled() else: self.player.play() if self.update_id == -1: self.update_id = gobject.timeout_add(self.UPDATE_INTERVAL, self.update_scale_cb) - self.toolbar.set_button_pause() + self.control.set_button_pause() def volume_changed_cb(self, widget, value): if self.player: self.player.player.set_property('volume', value) def scale_button_press_cb(self, widget, event): - self.toolbar.button.set_sensitive(False) + self.control.button.set_sensitive(False) self.was_playing = self.player.is_playing() if self.was_playing: self.player.pause() @@ -358,7 +412,7 @@ class JukeboxActivity(activity.Activity): # make sure we get changed notifies if self.changed_id == -1: - self.changed_id = self.toolbar.hscale.connect('value-changed', + self.changed_id = self.control.hscale.connect('value-changed', self.scale_value_changed_cb) def scale_value_changed_cb(self, scale): @@ -373,7 +427,7 @@ class JukeboxActivity(activity.Activity): widget.disconnect(self.changed_id) self.changed_id = -1 - self.toolbar.button.set_sensitive(True) + self.control.button.set_sensitive(True) if self.seek_timeout_id != -1: gobject.source_remove(self.seek_timeout_id) self.seek_timeout_id = -1 @@ -391,7 +445,7 @@ class JukeboxActivity(activity.Activity): self.p_position, self.p_duration = self.player.query_position() if self.p_position != gst.CLOCK_TIME_NONE: value = self.p_position * 100.0 / self.p_duration - self.toolbar.adjustment.set_value(value) + self.control.adjustment.set_value(value) return True |