From 36f95d77362c7a6c8eb208611b9d2ff039ab24ea Mon Sep 17 00:00:00 2001 From: bjschuma Date: Tue, 16 Mar 2010 19:54:04 -0400 Subject: [PATCH] Made more new gui elements, including progress bars and play/pause buttons --- src/core/event.py | 5 ++-- src/core/gstreamer.py | 55 +++++++++++++++++++++++++++++++++--- src/extra/et/__init__.py | 2 +- src/extra/et/times.py | 34 ++++++++++++++++++++++ src/extra/oGtk/__init__.py | 2 +- src/extra/oGtk/playButton.py | 27 ++++++++++++------ src/extra/oGtk/progbar.py | 47 ++++++++++++++++++++++++++++++ src/extra/ocarina-extra.py | 2 ++ src/simple.xml | 7 ++--- 9 files changed, 160 insertions(+), 21 deletions(-) create mode 100644 src/extra/et/times.py create mode 100644 src/extra/oGtk/progbar.py diff --git a/src/core/event.py b/src/core/event.py index aceaf3d2..14850450 100644 --- a/src/core/event.py +++ b/src/core/event.py @@ -32,10 +32,11 @@ class Event(Dict): # Add a "guest" (function or script) to this event def invite(self, name, guest, priority=None): + type = self.type(guest) if priority==None: - if self.type(guest)=='str' or self.type(guest)=='unicode': + if type=='str' or type=='unicode': priority = 200 - elif self.type(guest)=='function' or self.type(guest)=='instancemethod': + else: priority = 100 if self.has(name) == False: self[name] = GuestList(name) diff --git a/src/core/gstreamer.py b/src/core/gstreamer.py index 7bb69f2b..6f4e9cb0 100644 --- a/src/core/gstreamer.py +++ b/src/core/gstreamer.py @@ -51,16 +51,25 @@ def init(): load(song) +def getstate(): + global player + state = player.get_state()[1] + write("Gstreamer state: "+str(state), 1) + return player.get_state()[1] + + def play(): global player - write("Gstreamer state: playing", 1) player.set_state(gst.STATE_PLAYING) + if getstate() != gst.STATE_PLAYING: + ocarina.events.stop("ocarina-play") def pause(): global player - write("Gstreamer state: paused", 1) player.set_state(gst.STATE_PAUSED) + if getstate() != gst.STATE_PAUSED: + ocarina.events.stop("ocarina-pause") def onMessage(bus, message): @@ -78,12 +87,50 @@ def onMessage(bus, message): ocarina.events.start("tags-changed") +def duration(): + global player + global time + state = getstate() + if (state!=gst.STATE_PLAYING) and (state!=gst.STATE_PAUSED): + return 0 + total = player.query_duration(time)[0] + return total + + +def currentpos(): + global player + global time + state = getstate() + if (state!=gst.STATE_PLAYING) and (state!=gst.STATE_PAUSED): + return 0 + position = player.query_position(time)[0] + return position + + +def getProgress(): + global player + global time + state = getstate() + if (state!=gst.STATE_PLAYING) and (state!=gst.STATE_PAUSED): + return 0 + total = duration() + current = currentpos() + return float(current) / float(total) + + +def seek(prcnt): + global player + global time + newTime = duration() * prcnt + player.seek_simple(time,gst.SEEK_FLAG_FLUSH,newTime) + + bus.add_signal_watch() bus.connect("message", onMessage) ocarina.events.invite("ocarina-start", init, 60) ocarina.events.invite("ocarina-stop", uninit) -ocarina.events.invite("ocarina-play", play) -ocarina.events.invite("ocarina-pause", pause) +ocarina.events.invite("ocarina-play", play,50) +ocarina.events.invite("ocarina-pause", pause,50) # #def setvol(value): diff --git a/src/extra/et/__init__.py b/src/extra/et/__init__.py index daaea367..9410a8ff 100644 --- a/src/extra/et/__init__.py +++ b/src/extra/et/__init__.py @@ -1,4 +1,4 @@ __author__="bjschuma" __date__ ="$Mar 14, 2010 9:53:12 PM$" -__all__ = ["xm"] \ No newline at end of file +__all__ = ["times", "xm"] \ No newline at end of file diff --git a/src/extra/et/times.py b/src/extra/et/times.py new file mode 100644 index 00000000..66c05973 --- /dev/null +++ b/src/extra/et/times.py @@ -0,0 +1,34 @@ +#! /usr/bin/python + +# To change this template, choose Tools | Templates +# and open the template in the editor. + +__author__="bjschuma" +__date__ ="$Mar 16, 2010 7:36:48 PM$" + + +def ftime(time): + time = time/1000000000 + #print time + # Find hour + length = "" + if time >= 3600: + hour = time/3600 + time = time - (hour * 3600) + if hour > 0: + length=str(hour)+":" + # Find minute + if time >= 60: + min = time/60 + time = time - (min * 60) + if min < 10: + length+="0" + length+=str(min)+":" + else: + length+="00:" + # Remainder is seconds + sec = time + if sec < 10: + length+="0" + length+=str(sec) + return length \ No newline at end of file diff --git a/src/extra/oGtk/__init__.py b/src/extra/oGtk/__init__.py index 73d470bf..69796f6d 100644 --- a/src/extra/oGtk/__init__.py +++ b/src/extra/oGtk/__init__.py @@ -2,4 +2,4 @@ __author__="bjschuma" __date__ ="$Mar 14, 2010 10:21:40 PM$" -__all__ = ["box", "button", "label", "playButton", "songInfo", "window"] \ No newline at end of file +__all__ = ["box", "button", "label", "playButton", "progbar", "songInfo", "window"] \ No newline at end of file diff --git a/src/extra/oGtk/playButton.py b/src/extra/oGtk/playButton.py index d5090efd..0e7a1bec 100644 --- a/src/extra/oGtk/playButton.py +++ b/src/extra/oGtk/playButton.py @@ -8,7 +8,9 @@ __date__ ="$Mar 15, 2010 11:47:24 PM$" import guibuilder +import ocarina import gtk +from ct import cmd class PlayButton(gtk.HBox): def __init__(self,attrs): @@ -17,27 +19,36 @@ class PlayButton(gtk.HBox): for a in attrs: if a=="size": if attrs[a] == "large": - size = gtk.ICON_SIZE_LARGE_TOOLBAR + size = gtk.ICON_SIZE_DIALOG self.play = self.getButton(gtk.STOCK_MEDIA_PLAY, size) self.pause = self.getButton(gtk.STOCK_MEDIA_PAUSE, size) - self.pack_start(self.play, False) - self.pack_start(self.pause, False) - - self.pause.show() self.play.show() self.show() + ocarina.events.invite("ocarina-play", self.play.hide) + ocarina.events.invite("ocarina-play", self.pause.show) + ocarina.events.invite("ocarina-pause",self.play.show) + ocarina.events.invite("ocarina-pause",self.pause.hide) + def getButton(self,stock,size): - img = gtk.Image() - img.show() - img.set_from_stock(stock,size) + img = gtk.image_new_from_stock(stock,size) button = gtk.Button() button.add(img) + img.show() + button.connect("clicked",self.onclick) + self.pack_start(button, False) return button + def onclick(self,button): + if button == self.play: + cmd.run("play") + else: + cmd.run("pause") + + def make_playbutton(attrs=None):return PlayButton(attrs) guibuilder.parts["playbutton"] = make_playbutton \ No newline at end of file diff --git a/src/extra/oGtk/progbar.py b/src/extra/oGtk/progbar.py new file mode 100644 index 00000000..8336ff52 --- /dev/null +++ b/src/extra/oGtk/progbar.py @@ -0,0 +1,47 @@ +#! /usr/bin/python + +# To change this template, choose Tools | Templates +# and open the template in the editor. + +__author__="bjschuma" +__date__ ="$Mar 16, 2010 6:17:38 PM$" + + +import gtk +import gobject + +import guibuilder +import gstreamer +from et import times + +class ProgressBar(gtk.EventBox): + def __init__(self): + gtk.EventBox.__init__(self) + self.bar = gtk.ProgressBar() + self.bar.set_fraction(0) + + self.connect("button_release_event",self.clicked) + gobject.timeout_add(500,self.updatebar) + + self.add(self.bar) + self.bar.show() + self.show() + + + def clicked(self,widgit,data): + if data.button == 1: + prcnt = float(data.x) / float(self.bar.get_allocation()[2]) + self.bar.set_fraction(prcnt) + gstreamer.seek(prcnt) + + + def updatebar(self): + self.bar.set_fraction(gstreamer.getProgress()) + current = times.ftime(gstreamer.currentpos()) + duration = times.ftime(gstreamer.duration()) + self.bar.set_text(current + " / " + duration) + return True + + +def make_progbar(attrs):return ProgressBar() +guibuilder.parts["progbar"] = make_progbar \ No newline at end of file diff --git a/src/extra/ocarina-extra.py b/src/extra/ocarina-extra.py index b4f85570..09cfb68b 100644 --- a/src/extra/ocarina-extra.py +++ b/src/extra/ocarina-extra.py @@ -20,6 +20,8 @@ import guibuilder from oGtk import * import gtk +import gobject +gobject.threads_init() def main(): diff --git a/src/simple.xml b/src/simple.xml index 24cdd373..7f4d92a3 100644 --- a/src/simple.xml +++ b/src/simple.xml @@ -1,13 +1,10 @@ - + - -