mirror of
https://github.com/gryf/wmdocklib.git
synced 2025-12-19 12:28:10 +01:00
1580293: initialization of pixmask - drawing areas
this again is a radical modification... more or less as requested in pr.
This commit is contained in:
@@ -78,11 +78,10 @@ def addString(s, x, y):
|
|||||||
def addTimeString(s, x, y):
|
def addTimeString(s, x, y):
|
||||||
for c in s:
|
for c in s:
|
||||||
charW = 7
|
charW = 7
|
||||||
charX = 64 + (ord(c) - ord('0')) % 5 * 7
|
charX = (ord(c) - ord('0')) * 7
|
||||||
if c <='4': charY = 44
|
charY = 64
|
||||||
else: charY = 54
|
|
||||||
if not c.isdigit():
|
if not c.isdigit():
|
||||||
charX = 64 + 35
|
charX = 70
|
||||||
charW = 3
|
charW = 3
|
||||||
wmdocklib.copyXPMArea(charX, charY, charW, 10, x+xOffset, y+yOffset)
|
wmdocklib.copyXPMArea(charX, charY, charW, 10, x+xOffset, y+yOffset)
|
||||||
x += charW
|
x += charW
|
||||||
@@ -173,7 +172,7 @@ def mainLoop(timeFmt, dateFmt, dayFmt, weekFmt):
|
|||||||
spacing = getVertSpacing(4, margin)
|
spacing = getVertSpacing(4, margin)
|
||||||
if lastStrs[0] != timeStr:
|
if lastStrs[0] != timeStr:
|
||||||
addTimeString(timeStr, timeX, margin-4)
|
addTimeString(timeStr, timeX, margin-4)
|
||||||
margin += 1
|
margin += 2
|
||||||
else:
|
else:
|
||||||
margin = 4
|
margin = 4
|
||||||
spacing = getVertSpacing(4, margin)
|
spacing = getVertSpacing(4, margin)
|
||||||
@@ -211,72 +210,30 @@ def mainLoop(timeFmt, dateFmt, dayFmt, weekFmt):
|
|||||||
wmdocklib.redraw()
|
wmdocklib.redraw()
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
background = [
|
patterns = [
|
||||||
" ",
|
".+@@+.....#@...#@@#...#@@#....$@%...@@@@+..+=@%..+@@@@@..%@@+...&@@#.....",
|
||||||
" ",
|
"$@==@$...+@@..&@--@&.*@--@&...#@%..*@-%%*.$==-@&.*%%%@=.#@-=@*.*@=-@&....",
|
||||||
" ",
|
"&@**@&..#@@@..&@$.@%.&-..@%..*@@%..+@+....+@*.%*....+@*.%@.+@+.%@$.-%.*+.",
|
||||||
" ",
|
"%@..@%..#+%@.....$@%....+@#..--@%..&@=@#..%@$+$.....--..&@&%@$.%@..%@.%@.",
|
||||||
" ",
|
"%@..@%....%@.....%@*...%@-..*@$@%..%@%=@*.%@=@@*...*@&...=@@#..&@%&@@.*+.",
|
||||||
" ",
|
"%@..@%....%@....+@%....&-@+.=#.@%...*.$@%.%@%&@-...#@...#@&%@*..=@@@@....",
|
||||||
" ",
|
"%@..@%....%@...+@=$......-@.@-%@=&.....@%.%@..%@...=-...@%..@%...+*%@.&%.",
|
||||||
" ",
|
"&@**@&....%@..$@=$...&-..-@.@@@@@%.--.*@#.+@$.-@...@%...@-.$@%.$#*.=%.%@.",
|
||||||
" ",
|
"$@==@$....%@..#@-%%&.+@--@#....@%..%@-=@$.$@=-@#..+@+...#@-=@*.$@=-@+....",
|
||||||
" ",
|
".+@@+.....%@..@@@@@%..#@@#.....@%..$-@=+...+=@%$..+@+...$#@@&...+@@#.....",
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
" 7",
|
|
||||||
"7777777777777777777777777777777777777777777777777777777777777777",
|
|
||||||
" ",
|
|
||||||
" ",
|
|
||||||
".+@@+.....#@...#@@#...#@@#....$@%.. ",
|
|
||||||
"$@==@$...+@@..&@--@&.*@--@&...#@%.. ",
|
|
||||||
"&@**@&..#@@@..&@$.@%.&-..@%..*@@%.. ",
|
|
||||||
"%@..@%..#+%@.....$@%....+@#..--@%.. ",
|
|
||||||
"%@..@%....%@.....%@*...%@-..*@$@%.. ",
|
|
||||||
"%@..@%....%@....+@%....&-@+.=#.@%.. ",
|
|
||||||
"%@..@%....%@...+@=$......-@.@-%@=&. ",
|
|
||||||
"&@**@&....%@..$@=$...&-..-@.@@@@@%. ",
|
|
||||||
"$@==@$....%@..#@-%%&.+@--@#....@%.. ",
|
|
||||||
".+@@+.....%@..@@@@@%..#@@#.....@%.. ",
|
|
||||||
".@@@@+..+=@%..+@@@@@..%@@+...&@@#...... ",
|
|
||||||
"*@-%%*.$==-@&.*%%%@=.#@-=@*.*@=-@&..... ",
|
|
||||||
"+@+....+@*.%*....+@*.%@.+@+.%@$.-%.*+.. ",
|
|
||||||
"&@=@#..%@$+$.....--..&@&%@$.%@..%@.%@.. ",
|
|
||||||
"%@%=@*.%@=@@*...*@&...=@@#..&@%&@@.*+.. ",
|
|
||||||
".*.$@%.%@%&@-...#@...#@&%@*..=@@@@..... ",
|
|
||||||
"....@%.%@..%@...=-...@%..@%...+*%@.&%.. ",
|
|
||||||
"--.*@#.+@$.-@...@%...@-.$@%.$#*.=%.%@.. ",
|
|
||||||
"%@-=@$.$@=-@#..+@+...#@-=@*.$@=-@+..... ",
|
|
||||||
"$-@=+...+=@%$..+@+...$#@@&...+@@#...... ",
|
|
||||||
]
|
]
|
||||||
|
palette = {
|
||||||
|
".":"#181818",
|
||||||
|
"+":"#6E6E0F",
|
||||||
|
"@":"#FFFF00",
|
||||||
|
"#":"#A0A009",
|
||||||
|
"$":"#3B3B14",
|
||||||
|
"%":"#B9B907",
|
||||||
|
"&":"#87870C",
|
||||||
|
"*":"#545411",
|
||||||
|
"=":"#E6E602",
|
||||||
|
"-":"#CFCF04",
|
||||||
|
}
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
clConfig = parseCommandLine(sys.argv)
|
clConfig = parseCommandLine(sys.argv)
|
||||||
@@ -302,27 +259,22 @@ def main():
|
|||||||
programName = ''
|
programName = ''
|
||||||
sys.argv[0] = programName
|
sys.argv[0] = programName
|
||||||
|
|
||||||
palette = {
|
|
||||||
".":"#181818",
|
|
||||||
"+":"#6E6E0F",
|
|
||||||
"@":"#FFFF00",
|
|
||||||
"#":"#A0A009",
|
|
||||||
"$":"#3B3B14",
|
|
||||||
"%":"#B9B907",
|
|
||||||
"&":"#87870C",
|
|
||||||
"*":"#545411",
|
|
||||||
"=":"#E6E602",
|
|
||||||
"-":"#CFCF04",
|
|
||||||
}
|
|
||||||
palette[0] = clConfig.get('background', 'black')
|
palette[0] = clConfig.get('background', 'black')
|
||||||
palette[2] = clConfig.get('foreground', 'cyan3')
|
palette[2] = clConfig.get('foreground', 'cyan3')
|
||||||
|
|
||||||
font = clConfig.get('font', '6x8orig')
|
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
|
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,
|
font_name=font,
|
||||||
bg=0, fg=2, palette=palette)
|
bg=0, fg=2, palette=palette,
|
||||||
|
background=background)
|
||||||
maxCharsPerLine = (width-2*xOffset) / char_width
|
maxCharsPerLine = (width-2*xOffset) / char_width
|
||||||
antialiased = clConfig.get('antialiased', False)
|
antialiased = clConfig.get('antialiased', False)
|
||||||
|
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ def addString(s, x, y):
|
|||||||
|
|
||||||
def clearLine(y):
|
def clearLine(y):
|
||||||
"""Clear a line of text at position y."""
|
"""Clear a line of text at position y."""
|
||||||
wmdocklib.copyXPMArea(72, yOffset,
|
wmdocklib.copyXPMArea(0, 64+yOffset,
|
||||||
width - 2 * xOffset, char_height,
|
width - 2 * xOffset, char_height,
|
||||||
xOffset, y + yOffset)
|
xOffset, y + yOffset)
|
||||||
|
|
||||||
@@ -663,7 +663,7 @@ def main():
|
|||||||
sys.argv[0] = programName
|
sys.argv[0] = programName
|
||||||
|
|
||||||
global char_width, char_height
|
global char_width, char_height
|
||||||
char_width, char_height = wmdocklib.initPixmap(background,
|
char_width, char_height = wmdocklib.initPixmap(patterns=background,
|
||||||
font_name=font,
|
font_name=font,
|
||||||
bg='_', fg='%',
|
bg='_', fg='%',
|
||||||
palette=palette)
|
palette=palette)
|
||||||
|
|||||||
@@ -68,11 +68,11 @@ graphStartX = 7
|
|||||||
graphStartY = 53
|
graphStartY = 53
|
||||||
graphHeight = 4
|
graphHeight = 4
|
||||||
|
|
||||||
graphBgStartX = 72
|
graphBgStartX = 72-64
|
||||||
graphBgStartY = 53
|
graphBgStartY = 53+64
|
||||||
|
|
||||||
graphLineStartX = 66
|
graphLineStartX = 2
|
||||||
graphLineStartY = 58
|
graphLineStartY = 58+64
|
||||||
|
|
||||||
defaultConfigFile = os.environ['HOME']+'/.pywmhdmonrc'
|
defaultConfigFile = os.environ['HOME']+'/.pywmhdmonrc'
|
||||||
defaultProcStat = '/proc/stat'
|
defaultProcStat = '/proc/stat'
|
||||||
@@ -415,7 +415,7 @@ def main():
|
|||||||
font = clConfig.get('font', '6x8')
|
font = clConfig.get('font', '6x8')
|
||||||
|
|
||||||
global char_width, char_height
|
global char_width, char_height
|
||||||
char_width, char_height = wmdocklib.initPixmap(background,
|
char_width, char_height = wmdocklib.initPixmap(patterns=patterns,
|
||||||
font_name=font,
|
font_name=font,
|
||||||
palette=palette,
|
palette=palette,
|
||||||
bg=0, fg=2)
|
bg=0, fg=2)
|
||||||
@@ -464,7 +464,7 @@ def main():
|
|||||||
hdmon = PywmHDMon(pathsToMonitor, procStat, actMonEnabled, skipping)
|
hdmon = PywmHDMon(pathsToMonitor, procStat, actMonEnabled, skipping)
|
||||||
hdmon.mainLoop()
|
hdmon.mainLoop()
|
||||||
|
|
||||||
background = \
|
patterns = \
|
||||||
['0000000000000000000000000000000000000000000000000000000000000000',
|
['0000000000000000000000000000000000000000000000000000000000000000',
|
||||||
'0000000000000000000000000000000000000000000000000000000000000000',
|
'0000000000000000000000000000000000000000000000000000000000000000',
|
||||||
'0077700555002220055500555000000000000000000000000000000000000000',
|
'0077700555002220055500555000000000000000000000000000000000000000',
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ some other usable methods are provided there.
|
|||||||
<h3>Pywmdatetime</h3>
|
<h3>Pywmdatetime</h3>
|
||||||
<img src="pictures/pywmdatetime.png" alt="pywmdatetime">
|
<img src="pictures/pywmdatetime.png" alt="pywmdatetime">
|
||||||
<img src="pictures/pywmdatetime-fonts.png" alt="pywmdatetime">
|
<img src="pictures/pywmdatetime-fonts.png" alt="pywmdatetime">
|
||||||
|
<img src="pictures/pywmdatetime-antialiased.png" alt="pywmdatetime">
|
||||||
<p>Pywmdatetime is a dockapp that displays the current time, date, weekday and
|
<p>Pywmdatetime is a dockapp that displays the current time, date, weekday and
|
||||||
week number. Formats and colours and font are easily configured. </p>
|
week number. Formats and colours and font are easily configured. </p>
|
||||||
<p>Changes:</p>
|
<p>Changes:</p>
|
||||||
|
|||||||
@@ -26,10 +26,13 @@ Some changes to handle the additional event handling in pywmgeneral
|
|||||||
First workingish version
|
First workingish version
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os, re, types
|
||||||
import re
|
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
|
|
||||||
|
charset_start = None
|
||||||
|
charset_width = None
|
||||||
|
pattern_start = None
|
||||||
|
|
||||||
import pywmgeneral
|
import pywmgeneral
|
||||||
defaultRGBFileList = [
|
defaultRGBFileList = [
|
||||||
'/etc/X11/rgb.txt',
|
'/etc/X11/rgb.txt',
|
||||||
@@ -91,12 +94,13 @@ def addChar(ch, x, y, xOffset, yOffset, width, height):
|
|||||||
if not (32 <= ord(ch) <= 127):
|
if not (32 <= ord(ch) <= 127):
|
||||||
raise ValueError, "Unsupported Char: '%s'(%d)" % (ch, ord(ch))
|
raise ValueError, "Unsupported Char: '%s'(%d)" % (ch, ord(ch))
|
||||||
# linelength is the amount of bits the character set uses on each row.
|
# 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 is the horizontal index of the box containing ch.
|
||||||
pos = (ord(ch)-32) * char_width
|
pos = (ord(ch)-32) * char_width
|
||||||
# translate pos into chX, chY, rolling back and down each linelength
|
# translate pos into chX, chY, rolling back and down each linelength
|
||||||
# bits. character definition start at row 64, column 0.
|
# 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
|
targX = x + xOffset
|
||||||
targY = y + yOffset
|
targY = y + yOffset
|
||||||
pywmgeneral.copyXPMArea(chX, chY, char_width, char_height, targX, targY)
|
pywmgeneral.copyXPMArea(chX, chY, char_width, char_height, targX, targY)
|
||||||
@@ -143,12 +147,14 @@ def readXPM(fileName):
|
|||||||
break
|
break
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def initPixmap(xpm_background=None,
|
def initPixmap(background=None,
|
||||||
font_name='6x8',
|
patterns=None,
|
||||||
bg=0, fg=7,
|
style='3d',
|
||||||
width=64, height=64,
|
width=64, height=64,
|
||||||
margin=3,
|
margin=3,
|
||||||
palette=None):
|
font_name='6x8',
|
||||||
|
bg=0, fg=7,
|
||||||
|
palette=None, debug = 0):
|
||||||
"""builds and sets the pixmap of the program.
|
"""builds and sets the pixmap of the program.
|
||||||
|
|
||||||
a wmdockapp has a 128x112 pixmap
|
a wmdockapp has a 128x112 pixmap
|
||||||
@@ -205,13 +211,43 @@ def initPixmap(xpm_background=None,
|
|||||||
if isinstance(fg, int):
|
if isinstance(fg, int):
|
||||||
fg = '%x' % fg
|
fg = '%x' % fg
|
||||||
|
|
||||||
if xpm_background is None:
|
if patterns is None:
|
||||||
xpm_background = [bg*width]*height
|
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
|
global tile_width, tile_height
|
||||||
tile_width = width
|
tile_width = width
|
||||||
tile_height = height
|
tile_height = height
|
||||||
|
|
||||||
|
global pattern_start
|
||||||
|
pattern_start = height
|
||||||
|
|
||||||
def readFont(font_name):
|
def readFont(font_name):
|
||||||
# read xpm, skip header and color definitions, fill/trim to 48 lines.
|
# read xpm, skip header and color definitions, fill/trim to 48 lines.
|
||||||
fontdef = readXPM(__file__[:__file__.rfind(os.sep) + 1] + font_name + '.xpm')
|
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
|
global char_width, char_height
|
||||||
char_width, char_height, fontdef = readFont(font_name)
|
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 = [
|
xpm = [
|
||||||
'128 112 %d 1' % (1+len(palette)),
|
'%s %s %d 1' % (xpmwidth, xpmheight, 1+len(palette)),
|
||||||
] + [
|
] + [
|
||||||
' \tc black'
|
' \tc black'
|
||||||
] + [
|
] + [
|
||||||
'%s\tc %s' % (k,v)
|
'%s\tc %s' % (k,v)
|
||||||
for k,v in palette.items()
|
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]
|
line.replace('%', fg).replace(' ', bg) + ' '*(xpmwidth-len(line))
|
||||||
] + [
|
|
||||||
' '*width + item[:128-width] for item in xpm_background[-margin-1:]
|
|
||||||
] + [
|
|
||||||
line.replace('%', fg).replace(' ', bg)
|
|
||||||
for line in fontdef
|
for line in fontdef
|
||||||
]
|
]
|
||||||
if 0:
|
if debug:
|
||||||
print '/* XPM */\nstatic char *_x_[] = {'
|
print '/* XPM */\nstatic char *_x_[] = {'
|
||||||
for item in xpm:
|
for item in xpm:
|
||||||
print '"%s",' % item
|
print '"%s",' % item
|
||||||
|
|||||||
Reference in New Issue
Block a user