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:
16
examples/pywmoonop.py
Executable file
16
examples/pywmoonop.py
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""pywmoonop.py
|
||||
|
||||
object oriented WindowMaker dockapp doing nothing
|
||||
|
||||
Copyright (C) 2007 Mario Frasca
|
||||
|
||||
Licensed under the GNU General Public License.
|
||||
"""
|
||||
|
||||
from wmdocklib import wmoo
|
||||
thisapp = wmoo.Application()
|
||||
|
||||
if __name__ == '__main__':
|
||||
thisapp.run()
|
||||
@@ -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.addCallback(printevent)
|
||||
|
||||
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(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()
|
||||
|
||||
|
||||
73
wmdocklib/wmoo.py
Normal file
73
wmdocklib/wmoo.py
Normal file
@@ -0,0 +1,73 @@
|
||||
import sys, time
|
||||
import pywmhelpers
|
||||
|
||||
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 = []
|
||||
self._sleep = 0.1
|
||||
|
||||
pywmhelpers.initPixmap(*args, **kwargs)
|
||||
pywmhelpers.openXwindow(sys.argv, 64, 64)
|
||||
pass
|
||||
|
||||
def addHandler(self):
|
||||
"""adds a signal handler.
|
||||
|
||||
if the application receives the signal, the handler is called.
|
||||
|
||||
notice that the operating system does not know 'permanent' handlers,
|
||||
handlers are called once and that is it. the addHandler function
|
||||
takes care that the call is repeated each time the signal is
|
||||
received (repeated signals received during the handling of the
|
||||
previous signal will be lost, though).
|
||||
"""
|
||||
pass
|
||||
|
||||
def addCallback(self, callback, type=None, key=None, area=None ):
|
||||
"""the callback will be called during the eventLoop if the event
|
||||
matches the requirements on the type of the event, the key and the
|
||||
area where the event took place. remind that events are mostly
|
||||
mouse or keyboard event. all fields may be left to their 'None'
|
||||
default value, in which case the callback is activated on any event.
|
||||
"""
|
||||
if area is not None and len(area) is not 4:
|
||||
area = None
|
||||
self._events.append( (type, key, area, callback,) )
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
"""this contains the eventLoop. events are examined and if a
|
||||
callback has been registered, it is called, passing it the event as
|
||||
argument.
|
||||
"""
|
||||
while 1:
|
||||
event = pywmhelpers.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['button']: 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 = pywmhelpers.getEvent()
|
||||
pywmhelpers.redraw()
|
||||
time.sleep(self._sleep)
|
||||
|
||||
pass
|
||||
Reference in New Issue
Block a user