diff options
-rw-r--r-- | ControlToolbar.py | 47 | ||||
-rw-r--r-- | jukeboxactivity.py | 96 |
2 files changed, 90 insertions, 53 deletions
diff --git a/ControlToolbar.py b/ControlToolbar.py index b9b80e1..ff94122 100644 --- a/ControlToolbar.py +++ b/ControlToolbar.py @@ -28,30 +28,23 @@ from sugar.graphics import iconentry from sugar.activity import activity -class ControlToolbar(gtk.Toolbar): - """Class to create the Control (play )toolbar""" +class Control(gobject.GObject): + """Class to create the Control (play) toolbar""" - __gsignals__ = { - 'go-fullscreen': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ([])) - } - - - def __init__(self, toolbox, jukebox): - gtk.Toolbar.__init__(self) - self.toolbox = toolbox + 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.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.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, @@ -67,13 +60,12 @@ 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.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 +73,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 +91,18 @@ 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.toolbar.insert(self._fullscreen, -1) self._fullscreen.show() - + def prev_button_clicked_cb(self,widget): self.jukebox.songchange('prev') @@ -133,3 +125,10 @@ class ControlToolbar(gtk.Toolbar): def _fullscreen_cb(self, button): self.emit('go-fullscreen') + + +gobject.type_register(Control) +gobject.signal_new("go-fullscreen", Control, + gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])) + + diff --git a/jukeboxactivity.py b/jukeboxactivity.py index fc20f2b..3655229 100644 --- a/jukeboxactivity.py +++ b/jukeboxactivity.py @@ -30,6 +30,19 @@ 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.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 +57,7 @@ import gst.interfaces import gtk import urllib -from ControlToolbar import ControlToolbar +from ControlToolbar import Control from ConfigParser import ConfigParser cf = ConfigParser() @@ -58,23 +71,50 @@ 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() + toolbox.show() + + toolbox.connect("key_press_event", self._key_press_event_cb) + self.control.connect('go-fullscreen', self.__go_fullscreen_cb) + + 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 - self.toolbar = toolbar = ControlToolbar(toolbox, self) - toolbox.add_toolbar(_('Play'), toolbar) + 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) + self.control = Control(toolbar_box.toolbar, self) + self.control.connect('go-fullscreen', self.__go_fullscreen_cb) - toolbar.show() - toolbox.show() - self.toolbar.connect('go-fullscreen', self.__go_fullscreen_cb) + separator = gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_expand(True) + toolbar_box.toolbar.insert(separator, -1) - 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_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 +157,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 +180,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 +231,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 +368,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 +396,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 +411,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 +429,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 |