1
0
mirror of https://github.com/gryf/wmdocklib.git synced 2026-02-14 22:25:45 +01:00

1722440 missing 'mute' button

1722442  	  stale mplayer processes

removed the 'exit' button in favour of the 'mute' one.
no more killing of the player, but communication with it.
This commit is contained in:
mfrasca
2007-05-21 09:23:16 +00:00
parent 6971f5260e
commit f45d2f9a58

View File

@@ -15,15 +15,23 @@ devnull = file('/dev/null')
class Application(wmoo.Application): class Application(wmoo.Application):
def __init__(self, *args, **kwargs): def reset(self):
wmoo.Application.__init__(self, *args, **kwargs) self._cacheLevel = -50
self.child = None self.child = None
self._paused = None self._paused = None
self._buffering = 0
self._flash = 0
self._muting = 0
self.showCacheLevel()
def __init__(self, *args, **kwargs):
wmoo.Application.__init__(self, *args, **kwargs)
self.radioList = [] self.radioList = []
self.currentRadio = 0 self.currentRadio = 0
self._count = 0 self._count = 0
self._cacheLevel = -50 self._expectdying = 0
self._buffering = 0
self.reset()
self._buffered = '' self._buffered = ''
import re import re
@@ -39,23 +47,23 @@ class Application(wmoo.Application):
for i in t.split(u'\n'): for i in t.split(u'\n'):
radiodef = i.split('\t') radiodef = i.split('\t')
radioname = radiodef[0].lower() radioname = radiodef[0].lower()
if len(radiodef) == 1: if len(radiodef) != 3 or i[0] == '#':
continue continue
if radioname == '': if radioname == '':
globals()[radiodef[1]] = radiodef[2] globals()[radiodef[1]] = radiodef[2]
pass pass
else: else:
self.radioList.append( (radioname+' '*24, radiodef[1], radiodef[2]) ) self.radioList.append( (radioname+' '*24, radiodef[1], radiodef[2]) )
def reset(self):
self._cacheLevel = -50
self.child = None
self._paused = None
self.showCacheLevel()
def handler(self, num, frame): def handler(self, num, frame):
self.reset() if self._expectdying:
print self._expectdying
self._expectdying -= 1
else:
self.reset()
self._flash = 4
self._colour = 1
def startPlayer(self): def startPlayer(self):
import os, subprocess, signal import os, subprocess, signal
@@ -68,6 +76,7 @@ class Application(wmoo.Application):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=devnull) stderr=devnull)
signal.signal(signal.SIGCHLD, self.handler) signal.signal(signal.SIGCHLD, self.handler)
self._flash = 0
self._paused = False self._paused = False
self._buffered = '' self._buffered = ''
self._buffering = 1 self._buffering = 1
@@ -75,19 +84,21 @@ class Application(wmoo.Application):
import fcntl import fcntl
flags = fcntl.fcntl(self.child.stdout, fcntl.F_GETFL) flags = fcntl.fcntl(self.child.stdout, fcntl.F_GETFL)
fcntl.fcntl(self.child.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK) fcntl.fcntl(self.child.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
flags = fcntl.fcntl(self.child.stdin, fcntl.F_GETFL)
fcntl.fcntl(self.child.stdin, fcntl.F_SETFL, flags | os.O_NONBLOCK)
def stopPlayer(self): def stopPlayer(self):
if self.child: if self.child:
if self._buffering != 1: print self._expectdying
self.child.stdin.write('q') self.child.stdin.write('q')
import os, signal self._expectdying += 1
os.kill(self.child.pid, signal.SIGKILL) self.child = None
return True
return False
def quitProgram(self, event): def muteStream(self, event):
self.stopPlayer() if self.child and self._buffering == 0:
sys.exit(0) self.child.stdin.write('m')
self.putPattern(9*self._muting, 0, 9, 11, 30, 29)
self._muting = 1 - self._muting
def printevent(self, event): def printevent(self, event):
print event print event
@@ -96,14 +107,16 @@ class Application(wmoo.Application):
if self.currentRadio == 0: self.currentRadio = len(self.radioList) if self.currentRadio == 0: self.currentRadio = len(self.radioList)
self.currentRadio -= 1 self.currentRadio -= 1
self.putString(0, 10, self.radioList[self.currentRadio][0]) self.putString(0, 10, self.radioList[self.currentRadio][0])
if self.stopPlayer(): if self.child:
self.stopPlayer()
self.startPlayer() self.startPlayer()
def nextRadio(self, event): def nextRadio(self, event):
self.currentRadio += 1 self.currentRadio += 1
if self.currentRadio == len(self.radioList): self.currentRadio = 0 if self.currentRadio == len(self.radioList): self.currentRadio = 0
self.putString(0, 10, self.radioList[self.currentRadio][0]) self.putString(0, 10, self.radioList[self.currentRadio][0])
if self.stopPlayer(): if self.child:
self.stopPlayer()
self.startPlayer() self.startPlayer()
def playStream(self, event): def playStream(self, event):
@@ -114,7 +127,7 @@ class Application(wmoo.Application):
self.reset() self.reset()
def pauseStream(self, event): def pauseStream(self, event):
if self.child: if self.child and not self._buffering:
self.child.stdin.write(' ') self.child.stdin.write(' ')
self._paused = not self._paused self._paused = not self._paused
if self._paused: if self._paused:
@@ -133,12 +146,13 @@ class Application(wmoo.Application):
else: else:
self.putPattern(54, 0, 3, 1, 52, 54-i) self.putPattern(54, 0, 3, 1, 52, 54-i)
else: else:
if self._paused: if self._paused or self._flash:
colour = self._colour = 3 - self._colour colour = self._colour = 3 - self._colour
self._flash = max(0, self._flash - 1)
else: else:
colour = 2 colour = 2
for i in range(-1, 25): for i in range(-1, 25):
if i*4 < self._cacheLevel: if (i*4 < self._cacheLevel) or self._flash:
self.putPattern(54, colour, 3, 1, 52, 54-i) self.putPattern(54, colour, 3, 1, 52, 54-i)
else: else:
self.putPattern(54, 0, 3, 1, 52, 54-i) self.putPattern(54, 0, 3, 1, 52, 54-i)
@@ -168,12 +182,9 @@ class Application(wmoo.Application):
self._cacheLevel = float(match.group(1)) self._cacheLevel = float(match.group(1))
self._buffered = self._buffered[rpos:] self._buffered = self._buffered[rpos:]
if self.child or self._flash:
self.showCacheLevel() self.showCacheLevel()
def handler(num, frame):
hdmon.updateMonitoredPaths()
signal.alarm(10)
palette = { palette = {
'-': "#000000", '-': "#000000",
".": "#868682", ".": "#868682",
@@ -215,12 +226,12 @@ background = [
" XXXX. ", " XXXX. ",
" XXXXXXXX. XXXXXXXX. XXXXXXXX. X--- ", " XXXXXXXX. XXXXXXXX. XXXXXXXX. X--- ",
" X-------- X-------- X-------- X--- ", " X-------- X-------- X-------- X--- ",
" X-------- X-------- X-------- X--- ", " X-------- X-------- X-----o-- X--- ",
" X--o--o-- X--o--o-- X-o.-.o-- X--- ", " X--o--o-- X--o--o-- X----oo-- X--- ",
" X--o-oo-- X--oo-o-- X-.o.o.-- X--- ", " X--o-oo-- X--oo-o-- X-ooooo-- X--- ",
" X--oooo-- X--oooo-- X--.o. -- X--- ", " X--oooo-- X--oooo-- X-ooooo-- X--- ",
" X--o-oo-- X--oo-o-- X-.o.o.-- X--- ", " X--o-oo-- X--oo-o-- X----oo-- X--- ",
" X--o--o-- X--o--o-- X-o.-.o-- X--- ", " X--o--o-- X--o--o-- X-----o-- X--- ",
" X-------- X-------- X-------- X--- ", " X-------- X-------- X-------- X--- ",
" X-------- X-------- X-------- X--- ", " X-------- X-------- X-------- X--- ",
" .-------- .-------- .-------- X--- ", " .-------- .-------- .-------- X--- ",
@@ -253,13 +264,13 @@ background = [
patterns = [ patterns = [
"XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.--- ", "XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.--- ",
"X--------X--------X--------X--------X--------X--------rrr ", "X--------X--------X--------X--------X--------X--------rrr ",
"X--------X--------X--------X--------X--------X--------iii ", "X-----rr-X-----o--X-----o--X--------X--------X--------iii ",
"X-rrrrr--X-ooooo--X-rr-rr--X-oo-oo--X--o-----X--r----- ", "X----rr--X----oo--X----oo--X-oo-oo--X--o-----X--r----- ",
"X-rrrrr--X-ooooo--X-rr-rr--X-oo-oo--X--oo----X--rr---- ", "X-oorro--X-ooooo--X-ooooo--X-oo-oo--X--oo----X--rr---- ",
"X-rrrrr--X-ooooo--X-rr-rr--X-oo-oo--X--ooo---X--rrr--- ", "X-ooroo--X-ooooo--X-ooooo--X-oo-oo--X--ooo---X--rrr--- ",
"X-rrrrr--X-ooooo--X-rr-rr--X-oo-oo--X--oo----X--rr---- ", "X--rroo--X----oo--X----oo--X-oo-oo--X--oo----X--rr---- ",
"X-rrrrr--X-ooooo--X-rr-rr--X-oo-oo--X--o-----X--r----- ", "X-rr--o--X-----o--X-----o--X-oo-oo--X--o-----X--r----- ",
"X--------X--------X--------X--------X--------X-------- ", "X- ------X--------X--------X--------X--------X-------- ",
"X--------X--------X--------X--------X--------X-------- ", "X--------X--------X--------X--------X--------X-------- ",
".--------.--------.--------.--------.--------.-------- ", ".--------.--------.--------.--------.--------.-------- ",
] ]
@@ -280,7 +291,7 @@ def main():
app.addCallback(app.previousRadio, 'buttonrelease', area=( 6,29,15,38)) app.addCallback(app.previousRadio, 'buttonrelease', area=( 6,29,15,38))
app.addCallback(app.nextRadio, 'buttonrelease', area=(18,29,27,38)) app.addCallback(app.nextRadio, 'buttonrelease', area=(18,29,27,38))
app.addCallback(app.quitProgram, 'buttonrelease', area=(30,29,39,38), key=1) app.addCallback(app.muteStream, 'buttonrelease', area=(30,29,39,38))
app.addCallback(app.playStream, 'buttonrelease', area=( 6,43,15,52)) app.addCallback(app.playStream, 'buttonrelease', area=( 6,43,15,52))
app.addCallback(app.pauseStream, 'buttonrelease', area=(18,43,27,52)) app.addCallback(app.pauseStream, 'buttonrelease', area=(18,43,27,52))