Made more new gui elements, including progress bars and play/pause

buttons
This commit is contained in:
bjschuma 2010-03-16 19:54:04 -04:00
parent 9d27a0de0f
commit 36f95d7736
9 changed files with 160 additions and 21 deletions

View File

@ -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)

View File

@ -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):

View File

@ -1,4 +1,4 @@
__author__="bjschuma"
__date__ ="$Mar 14, 2010 9:53:12 PM$"
__all__ = ["xm"]
__all__ = ["times", "xm"]

34
src/extra/et/times.py Normal file
View File

@ -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

View File

@ -2,4 +2,4 @@ __author__="bjschuma"
__date__ ="$Mar 14, 2010 10:21:40 PM$"
__all__ = ["box", "button", "label", "playButton", "songInfo", "window"]
__all__ = ["box", "button", "label", "playButton", "progbar", "songInfo", "window"]

View File

@ -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

47
src/extra/oGtk/progbar.py Normal file
View File

@ -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

View File

@ -20,6 +20,8 @@ import guibuilder
from oGtk import *
import gtk
import gobject
gobject.threads_init()
def main():

View File

@ -1,13 +1,10 @@
<?xml version="1.0" ?>
<window width="400" height="300" close="ocarina-stop" title="Ocarina 3.0">
<window width="400" height="150" close="ocarina-stop" title="Ocarina 3.0">
<add>
<vbox>
<songinfo/>
<playbutton size="large"/>
<hbox>
<button relief="none" text="gtk.STOCK_MEDIA_PLAY" cmd="play" show="ocarina-pause" hide="ocarina-play" stock="True"/>
<button relief="none" text="Pause" cmd="pause" show="ocarina-play" hide="ocarina-pause" hidden="true"/>
</hbox>
<progbar/>
</vbox>
</add>
</window>