mirror of
https://github.com/gryf/wmdocklib.git
synced 2025-12-18 20:10:23 +01:00
1714519: object oriented library
example pywmphoto rewritten. modified initializer of pixmap: you can give the name of the pixmap containing the background/patterns, so you do not need reading it in advance.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
WindowMaker dockapp that displays a static xpm
|
||||
|
||||
Copyright (C) 2006 Mario Frasca
|
||||
Copyright (C) 2006-2007 Mario Frasca
|
||||
|
||||
Licensed under the GNU General Public License.
|
||||
|
||||
@@ -12,84 +12,31 @@ Licensed under the GNU General Public License.
|
||||
Changes:
|
||||
2006-10-27 Mario Frasca
|
||||
First workingish version
|
||||
"""
|
||||
usage = """pywmphoto.py [options]
|
||||
Available options are:
|
||||
-h, --help print this help
|
||||
-f, --file <file> set the xpm name
|
||||
--debug shows the pixmap
|
||||
|
||||
2007-05-19 Mario Frasca
|
||||
more compact form, based on wmdocklib.wmoo and optparse.
|
||||
"""
|
||||
|
||||
import sys, os, time
|
||||
import getopt
|
||||
|
||||
import wmdocklib
|
||||
|
||||
def parseCommandLine(argv):
|
||||
"""Parse the commandline. Return a dictionary with options and values."""
|
||||
shorts = 'hf:'
|
||||
longs = ['help', 'file=', 'debug',
|
||||
]
|
||||
try:
|
||||
opts, nonOptArgs = getopt.getopt(argv[1:], shorts, longs)
|
||||
except getopt.GetoptError, e:
|
||||
sys.stderr.write('Error when parsing commandline: ' + str(e) + '\n')
|
||||
sys.stderr.write(usage)
|
||||
sys.exit(2)
|
||||
d = {}
|
||||
|
||||
for o, a in opts:
|
||||
if o in ('-h', '--help'):
|
||||
sys.stdout.write(usage)
|
||||
sys.exit(0)
|
||||
if o in ('-f', '--file'):
|
||||
d['file'] = a
|
||||
if o in ('--debug'):
|
||||
d['debug'] = True
|
||||
return d
|
||||
|
||||
def checkForEvents():
|
||||
event = wmdocklib.getEvent()
|
||||
while not event is None:
|
||||
if event['type'] == 'destroynotify':
|
||||
sys.exit(0)
|
||||
event = wmdocklib.getEvent()
|
||||
|
||||
def mainLoop():
|
||||
while 1:
|
||||
checkForEvents()
|
||||
wmdocklib.redraw()
|
||||
time.sleep(0.5)
|
||||
from wmdocklib import wmoo
|
||||
|
||||
def main():
|
||||
clConfig = parseCommandLine(sys.argv)
|
||||
|
||||
# openXwindow sets the window title to the program name. If we get the
|
||||
# program name with a path, split it so we only name the window with the
|
||||
# filename.
|
||||
try:
|
||||
programName = sys.argv[0].split(os.sep)[-1]
|
||||
except IndexError: # Should only happen when using the interpreter.
|
||||
programName = ''
|
||||
sys.argv[0] = programName
|
||||
from optparse import OptionParser
|
||||
|
||||
xpmName = clConfig.get('file')
|
||||
parser = OptionParser()
|
||||
parser.add_option("-f", "--file", dest="filename",
|
||||
help="read background from file", metavar="FILE")
|
||||
parser.add_option("-d", "--debug", dest="debug",
|
||||
action="store_true", default=False,
|
||||
help="print the pixmap")
|
||||
|
||||
palette, patterns = wmdocklib.readXPM(xpmName)
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
debug = clConfig.get('debug')
|
||||
|
||||
global char_width, char_height, maxCharsPerLine, antialiased
|
||||
wmdocklib.initPixmap(palette=palette,
|
||||
patterns=patterns,
|
||||
margin=3,
|
||||
debug=debug)
|
||||
app = wmoo.Application(background = options.filename,
|
||||
margin = 3,
|
||||
debug = options.debug)
|
||||
|
||||
wmdocklib.openXwindow(sys.argv, 64, 64)
|
||||
wmdocklib.copyXPMArea(0, 64, 58, 58, 3, 3)
|
||||
|
||||
mainLoop()
|
||||
app.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
@@ -207,6 +207,11 @@ def initPixmap(background=None,
|
||||
'gray41', 'blue1', 'green1', 'cyan1',
|
||||
'red1', 'magenta1', 'yellow1', 'white']
|
||||
|
||||
if isinstance(patterns, str):
|
||||
palette, patterns = readXPM(patterns)
|
||||
if isinstance(background, str):
|
||||
palette, background = readXPM(background)
|
||||
|
||||
alter_palette, palette = palette, {}
|
||||
for name, index in zip(basic_colors, range(16)):
|
||||
palette['%x'%index] = getColorCode(name)
|
||||
|
||||
Reference in New Issue
Block a user