libsaria: Began implementing better callback system
The event system was evil, hard to use, and hard to follow. This patch is the beginning of a new, more straightforward system.
This commit is contained in:
parent
6855fb6b2d
commit
b562fff0ed
|
@ -1,8 +1,10 @@
|
||||||
# Bryan Schumake (8/7/2010)
|
# Bryan Schumake (8/7/2010)
|
||||||
|
|
||||||
|
import gst
|
||||||
import datetime
|
import datetime
|
||||||
import threading
|
import threading
|
||||||
import pipeline
|
import pipeline
|
||||||
|
from libsaria import callbacks
|
||||||
|
|
||||||
timedelta = datetime.timedelta
|
timedelta = datetime.timedelta
|
||||||
audio_lock = threading.Lock()
|
audio_lock = threading.Lock()
|
||||||
|
@ -24,15 +26,15 @@ def get_state():
|
||||||
def is_playing():
|
def is_playing():
|
||||||
return get_state() == gst.STATE_PLAYING
|
return get_state() == gst.STATE_PLAYING
|
||||||
|
|
||||||
#def do_notify_playing():
|
def do_notify_playing():
|
||||||
# if get_state() == gst.STATE_PLAYING:
|
if get_state() == gst.STATE_PLAYING:
|
||||||
# callback.play()
|
callbacks.play()
|
||||||
|
|
||||||
def play():
|
def play():
|
||||||
lock_audio()
|
lock_audio()
|
||||||
pipeline.play()
|
pipeline.play()
|
||||||
unlock_audio()
|
unlock_audio()
|
||||||
#do_notify_playing()
|
do_notify_playing()
|
||||||
|
|
||||||
#def do_notify_paused():
|
#def do_notify_paused():
|
||||||
# if get_state() == gst.STATE_PAUSED:
|
# if get_state() == gst.STATE_PAUSED:
|
||||||
|
|
8
libsaria/callbacks.py
Normal file
8
libsaria/callbacks.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Bryan Schumaker (4 / 30 / 2011)
|
||||||
|
|
||||||
|
def null_cb(*args):
|
||||||
|
pass
|
||||||
|
|
||||||
|
on_play = null_cb
|
||||||
|
def play():
|
||||||
|
on_play()
|
|
@ -62,7 +62,7 @@ def next():
|
||||||
return call("NEXT", pick_next)
|
return call("NEXT", pick_next)
|
||||||
|
|
||||||
def play():
|
def play():
|
||||||
return call("PLAY", audio.play)
|
audio.play()
|
||||||
|
|
||||||
def pause():
|
def pause():
|
||||||
return call("PAUSE", audio.pause)
|
return call("PAUSE", audio.pause)
|
||||||
|
|
|
@ -15,7 +15,9 @@ class BG_Thread(Thread):
|
||||||
self.func = func
|
self.func = func
|
||||||
self.args = args
|
self.args = args
|
||||||
def run(self):
|
def run(self):
|
||||||
|
print "running func %s with args %s" % (self.func, self.args)
|
||||||
self.func(*self.args)
|
self.func(*self.args)
|
||||||
|
print "exiting func %s" % self.func
|
||||||
|
|
||||||
|
|
||||||
def background(func, *args):
|
def background(func, *args):
|
||||||
|
|
|
@ -6,11 +6,11 @@ __start__ = now()
|
||||||
|
|
||||||
import gtk
|
import gtk
|
||||||
import gobject
|
import gobject
|
||||||
import libsaria
|
|
||||||
|
|
||||||
__vers__ = "Ocarina %s" % libsaria.__vstr__
|
|
||||||
gobject.threads_init()
|
gobject.threads_init()
|
||||||
|
|
||||||
|
import libsaria
|
||||||
|
__vers__ = "Ocarina %s" % libsaria.__vstr__
|
||||||
|
|
||||||
def uptime():
|
def uptime():
|
||||||
return now() - __start__
|
return now() - __start__
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@ def quit(window, event):
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
libsaria.shutdown()
|
libsaria.shutdown()
|
||||||
print "Ocarina ran for:", uptime()
|
print "Ocarina ran for:", uptime()
|
||||||
|
import threading
|
||||||
|
print "active threads?", threading.active_count()
|
||||||
|
|
||||||
import window
|
import window
|
||||||
import playlist
|
import playlist
|
||||||
|
|
|
@ -4,6 +4,7 @@ import libsaria
|
||||||
import queue
|
import queue
|
||||||
from ocarina import body
|
from ocarina import body
|
||||||
from ocarina.body import footer
|
from ocarina.body import footer
|
||||||
|
from libsaria import callbacks
|
||||||
import playlist
|
import playlist
|
||||||
import library
|
import library
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ invite = libsaria.event.invite
|
||||||
|
|
||||||
def on_play(*args):
|
def on_play(*args):
|
||||||
footer.on_play()
|
footer.on_play()
|
||||||
invite("POSTPLAY", on_play)
|
callbacks.on_play = on_play
|
||||||
|
|
||||||
def on_pause(*args):
|
def on_pause(*args):
|
||||||
footer.on_pause()
|
footer.on_pause()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user