mirror of
https://github.com/gryf/wmdocklib.git
synced 2025-12-19 12:28:10 +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
|
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.
|
Licensed under the GNU General Public License.
|
||||||
|
|
||||||
@@ -12,84 +12,31 @@ Licensed under the GNU General Public License.
|
|||||||
Changes:
|
Changes:
|
||||||
2006-10-27 Mario Frasca
|
2006-10-27 Mario Frasca
|
||||||
First workingish version
|
First workingish version
|
||||||
"""
|
|
||||||
usage = """pywmphoto.py [options]
|
2007-05-19 Mario Frasca
|
||||||
Available options are:
|
more compact form, based on wmdocklib.wmoo and optparse.
|
||||||
-h, --help print this help
|
|
||||||
-f, --file <file> set the xpm name
|
|
||||||
--debug shows the pixmap
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os, time
|
from wmdocklib import wmoo
|
||||||
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)
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
clConfig = parseCommandLine(sys.argv)
|
|
||||||
|
|
||||||
# openXwindow sets the window title to the program name. If we get the
|
from optparse import OptionParser
|
||||||
# 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
|
|
||||||
|
|
||||||
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')
|
app = wmoo.Application(background = options.filename,
|
||||||
|
margin = 3,
|
||||||
|
debug = options.debug)
|
||||||
|
|
||||||
global char_width, char_height, maxCharsPerLine, antialiased
|
app.run()
|
||||||
wmdocklib.initPixmap(palette=palette,
|
|
||||||
patterns=patterns,
|
|
||||||
margin=3,
|
|
||||||
debug=debug)
|
|
||||||
|
|
||||||
wmdocklib.openXwindow(sys.argv, 64, 64)
|
|
||||||
wmdocklib.copyXPMArea(0, 64, 58, 58, 3, 3)
|
|
||||||
|
|
||||||
mainLoop()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
@@ -207,6 +207,11 @@ def initPixmap(background=None,
|
|||||||
'gray41', 'blue1', 'green1', 'cyan1',
|
'gray41', 'blue1', 'green1', 'cyan1',
|
||||||
'red1', 'magenta1', 'yellow1', 'white']
|
'red1', 'magenta1', 'yellow1', 'white']
|
||||||
|
|
||||||
|
if isinstance(patterns, str):
|
||||||
|
palette, patterns = readXPM(patterns)
|
||||||
|
if isinstance(background, str):
|
||||||
|
palette, background = readXPM(background)
|
||||||
|
|
||||||
alter_palette, palette = palette, {}
|
alter_palette, palette = palette, {}
|
||||||
for name, index in zip(basic_colors, range(16)):
|
for name, index in zip(basic_colors, range(16)):
|
||||||
palette['%x'%index] = getColorCode(name)
|
palette['%x'%index] = getColorCode(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user