summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2007-07-21 18:21:46 -0400
committerDan Williams <dcbw@redhat.com>2007-07-21 18:21:46 -0400
commit0469c7f24e7d0e40cd19635c78fa4855eab1069e (patch)
tree17fd91f0d3e355a12b6c5a4c4f71f862fcc55ebc
parent63f203648c643fda4ce85f15cc462a1a68cc8328 (diff)
downloadjukebox-activity.git-0469c7f24e7d0e40cd19635c78fa4855eab1069e.zip
jukebox-activity.git-0469c7f24e7d0e40cd19635c78fa4855eab1069e.tar.gz
jukebox-activity.git-0469c7f24e7d0e40cd19635c78fa4855eab1069e.tar.xz
Move controls to toolbar (Yaakov M. Nemoy)
-rwxr-xr-xjukeboxactivity.py129
1 files changed, 64 insertions, 65 deletions
diff --git a/jukeboxactivity.py b/jukeboxactivity.py
index a609915..dfa9a6c 100755
--- a/jukeboxactivity.py
+++ b/jukeboxactivity.py
@@ -51,6 +51,11 @@ class JukeboxActivity(activity.Activity):
toolbox = activity.ActivityToolbox(self)
self.set_toolbox(toolbox)
+
+ self.toolbar = toolbar = ControlToolbar(toolbox, self)
+ toolbox.add_toolbar(_('Play'), toolbar)
+
+ toolbar.show()
toolbox.show()
self.connect("shared", self._shared_cb)
@@ -81,22 +86,22 @@ class JukeboxActivity(activity.Activity):
self.show_all()
+ handle.uri = "file:///home/dcbw/Music/LivKristine_FakeASmile_320_big.mpeg"
if handle.uri:
gobject.idle_add(self._start, handle.uri)
def _joined_cb(self, activity):
+ logging.debug("someone joined")
pass
def _shared_cb(self, activity):
+ logging.debug("shared start")
pass
def read_file(self, file_path):
uri = "file://" + urllib.quote(os.path.abspath(file_path))
gobject.idle_add(self._start, uri)
- def write_file(self, file_path):
- pass
-
def _start(self, uri=None):
if not uri:
return False
@@ -106,67 +111,22 @@ class JukeboxActivity(activity.Activity):
return False
def create_ui(self):
- vbox = gtk.VBox()
- self.set_canvas(vbox)
-
self.videowidget = VideoWidget()
- vbox.pack_start(self.videowidget)
-
- hbox = gtk.HBox()
- vbox.pack_start(hbox, fill=False, expand=False)
-
- self.pause_image = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PAUSE,
- gtk.ICON_SIZE_BUTTON)
- self.pause_image.show()
- self.play_image = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PLAY,
- gtk.ICON_SIZE_BUTTON)
- self.play_image.show()
- self.button = button = gtk.Button()
- button.add(self.play_image)
- button.set_property('can-default', True)
- button.set_focus_on_click(False)
- button.show()
- hbox.pack_start(button, False)
- button.set_property('has-default', True)
- button.connect('clicked', lambda *args: self.play_toggled())
-
- self.adjustment = gtk.Adjustment(0.0, 0.00, 100.0, 0.1, 1.0, 1.0)
- hscale = gtk.HScale(self.adjustment)
- hscale.set_digits(2)
- hscale.set_update_policy(gtk.UPDATE_CONTINUOUS)
- hscale.connect('button-press-event', self.scale_button_press_cb)
- hscale.connect('button-release-event', self.scale_button_release_cb)
- hscale.connect('format-value', self.scale_format_value_cb)
- hbox.pack_start(hscale)
- self.hscale = hscale
+ self.set_canvas(self.videowidget)
def play_toggled(self):
- self.button.remove(self.button.child)
if self.player.is_playing():
self.player.pause()
- self.button.add(self.play_image)
+ self.toolbar.set_button_play()
else:
self.player.play()
if self.update_id == -1:
self.update_id = gobject.timeout_add(self.UPDATE_INTERVAL,
self.update_scale_cb)
- self.button.add(self.pause_image)
-
- def scale_format_value_cb(self, scale, value):
- if self.p_duration == -1:
- real = 0
- else:
- real = value * self.p_duration / 100
-
- seconds = real / gst.SECOND
-
- return "%02d:%02d" % (seconds / 60, seconds % 60)
+ self.toolbar.set_button_pause()
def scale_button_press_cb(self, widget, event):
- # see seek.c:start_seek
- gst.debug('starting seek')
-
- self.button.set_sensitive(False)
+ self.toolbar.button.set_sensitive(False)
self.was_playing = self.player.is_playing()
if self.was_playing:
self.player.pause()
@@ -178,13 +138,12 @@ class JukeboxActivity(activity.Activity):
# make sure we get changed notifies
if self.changed_id == -1:
- self.changed_id = self.hscale.connect('value-changed',
+ self.changed_id = self.toolbar.hscale.connect('value-changed',
self.scale_value_changed_cb)
def scale_value_changed_cb(self, scale):
# see seek.c:seek_cb
real = long(scale.get_value() * self.p_duration / 100) # in ns
- gst.debug('value changed, perform seek to %r' % real)
self.player.seek(real)
# allow for a preroll
self.player.get_state(timeout=50*gst.MSECOND) # 50 ms
@@ -194,12 +153,11 @@ class JukeboxActivity(activity.Activity):
widget.disconnect(self.changed_id)
self.changed_id = -1
- self.button.set_sensitive(True)
+ self.toolbar.button.set_sensitive(True)
if self.seek_timeout_id != -1:
gobject.source_remove(self.seek_timeout_id)
self.seek_timeout_id = -1
else:
- gst.debug('released slider, setting back to playing')
if self.was_playing:
self.player.play()
@@ -213,17 +171,60 @@ 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.adjustment.set_value(value)
+ self.toolbar.adjustment.set_value(value)
return True
+class ControlToolbar(gtk.Toolbar):
+ def __init__(self, toolbox, jukebox):
+ gtk.Toolbar.__init__(self)
+
+ self.toolbox = toolbox
+ self.jukebox = jukebox
+
+ self.pause_image = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PAUSE,
+ gtk.ICON_SIZE_BUTTON)
+ self.pause_image.show()
+ self.play_image = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PLAY,
+ gtk.ICON_SIZE_BUTTON)
+ self.play_image.show()
+
+ self.button = gtk.ToolButton()
+ self.button.set_icon_widget(self.play_image)
+ self.button.set_property('can-default', True)
+ self.button.show()
+ self.button.connect('clicked', self._button_clicked_cb)
+
+ self.insert(self.button, -1)
+
+ self.adjustment = gtk.Adjustment(0.0, 0.00, 100.0, 0.1, 1.0, 1.0)
+ self.hscale = gtk.HScale(self.adjustment)
+ self.hscale.set_draw_value(False)
+ 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)
+
+ def _button_clicked_cb(self, widget):
+ self.jukebox.play_toggled()
+
+ def set_button_play(self):
+ self.button.set_icon_widget(self.play_image)
+
+ def set_button_pause(self):
+ self.button.set_icon_widget(self.pause_image)
+
class GstPlayer:
def __init__(self, videowidget):
self.playing = False
self.player = gst.element_factory_make("playbin", "player")
# FIXME: hook up to the 'error' signal of the playbin
- xvsink = gst.element_factory_make("xvimagesink", "xvimagesink")
+ xvsink = gst.element_factory_make("ximagesink", "ximagesink")
self.player.set_property("video-sink", xvsink)
self.videowidget = videowidget
@@ -276,7 +277,6 @@ class GstPlayer:
"""
@param location: time to seek to, in nanoseconds
"""
- gst.debug("seeking to %r" % location)
event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
gst.SEEK_TYPE_SET, location,
@@ -284,24 +284,23 @@ class GstPlayer:
res = self.player.send_event(event)
if res:
- gst.info("setting new stream time to 0")
self.player.set_new_stream_time(0L)
else:
- gst.error("seek to %r failed" % location)
+ logging.debug("seek to %r failed" % location)
def pause(self):
- gst.info("pausing player")
+ logging.debug("pausing player")
self.player.set_state(gst.STATE_PAUSED)
self.playing = False
def play(self):
- gst.info("playing player")
+ logging.debug("playing player")
self.player.set_state(gst.STATE_PLAYING)
self.playing = True
def stop(self):
self.player.set_state(gst.STATE_NULL)
- gst.info("stopped player")
+ logging.debug("stopped player")
def get_state(self, timeout=1):
return self.player.get_state(timeout=timeout)
@@ -314,6 +313,7 @@ class VideoWidget(gtk.DrawingArea):
gtk.DrawingArea.__init__(self)
self.imagesink = None
self.unset_flags(gtk.DOUBLE_BUFFERED)
+ self.set_flags(gtk.APP_PAINTABLE)
def do_expose_event(self, event):
if self.imagesink:
@@ -327,4 +327,3 @@ class VideoWidget(gtk.DrawingArea):
self.imagesink = sink
self.imagesink.set_xwindow_id(self.window.xid)
-