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

1723251: it is too difficult to move a button

I've added the two methods addButton and setButtonPattern to the Application class.

the area in the background has to be paintable, not transparent, or the
button will not be displayed nor be sensitive.

patterns are taken from the application and are not stored with the button.

it might be a good idea to introduce an object hierarchy for widgets,
including Labels and Buttons, maybe also flashing buttons, but as far as the
application programmer (of things like the current examples) is concerned,
this is good enough, I'd say.
This commit is contained in:
mfrasca
2007-05-22 08:11:57 +00:00
parent f941df25af
commit 40f0474ce2
2 changed files with 120 additions and 74 deletions

View File

@@ -58,7 +58,6 @@ class Application(wmoo.Application):
def handler(self, num, frame): def handler(self, num, frame):
if self._expectdying: if self._expectdying:
print self._expectdying
self._expectdying -= 1 self._expectdying -= 1
else: else:
self.reset() self.reset()
@@ -89,21 +88,15 @@ class Application(wmoo.Application):
def stopPlayer(self): def stopPlayer(self):
if self.child: if self.child:
print self._expectdying
self.child.stdin.write('q') self.child.stdin.write('q')
self._expectdying += 1 self._expectdying += 1
self.child = None self.child = None
def muteStream(self, event):
if self.child and self._buffering == 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
def previousRadio(self, event): def previousRadio(self, event):
print 'in previousRadio'
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.setLabelText('name', self.radioList[self.currentRadio][0]) self.setLabelText('name', self.radioList[self.currentRadio][0])
@@ -112,6 +105,7 @@ class Application(wmoo.Application):
self.startPlayer() self.startPlayer()
def nextRadio(self, event): def nextRadio(self, event):
print 'in nextRadio'
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.setLabelText('name', self.radioList[self.currentRadio][0]) self.setLabelText('name', self.radioList[self.currentRadio][0])
@@ -120,13 +114,16 @@ class Application(wmoo.Application):
self.startPlayer() self.startPlayer()
def playStream(self, event): def playStream(self, event):
print 'in playStream'
self.startPlayer() self.startPlayer()
def stopStream(self, event): def stopStream(self, event):
print 'in stopStream'
self.stopPlayer() self.stopPlayer()
self.reset() self.reset()
def pauseStream(self, event): def pauseStream(self, event):
print 'in pauseStream'
if self.child and not self._buffering: 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
@@ -135,6 +132,13 @@ class Application(wmoo.Application):
return True return True
return False return False
def muteStream(self, event):
print 'in muteStream'
if self.child and self._buffering == 0:
self.child.stdin.write('m')
self.setButtonPattern('mute', (33-11*self._muting, 0))
self._muting = 1 - self._muting
def showCacheLevel(self): def showCacheLevel(self):
if self._buffering: if self._buffering:
self._cacheLevel += 1 self._cacheLevel += 1
@@ -142,9 +146,9 @@ class Application(wmoo.Application):
self._cacheLevel -= 25 self._cacheLevel -= 25
for i in range(-1, 25): for i in range(-1, 25):
if abs(i - self._cacheLevel) <= 1: if abs(i - self._cacheLevel) <= 1:
self.putPattern(54, self._buffering, 3, 1, 52, 54-i) self.putPattern(54, self._buffering, 5, 1, 54, 58-i)
else: else:
self.putPattern(54, 0, 3, 1, 52, 54-i) self.putPattern(54, 0, 5, 1, 54, 58-i)
else: else:
if self._paused or self._flash: if self._paused or self._flash:
colour = self._colour = 3 - self._colour colour = self._colour = 3 - self._colour
@@ -153,9 +157,9 @@ class Application(wmoo.Application):
colour = 2 colour = 2
for i in range(-1, 25): for i in range(-1, 25):
if (i*4 < self._cacheLevel) or self._flash: if (i*4 < self._cacheLevel) or self._flash:
self.putPattern(54, colour, 3, 1, 52, 54-i) self.putPattern(54, colour, 5, 1, 54, 58-i)
else: else:
self.putPattern(54, 0, 3, 1, 52, 54-i) self.putPattern(54, 0, 5, 1, 54, 58-i)
def update(self): def update(self):
wmoo.Application.update(self) wmoo.Application.update(self)
@@ -206,55 +210,55 @@ background = [
" ", " ",
" ", " ",
" ", " ",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
" ", " ",
" ", " ",
" ", " ",
" ", " ",
" XXXX. ", " ",
" XXXXXXXX. XXXXXXXX. XXXXXXXX. X--- ", " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" X-------- X-------- X-------- X--- ", " X----------------------------------------------------------X ",
" X-------- X-------- X-----o-- X--- ", " X----------------------------------------------------------X ",
" X--o--o-- X--o--o-- X----oo-- X--- ", " X----------------------------------------------------------X ",
" X--o-oo-- X--oo-o-- X-ooooo-- X--- ", " X----------------------------------------------------------X ",
" X--oooo-- X--oooo-- X-ooooo-- X--- ", " X----------------------------------------------------------X ",
" X--o-oo-- X--oo-o-- X----oo-- X--- ", " X----------------------------------------------------------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--- ", " X----------------------------------------------------------X ",
" X--- ", " X----------------------------------------------------------X ",
" X.---.. ", " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXX. XXXXXXXX. XXXXXXXX. X--- ",
" X-------- X-------- X-------- X--- ",
" X-------- X-------- X-------- X--- ",
" X--o----- X-oo-oo-- X-ooooo-- X--- ",
" X--oo---- X-oo-oo-- X-ooooo-- X--- ",
" X--ooo--- X-oo-oo-- X-ooooo-- X--- ",
" X--oo---- X-oo-oo-- X-ooooo-- X--- ",
" X--o----- X-oo-oo-- X-ooooo-- X--- ",
" X-------- X-------- X-------- X--- ",
" X-------- X-------- X-------- X--- ",
" .-------- .-------- .-------- X--- ",
" X--- ",
" .--- ",
" ",
" ", " ",
" ", " ",
" ............ ............ ............ XXXXXX. ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" X----- ",
" X----- ",
" X.-----.. ",
" X----- ",
" ............ ............ ............ X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... X----- ",
" ........... ........... ........... .----- ",
" ", " ",
" ", " ",
" ", " ",
@@ -263,17 +267,30 @@ background = [
] ]
patterns = [ patterns = [
"XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.XXXXXXXX.--- ", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ----- ",
"X--------X--------X--------X--------X--------X--------rrr ", "X----------X----------X----------X---------- rrrrr ",
"X-----rr-X-----o--X-----o--X--------X--------X--------iii ", "X----------X----------X------oo--X------oor- iiiii ",
"X----rr--X----oo--X----oo--X-oo-oo--X--o-----X--r----- ", "X--o---o---X--o---o---X-----ooo--X-----oorr- ",
"X-oorro--X-ooooo--X-ooooo--X-oo-oo--X--oo----X--rr---- ", "X--o--oo---X--oo--o---X----oooo--X----oorr-- ",
"X-ooroo--X-ooooo--X-ooooo--X-oo-oo--X--ooo---X--rrr--- ", "X--o-ooo---X--ooo-o---X-ooXoooo--X-ooXorro-- ",
"X--rroo--X----oo--X----oo--X-oo-oo--X--oo----X--rr---- ", "X--ooooo---X--ooooo---X-ooXoooo--X-ooXrroo-- ",
"X-rr--o--X-----o--X-----o--X-oo-oo--X--o-----X--r----- ", "X--o-ooo---X--ooo-o---X-ooXoooo--X-oorrooo-- ",
"X- ------X--------X--------X--------X--------X-------- ", "X--o--oo---X--oo--o---X----oooo--X--rroooo-- ",
"X--------X--------X--------X--------X--------X-------- ", "X--o---o---X--o---o---X-----ooo--X-rr--ooo-- ",
".--------.--------.--------.--------.--------.-------- ", "X----------X----------X------oo--X-r----oo-- ",
".----------.----------.----------X---------- ",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
"X----------X----------X---------- ",
"X----------X----------X---------- ",
"X--oo------X--oo-oo---X--oooooo-- ",
"X--ooo-----X--oo-oo---X--oooooo-- ",
"X--oooo----X--oo-oo---X--oooooo-- ",
"X--ooooo---X--oo-oo---X--oooooo-- ",
"X--oooo----X--oo-oo---X--oooooo-- ",
"X--ooo-----X--oo-oo---X--oooooo-- ",
"X--oo------X--oo-oo---X--oooooo-- ",
"X----------X----------X---------- ",
".---------------------.---------- ",
] ]
@@ -286,17 +303,16 @@ def main():
background = background, background = background,
patterns = patterns) patterns = patterns)
# maxCharsPerLine = (width-2*xOffset) / char width # maxCharsPerLine = (width-2*xOffset) / char width
app.addLabel('name', (3, 13), (58, 10), app.radioList[app.currentRadio][0]) app.addLabel('name', (5, 18), (54, 10), app.radioList[app.currentRadio][0])
# app.addCallback(printevent) # app.addCallback(printevent)
app.addButton('prev', ( 4,31), (11, 12), app.previousRadio, pattern=(0,0))
app.addButton('next', (20,31), (11, 12), app.nextRadio, pattern=(11,0))
app.addButton('mute', (36,31), (11, 12), app.muteStream, pattern=(22,0))
app.addCallback(app.previousRadio, 'buttonrelease', area=( 6,29,15,38)) app.addButton('play', ( 4,47), (11, 12), app.playStream, pattern=(0,12))
app.addCallback(app.nextRadio, 'buttonrelease', area=(18,29,27,38)) app.addButton('pause', (20,47), (11, 12), app.pauseStream, pattern=(11,12))
app.addCallback(app.muteStream, 'buttonrelease', area=(30,29,39,38)) app.addButton('stop', (36,47), (11, 12), app.stopStream, pattern=(22,12))
app.addCallback(app.playStream, 'buttonrelease', area=( 6,43,15,52))
app.addCallback(app.pauseStream, 'buttonrelease', area=(18,43,27,52))
app.addCallback(app.stopStream, 'buttonrelease', area=(30,43,39,52))
app.run() app.run()

View File

@@ -15,6 +15,7 @@ class Application:
""" """
self._elements = {} self._elements = {}
self._buttons = {}
self._events = [] self._events = []
self._sleep = 0.1 self._sleep = 0.1
self._cycle = 0 self._cycle = 0
@@ -64,6 +65,35 @@ class Application:
pywmhelpers.addString(text, 0, 0, drawable=pixmap) pywmhelpers.addString(text, 0, 0, drawable=pixmap)
pixmap.xCopyAreaToWindow(0, 0, size_x, size_y, orig_x, orig_y) pixmap.xCopyAreaToWindow(0, 0, size_x, size_y, orig_x, orig_y)
def addButton(self, buttonId, orig, size,
callback1, callback2=None, callback3=None,
pattern=None):
"""adds an area sensitive to the click of the mouse buttons
the graphical appearance can be specified in the pattern or left as
in the background. in both cases, it can later be modified by
calling setButtonPattern
"""
orig_x, orig_y = orig
dx, dy = size
area = (orig_x, orig_y, orig_x + dx, orig_y + dy)
self.addCallback(callback1, 'buttonrelease', area=area)
if callback2 is not None:
self.addCallback(callback2, 'buttonrelease', area=area)
if callback3 is not None:
self.addCallback(callback3, 'buttonrelease', area=area)
self._buttons[buttonId] = (orig, size)
if pattern is not None:
self.setButtonPattern(buttonId, pattern)
def setButtonPattern(self, buttonId, patternOrig):
"""paints the pattern on top of the button
"""
(x, y), (w, h) = self._buttons[buttonId]
pywmhelpers.copyXPMArea(patternOrig[0], patternOrig[1] + 64, w, h, x, y)
def update(self): def update(self):
for labelId in self._elements: for labelId in self._elements:
(orig_x,orig_y), (size_x, size_y), width, offset, pixmap = self._elements[labelId] (orig_x,orig_y), (size_x, size_y), width, offset, pixmap = self._elements[labelId]