1
0
mirror of https://github.com/gryf/wmdocklib.git synced 2025-12-18 20:10:23 +01:00

1714519 - object oriented library

first working version...
it gives very little feedback about the running player.
This commit is contained in:
mfrasca
2007-05-15 15:14:24 +00:00
parent b34c324414
commit 5f5dfd16cf
2 changed files with 131 additions and 35 deletions

View File

@@ -11,42 +11,101 @@ Licensed under the GNU General Public License.
import sys, time
from wmdocklib import wmoo
devnull = file('/dev/null')
debug = 0
class Application(wmoo.Application):
def printevent(event):
print event
def __init__(self, *args, **kwargs):
wmoo.Application.__init__(self, *args, **kwargs)
self.child = None
self.cache = '64'
self.radioList = []
self.currentRadio = 0
self._blink = 0
def previousRadio(event):
print 'previousRadio', event
import fileinput, os
configfile = os.sep.join([os.environ['HOME'], '.pyradiorc'])
def nextRadio(event):
print 'nextRadio', event
for i in fileinput.input(configfile):
i = i.split('\n')[0]
radiodef = i.split('\t')
radioname = radiodef[0].lower()
if len(radiodef) == 1:
continue
if radioname == '':
globals()[radiodef[1]] = radiodef[2]
pass
else:
self.radioList.append( (radioname+' '*24, radiodef[1]) )
def quitProgram(event):
print 'quitProgram', event
sys.exit(0)
def startPlayer(self):
import os, subprocess
commandline = [mplayer,
'-cache', self.cache,
self.radioList[self.currentRadio][1]
]
self.child = subprocess.Popen(commandline,
stdout=devnull,
stderr=devnull)
def playStream(event):
print 'playStream', event
def stopPlayer(self):
if self.child:
import os, subprocess, signal
os.kill(self.child.pid, signal.SIGKILL)
self.child = None
return True
return False
def stopStream(event):
print 'stopStream', event
def quitProgram(self, event):
self.stopPlayer()
sys.exit(0)
def printevent(self, event):
print event
def previousRadio(self, event):
if self.currentRadio == 0: self.currentRadio = len(self.radioList)
self.currentRadio -= 1
self.putString(0, 10, self.radioList[self.currentRadio][0])
if self.stopPlayer():
self.startPlayer()
def nextRadio(self, event):
self.currentRadio += 1
if self.currentRadio == len(self.radioList): self.currentRadio = 0
self.putString(0, 10, self.radioList[self.currentRadio][0])
if self.stopPlayer():
self.startPlayer()
def playStream(self, event):
self.startPlayer()
def stopStream(self, event):
self.stopPlayer()
self.putPattern(9, 0, 9, 11, 38, 43)
def blink(self):
self._blink += 1
if self._blink == 10:
self.putPattern(0, 0, 9, 11, 38, 43)
elif self._blink == 20:
self._blink = 0
self.putPattern(9, 0, 9, 11, 38, 43)
pass
def update(self):
if self.child:
self.blink()
palette = {
'-': "#000000",
".": "#868682",
"X": "#AEAEAA",
"o": "#F7F7F3",
"r": "#F70000",
}
patterns = [
" ",
" ",
" ",
" ",
" ",
" ",
background = [
" ",
" ",
" ",
@@ -65,11 +124,17 @@ patterns = [
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
" ",
" ",
" ",
" ",
" ",
" XXXXXXXX. XXXXXXXX. XXXXXXXX. ",
" X-------- X-------- X-------- ",
" X-------- X-------- X-------- ",
@@ -107,27 +172,41 @@ patterns = [
" ",
]
patterns = [
"XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX. ",
"X--------X--------X--------X--------X--------X-------- ",
"X--------X--------X--------X--------X--------X-------- ",
"X-rrrrr--X-ooooo--X-rr-rr--X-oo-oo--X--o-----X--r----- ",
"X-rrrrr--X-ooooo--X-rr-rr--X-oo-oo--X--oo----X--rr---- ",
"X-rrrrr--X-ooooo--X-rr-rr--X-oo-oo--X--ooo---X--rrr--- ",
"X-rrrrr--X-ooooo--X-rr-rr--X-oo-oo--X--oo----X--rr---- ",
"X-rrrrr--X-ooooo--X-rr-rr--X-oo-oo--X--o-----X--r----- ",
"X--------X--------X--------X--------X--------X-------- ",
"X--------X--------X--------X--------X--------X-------- ",
".--------.--------.--------.--------.--------.-------- ",
]
def main():
global char_width, char_height, maxCharsPerLine, antialiased
app = wmoo.Application(font_name='5x8',
margin = 3,
bg=0, fg=2, palette=palette,
background=patterns,
debug=debug)
app = Application(font_name='5x8',
margin = 3,
bg=0, fg=2, palette = palette,
background = background,
patterns = patterns)
# maxCharsPerLine = (width-2*xOffset) / char width
app.putString(0, 10, app.radioList[app.currentRadio][0])
app.addCallback(printevent)
# app.addCallback(printevent)
app.addCallback(previousRadio, 'buttonrelease', area=(14,29,23,38))
app.addCallback(nextRadio, 'buttonrelease', area=(26,29,35,38))
app.addCallback(quitProgram, 'buttonrelease', area=(38,29,47,38), key=1)
app.addCallback(app.previousRadio, 'buttonrelease', area=(14,29,23,38))
app.addCallback(app.nextRadio, 'buttonrelease', area=(26,29,35,38))
app.addCallback(app.quitProgram, 'buttonrelease', area=(38,29,47,38), key=1)
app.addCallback(playStream, 'buttonrelease', area=(14,43,23,52))
app.addCallback(stopStream, 'buttonrelease', area=(26,43,35,52))
app.addCallback(stopStream, 'buttonrelease', area=(38,43,47,52))
app.addCallback(app.playStream, 'buttonrelease', area=(14,43,23,52))
app.addCallback(app.stopStream, 'buttonrelease', area=(26,43,35,52))
app.addCallback(app.stopStream, 'buttonrelease', area=(38,43,47,52))
app.run()

View File

@@ -16,11 +16,28 @@ class Application:
"""
self._events = []
self._sleep = 0.1
self._offset_x = self._offset_y = 3
pywmhelpers.initPixmap(*args, **kwargs)
self._char_width, self._char_height = pywmhelpers.initPixmap(*args, **kwargs)
pywmhelpers.openXwindow(sys.argv, 64, 64)
pass
def putString(self, x, y, string):
pywmhelpers.addString(string, x, y,
self._offset_x, self._offset_y,
self._char_width, self._char_height)
def putPattern(self, sourceX, sourceY, width, height, targetX, targetY):
pywmhelpers.copyXPMArea(sourceX, sourceY+64, width, height,
targetX, targetY)
def update(self):
pass
def redraw(self):
self.update()
pywmhelpers.redraw()
def addHandler(self):
"""adds a signal handler.
@@ -67,7 +84,7 @@ class Application:
callback(event)
event = pywmhelpers.getEvent()
pywmhelpers.redraw()
self.redraw()
time.sleep(self._sleep)
pass