From 504b2419f8f9a51cc9993f6fc7e041ba93e4f955 Mon Sep 17 00:00:00 2001 From: mfrasca <> Date: Fri, 20 Oct 2006 20:01:54 +0000 Subject: [PATCH] 1580293: initialization of pixmask - drawing areas this again is a radical modification... more or less as requested in pr. --- examples/pywmdatetime.py | 120 ++++++++++++--------------------------- examples/pywmgeneric.py | 4 +- examples/pywmhdmon.py | 12 ++-- website/index.html | 1 + wmdocklib/pywmhelpers.py | 75 ++++++++++++++++++------ 5 files changed, 102 insertions(+), 110 deletions(-) diff --git a/examples/pywmdatetime.py b/examples/pywmdatetime.py index f7532c1..27503f6 100755 --- a/examples/pywmdatetime.py +++ b/examples/pywmdatetime.py @@ -78,11 +78,10 @@ def addString(s, x, y): def addTimeString(s, x, y): for c in s: charW = 7 - charX = 64 + (ord(c) - ord('0')) % 5 * 7 - if c <='4': charY = 44 - else: charY = 54 + charX = (ord(c) - ord('0')) * 7 + charY = 64 if not c.isdigit(): - charX = 64 + 35 + charX = 70 charW = 3 wmdocklib.copyXPMArea(charX, charY, charW, 10, x+xOffset, y+yOffset) x += charW @@ -173,7 +172,7 @@ def mainLoop(timeFmt, dateFmt, dayFmt, weekFmt): spacing = getVertSpacing(4, margin) if lastStrs[0] != timeStr: addTimeString(timeStr, timeX, margin-4) - margin += 1 + margin += 2 else: margin = 4 spacing = getVertSpacing(4, margin) @@ -211,72 +210,30 @@ def mainLoop(timeFmt, dateFmt, dayFmt, weekFmt): wmdocklib.redraw() time.sleep(0.1) -background = [ -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" 7", -" 7", -" 7", -" 7", -" 7", -" 7", -" 7", -" 7", -" 7", -" 7", -" 7", -" 7", -" 7", -" 7", -"7777777777777777777777777777777777777777777777777777777777777777", -" ", -" ", -".+@@+.....#@...#@@#...#@@#....$@%.. ", -"$@==@$...+@@..&@--@&.*@--@&...#@%.. ", -"&@**@&..#@@@..&@$.@%.&-..@%..*@@%.. ", -"%@..@%..#+%@.....$@%....+@#..--@%.. ", -"%@..@%....%@.....%@*...%@-..*@$@%.. ", -"%@..@%....%@....+@%....&-@+.=#.@%.. ", -"%@..@%....%@...+@=$......-@.@-%@=&. ", -"&@**@&....%@..$@=$...&-..-@.@@@@@%. ", -"$@==@$....%@..#@-%%&.+@--@#....@%.. ", -".+@@+.....%@..@@@@@%..#@@#.....@%.. ", -".@@@@+..+=@%..+@@@@@..%@@+...&@@#...... ", -"*@-%%*.$==-@&.*%%%@=.#@-=@*.*@=-@&..... ", -"+@+....+@*.%*....+@*.%@.+@+.%@$.-%.*+.. ", -"&@=@#..%@$+$.....--..&@&%@$.%@..%@.%@.. ", -"%@%=@*.%@=@@*...*@&...=@@#..&@%&@@.*+.. ", -".*.$@%.%@%&@-...#@...#@&%@*..=@@@@..... ", -"....@%.%@..%@...=-...@%..@%...+*%@.&%.. ", -"--.*@#.+@$.-@...@%...@-.$@%.$#*.=%.%@.. ", -"%@-=@$.$@=-@#..+@+...#@-=@*.$@=-@+..... ", -"$-@=+...+=@%$..+@+...$#@@&...+@@#...... ", +patterns = [ +".+@@+.....#@...#@@#...#@@#....$@%...@@@@+..+=@%..+@@@@@..%@@+...&@@#.....", +"$@==@$...+@@..&@--@&.*@--@&...#@%..*@-%%*.$==-@&.*%%%@=.#@-=@*.*@=-@&....", +"&@**@&..#@@@..&@$.@%.&-..@%..*@@%..+@+....+@*.%*....+@*.%@.+@+.%@$.-%.*+.", +"%@..@%..#+%@.....$@%....+@#..--@%..&@=@#..%@$+$.....--..&@&%@$.%@..%@.%@.", +"%@..@%....%@.....%@*...%@-..*@$@%..%@%=@*.%@=@@*...*@&...=@@#..&@%&@@.*+.", +"%@..@%....%@....+@%....&-@+.=#.@%...*.$@%.%@%&@-...#@...#@&%@*..=@@@@....", +"%@..@%....%@...+@=$......-@.@-%@=&.....@%.%@..%@...=-...@%..@%...+*%@.&%.", +"&@**@&....%@..$@=$...&-..-@.@@@@@%.--.*@#.+@$.-@...@%...@-.$@%.$#*.=%.%@.", +"$@==@$....%@..#@-%%&.+@--@#....@%..%@-=@$.$@=-@#..+@+...#@-=@*.$@=-@+....", +".+@@+.....%@..@@@@@%..#@@#.....@%..$-@=+...+=@%$..+@+...$#@@&...+@@#.....", ] +palette = { + ".":"#181818", + "+":"#6E6E0F", + "@":"#FFFF00", + "#":"#A0A009", + "$":"#3B3B14", + "%":"#B9B907", + "&":"#87870C", + "*":"#545411", + "=":"#E6E602", + "-":"#CFCF04", + } def main(): clConfig = parseCommandLine(sys.argv) @@ -302,27 +259,22 @@ def main(): programName = '' sys.argv[0] = programName - palette = { - ".":"#181818", - "+":"#6E6E0F", - "@":"#FFFF00", - "#":"#A0A009", - "$":"#3B3B14", - "%":"#B9B907", - "&":"#87870C", - "*":"#545411", - "=":"#E6E602", - "-":"#CFCF04", - } palette[0] = clConfig.get('background', 'black') palette[2] = clConfig.get('foreground', 'cyan3') font = clConfig.get('font', '6x8orig') + + if clConfig.get('antialiased'): + background = [((3,3),(60,18)), + ((3,21),(60,60))] + else: + background = [((3,3),(60,60))] global char_width, char_height, maxCharsPerLine, antialiased - char_width, char_height = wmdocklib.initPixmap(background, + char_width, char_height = wmdocklib.initPixmap(patterns=patterns, font_name=font, - bg=0, fg=2, palette=palette) + bg=0, fg=2, palette=palette, + background=background) maxCharsPerLine = (width-2*xOffset) / char_width antialiased = clConfig.get('antialiased', False) diff --git a/examples/pywmgeneric.py b/examples/pywmgeneric.py index c610607..d28f59e 100644 --- a/examples/pywmgeneric.py +++ b/examples/pywmgeneric.py @@ -159,7 +159,7 @@ def addString(s, x, y): def clearLine(y): """Clear a line of text at position y.""" - wmdocklib.copyXPMArea(72, yOffset, + wmdocklib.copyXPMArea(0, 64+yOffset, width - 2 * xOffset, char_height, xOffset, y + yOffset) @@ -663,7 +663,7 @@ def main(): sys.argv[0] = programName global char_width, char_height - char_width, char_height = wmdocklib.initPixmap(background, + char_width, char_height = wmdocklib.initPixmap(patterns=background, font_name=font, bg='_', fg='%', palette=palette) diff --git a/examples/pywmhdmon.py b/examples/pywmhdmon.py index a183085..22f137f 100755 --- a/examples/pywmhdmon.py +++ b/examples/pywmhdmon.py @@ -68,11 +68,11 @@ graphStartX = 7 graphStartY = 53 graphHeight = 4 -graphBgStartX = 72 -graphBgStartY = 53 +graphBgStartX = 72-64 +graphBgStartY = 53+64 -graphLineStartX = 66 -graphLineStartY = 58 +graphLineStartX = 2 +graphLineStartY = 58+64 defaultConfigFile = os.environ['HOME']+'/.pywmhdmonrc' defaultProcStat = '/proc/stat' @@ -415,7 +415,7 @@ def main(): font = clConfig.get('font', '6x8') global char_width, char_height - char_width, char_height = wmdocklib.initPixmap(background, + char_width, char_height = wmdocklib.initPixmap(patterns=patterns, font_name=font, palette=palette, bg=0, fg=2) @@ -464,7 +464,7 @@ def main(): hdmon = PywmHDMon(pathsToMonitor, procStat, actMonEnabled, skipping) hdmon.mainLoop() -background = \ +patterns = \ ['0000000000000000000000000000000000000000000000000000000000000000', '0000000000000000000000000000000000000000000000000000000000000000', '0077700555002220055500555000000000000000000000000000000000000000', diff --git a/website/index.html b/website/index.html index 0af4971..2070f34 100644 --- a/website/index.html +++ b/website/index.html @@ -104,6 +104,7 @@ some other usable methods are provided there.
+
Pywmdatetime is a dockapp that displays the current time, date, weekday and week number. Formats and colours and font are easily configured.
Changes:
diff --git a/wmdocklib/pywmhelpers.py b/wmdocklib/pywmhelpers.py index 89e92ad..1924d0d 100644 --- a/wmdocklib/pywmhelpers.py +++ b/wmdocklib/pywmhelpers.py @@ -26,10 +26,13 @@ Some changes to handle the additional event handling in pywmgeneral First workingish version """ -import os -import re +import os, re, types import ConfigParser +charset_start = None +charset_width = None +pattern_start = None + import pywmgeneral defaultRGBFileList = [ '/etc/X11/rgb.txt', @@ -91,12 +94,13 @@ def addChar(ch, x, y, xOffset, yOffset, width, height): if not (32 <= ord(ch) <= 127): raise ValueError, "Unsupported Char: '%s'(%d)" % (ch, ord(ch)) # linelength is the amount of bits the character set uses on each row. - linelength = 128 - (128 % char_width) + linelength = charset_width - (charset_width % char_width) # pos is the horizontal index of the box containing ch. pos = (ord(ch)-32) * char_width # translate pos into chX, chY, rolling back and down each linelength # bits. character definition start at row 64, column 0. - chY, chX = (pos / linelength) * char_height + 64, pos % linelength + chY = (pos / linelength) * char_height + charset_start + chX = pos % linelength targX = x + xOffset targY = y + yOffset pywmgeneral.copyXPMArea(chX, chY, char_width, char_height, targX, targY) @@ -143,12 +147,14 @@ def readXPM(fileName): break return res -def initPixmap(xpm_background=None, - font_name='6x8', - bg=0, fg=7, +def initPixmap(background=None, + patterns=None, + style='3d', width=64, height=64, margin=3, - palette=None): + font_name='6x8', + bg=0, fg=7, + palette=None, debug = 0): """builds and sets the pixmap of the program. a wmdockapp has a 128x112 pixmap @@ -205,13 +211,43 @@ def initPixmap(xpm_background=None, if isinstance(fg, int): fg = '%x' % fg - if xpm_background is None: - xpm_background = [bg*width]*height + if patterns is None: + patterns = [bg*width]*height + + if style == '3d': ex = '7' + else: ex = bg + + if background is None: + background = [ + ' '*width + for item in range(margin) + ] + [ + ' '*margin + bg*(width-2*margin-1) + ex + ' '*(margin) + for item in range(margin,height-margin-1) + ] + [ + ' '*margin + ex*(width-2*margin) + ' '*(margin) + ] + [ + ' '*width for item in range(margin) + ] + elif isinstance(background, types.ListType): + nbackground = [[' ']*width for i in range(height)] + for ((left, top),(right, bottom)) in background: + for x in range(left, right+1): + for y in range(top, bottom): + if x < right: + nbackground[y][x] = bg + else: + nbackground[y][x] = ex + nbackground[bottom][x] = ex + background = [ ''.join(item) for item in nbackground ] global tile_width, tile_height tile_width = width tile_height = height + global pattern_start + pattern_start = height + def readFont(font_name): # read xpm, skip header and color definitions, fill/trim to 48 lines. fontdef = readXPM(__file__[:__file__.rfind(os.sep) + 1] + font_name + '.xpm') @@ -227,25 +263,28 @@ def initPixmap(xpm_background=None, global char_width, char_height char_width, char_height, fontdef = readFont(font_name) + + global charset_start, charset_width + charset_start = height + len(patterns) + charset_width = len(fontdef[0]) + + xpmwidth = max(len(background[0]), len(patterns[0]), len(fontdef[0])) + xpmheight = len(background)+len(patterns)+len(fontdef) xpm = [ - '128 112 %d 1' % (1+len(palette)), + '%s %s %d 1' % (xpmwidth, xpmheight, 1+len(palette)), ] + [ ' \tc black' ] + [ '%s\tc %s' % (k,v) for k,v in palette.items() ] + [ - ' '*width + item[:128-width] for item in xpm_background[:margin] + item+' '*(xpmwidth-len(item)) for item in background + patterns ] + [ - ' '*margin+bg*(width-margin-margin-2)+' '*(margin+2) + item[:128-width] for item in xpm_background[margin:-margin-1] - ] + [ - ' '*width + item[:128-width] for item in xpm_background[-margin-1:] - ] + [ - line.replace('%', fg).replace(' ', bg) + line.replace('%', fg).replace(' ', bg) + ' '*(xpmwidth-len(line)) for line in fontdef ] - if 0: + if debug: print '/* XPM */\nstatic char *_x_[] = {' for item in xpm: print '"%s",' % item