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

1714519 - object oriented library

separated the library part from the application part.
added wmoo module.
added pywmoonop (object oriented form of the empty dock).
This commit is contained in:
mfrasca
2007-05-15 07:31:09 +00:00
parent 844eecc535
commit b34c324414
3 changed files with 113 additions and 67 deletions

View File

@@ -10,55 +10,10 @@ Licensed under the GNU General Public License.
"""
import sys, time
import wmdocklib
from wmdocklib import wmoo
debug = 0
class Application:
def __init__(self, *args, **kwargs):
"""initializes the object
_events is a list of tuples (type, key, area, callback)
'type' <- ['buttonpress', 'buttonrelease', 'keypress'],
'callback': the function to which the event should be passed.
'key': the utf-8 character or the mouse button number,
'area': if the pointer is here, the event is considered,
"""
self._events = []
wmdocklib.initPixmap(*args, **kwargs)
wmdocklib.openXwindow(sys.argv, 64, 64)
pass
def addHandler(self, callback, type=None, key=None, area=None ):
if area is not None and len(area) is not 4:
area = None
self._events.append( (type, key, area, callback,) )
pass
def run(self):
while 1:
event = wmdocklib.getEvent()
while not event is None:
if event['type'] == 'destroynotify':
sys.exit(0)
for evtype, key, area, callback in self._events:
if evtype is not None and evtype != event['type']: continue
if key is not None and key != event['key']: continue
if area is not None:
if not area[0] <= event['x'] <= area[2]: continue
if not area[1] <= event['y'] <= area[3]: continue
callback(event)
event = wmdocklib.getEvent()
wmdocklib.redraw()
time.sleep(0.5)
pass
def printevent(event):
print event
@@ -102,15 +57,15 @@ patterns = [
" ",
" ",
" ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" X-------------------------------------------X ",
" X-------------------------------------------X ",
" X-------------------------------------------X ",
" X-------------------------------------------X ",
" X-------------------------------------------X ",
" X-------------------------------------------X ",
" X-------------------------------------------X ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"----------------------------------------------------------------",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
" ",
" ",
" ",
@@ -157,20 +112,22 @@ patterns = [
def main():
global char_width, char_height, maxCharsPerLine, antialiased
app = Application(font_name='5x8',
margin = 3,
bg=0, fg=2, palette=palette,
background=patterns,
debug=debug)
app = wmoo.Application(font_name='5x8',
margin = 3,
bg=0, fg=2, palette=palette,
background=patterns,
debug=debug)
# maxCharsPerLine = (width-2*xOffset) / char width
app.addHandler(previousRadio, 'buttonrelease', area=(14,29,23,38))
app.addHandler(nextRadio, 'buttonrelease', area=(26,29,35,38))
app.addHandler(quitProgram, 'buttonrelease', area=(38,29,47,38))
app.addHandler(playStream, 'buttonrelease', area=(14,43,23,52))
app.addHandler(stopStream, 'buttonrelease', area=(26,43,35,52))
app.addHandler(stopStream, 'buttonrelease', area=(38,43,47,52))
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(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.run()