mirror of
https://github.com/gryf/wmdocklib.git
synced 2025-12-19 20:38:03 +01:00
1584740: colours messed up
modified the fonts: they start from background colour (None or Black) and go to full intensity, which ought to be gray100 or white. the initialization procedure will spread all colour differences between the requested background and foreground proportionally to the intensity of the gray char pixel. most colour code clashes are resolved at initialization stage. there are only a few things you should not reuse, such as the space for transparency. just try out the result and make use of the 'debug' parameter which will cause the function to print the the generated xpm.
This commit is contained in:
@@ -38,6 +38,7 @@ Available options are:
|
||||
-e, --weekformat <format> set the week format
|
||||
-r, --rgbfile <file> set the rgb file to get color codes from
|
||||
-c, --configfile <file> set the config file to use
|
||||
--debug shows the pixmap
|
||||
|
||||
The formats are the same as Python's strftime() accept. See the sample
|
||||
rc-file for more information about this.
|
||||
@@ -113,7 +114,8 @@ def calculateWeek(localTime):
|
||||
def parseCommandLine(argv):
|
||||
"""Parse the commandline. Return a dictionary with options and values."""
|
||||
shorts = 'hf:b:t:d:e:y:r:c:F:a'
|
||||
longs = ['antialiased', 'help', 'foreground=', 'background=', 'timeformat=', 'dateformat=',
|
||||
longs = ['antialiased', 'help', 'foreground=', 'background=',
|
||||
'timeformat=', 'dateformat=', 'debug',
|
||||
'weekdayformat=', 'weekformat=', 'rgbfile=', 'configfile=', 'font=']
|
||||
try:
|
||||
opts, nonOptArgs = getopt.getopt(argv[1:], shorts, longs)
|
||||
@@ -147,6 +149,8 @@ def parseCommandLine(argv):
|
||||
d['rgbfile'] = a
|
||||
if o in ('-c', '--configfile'):
|
||||
d['configfile'] = a
|
||||
if o in ('--debug'):
|
||||
d['debug'] = True
|
||||
return d
|
||||
|
||||
def checkForEvents():
|
||||
@@ -269,12 +273,15 @@ def main():
|
||||
((3,22),(60,60))]
|
||||
else:
|
||||
background = [((3,3),(59,60))]
|
||||
|
||||
debug = clConfig.get('debug')
|
||||
|
||||
global char_width, char_height, maxCharsPerLine, antialiased
|
||||
char_width, char_height = wmdocklib.initPixmap(patterns=patterns,
|
||||
font_name=font,
|
||||
bg=0, fg=2, palette=palette,
|
||||
background=background)
|
||||
background=background,
|
||||
debug=debug)
|
||||
maxCharsPerLine = (width-2*xOffset) / char_width
|
||||
antialiased = clConfig.get('antialiased', False)
|
||||
|
||||
|
||||
@@ -513,7 +513,8 @@ class PywmGeneric:
|
||||
def parseCommandLine(argv):
|
||||
"""Parse the commandline. Return a dictionary with options and values."""
|
||||
shorts = 'ht:b:r:c:F:'
|
||||
longs = ['help', 'text=', 'background=', 'rgbfile=', 'configfile=', 'font=']
|
||||
longs = ['help', 'text=', 'background=', 'rgbfile=', 'configfile=',
|
||||
'font=', 'debug']
|
||||
try:
|
||||
opts, nonOptArgs = getopt.getopt(argv[1:], shorts, longs)
|
||||
except getopt.GetoptError, e:
|
||||
@@ -535,6 +536,8 @@ def parseCommandLine(argv):
|
||||
d['rgbfile'] = a
|
||||
if o in ('-c', '--configfile'):
|
||||
d['configfile'] = a
|
||||
if o in ('--debug'):
|
||||
d['debug'] = True
|
||||
return d
|
||||
|
||||
def readConfigFile(fileName):
|
||||
@@ -634,21 +637,20 @@ def main():
|
||||
clConfig = parseCommandLine(sys.argv)
|
||||
|
||||
palette = {
|
||||
' ': '#208120812081',
|
||||
'.': '#00000000FFFF',
|
||||
'o': '#C71BC30BC71B',
|
||||
'O': '#861782078E38',
|
||||
'+': '#EFBEF3CEEFBE',
|
||||
'@': '#618561856185',
|
||||
'#': '#9E79A2899E79',
|
||||
'$': '#410341034103',
|
||||
'.': '#0000FF',
|
||||
'o': '#C7C3C7',
|
||||
'O': '#86828E',
|
||||
'+': '#EFF3EF',
|
||||
'@': '#616161',
|
||||
'#': '#9EA29E',
|
||||
'$': '#414141',
|
||||
}
|
||||
|
||||
palette['o'] = clConfig.get('indicator', '#2020b2b2aaaa')
|
||||
palette['/'] = clConfig.get('graph', '#2020b2b2aaaa')
|
||||
palette['-'] = clConfig.get('graphbg', '#707070707070')
|
||||
palette['_'] = clConfig.get('background', '#FFFFFFFFFFFF')
|
||||
palette['%'] = clConfig.get('text', '#2081B2CAAEBA')
|
||||
palette['o'] = clConfig.get('indicator', '#20b2aa')
|
||||
palette['/'] = clConfig.get('graph', '#20b2aa')
|
||||
palette['-'] = clConfig.get('graphbg', '#707070')
|
||||
palette['_'] = clConfig.get('background', '#FFFFFF')
|
||||
palette['%'] = clConfig.get('text', '#20B2AE')
|
||||
|
||||
font = clConfig.get('font', '6x8')
|
||||
|
||||
|
||||
@@ -310,7 +310,7 @@ def parseCommandLine(argv):
|
||||
shorts = 'ht:f:g:b:r:c:p:s:F:'
|
||||
longs = ['help', 'textcolor=', 'background=', 'barfgcolor=',
|
||||
'rgbfile=', 'configfile=', 'barbgcolor=', 'procstat=',
|
||||
'skipconf=','font=']
|
||||
'skipconf=','font=', 'debug']
|
||||
try:
|
||||
opts, nonOptArgs = getopt.getopt(argv[1:], shorts, longs)
|
||||
except getopt.GetoptError, e:
|
||||
@@ -340,6 +340,8 @@ def parseCommandLine(argv):
|
||||
d['procstat'] = a
|
||||
if o in ('-s', '--skipconf'):
|
||||
d['skipconf'] = a
|
||||
if o in ('--debug'):
|
||||
d['debug'] = True
|
||||
return d
|
||||
|
||||
def makeNumDigits(num, numDigits):
|
||||
@@ -420,12 +422,14 @@ def main():
|
||||
palette['-'] = 'grey65'
|
||||
|
||||
font = clConfig.get('font', '6x8')
|
||||
debug = clConfig.get('debug')
|
||||
|
||||
global char_width, char_height
|
||||
char_width, char_height = wmdocklib.initPixmap(patterns=patterns,
|
||||
font_name=font,
|
||||
palette=palette,
|
||||
bg=0, fg=2)
|
||||
margin=3,
|
||||
bg=0, fg=2, debug=debug)
|
||||
|
||||
pathsToMonitor = []
|
||||
for i in range(1,1000):
|
||||
|
||||
BIN
website/pictures/hdmon-41.png
Normal file
BIN
website/pictures/hdmon-41.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -2,8 +2,8 @@
|
||||
static char *_x_[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"128 28 2 1",
|
||||
"% c black",
|
||||
" c gray100",
|
||||
" c None",
|
||||
"% c gray100",
|
||||
/* pixels */
|
||||
" % % % % % % % % % %% %%%% % %%%% %% %%%% %% ",
|
||||
" % % % % % %%% % % % % % % % % % % % % %% % % % %% % % % % % ",
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
static char *square_[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"128 32 2 1",
|
||||
"% c black",
|
||||
" c gray100",
|
||||
" c None",
|
||||
"% c gray100",
|
||||
/* pixels */
|
||||
" % % % % % % % % %% % % % %% % %% %% % %%%% %% %%%% %% ",
|
||||
" % % % % % %%% % % % % % % % % % % % % % %% % % % % %% % % % % % % % ",
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
static char *_x__[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"192 36 2 1",
|
||||
"% c black",
|
||||
" c gray100",
|
||||
" c None",
|
||||
"% c gray100",
|
||||
/* pixels */
|
||||
" % % ",
|
||||
" % % % % % % % % % % % % % %%% %%%%% % %%%%% %%% %%%%% %%% %%% % % %%% ",
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
static char *square_[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"128 40 2 1",
|
||||
"% c black",
|
||||
" c gray100",
|
||||
" c None",
|
||||
"% c gray100",
|
||||
/* pixels */
|
||||
" % % % % % % % % %% % % % %%% % %%% %%% % ",
|
||||
" % % % % % %%%% % % % % % % % % % % % % %% % % % % %% ",
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
static char *square_[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"128 40 2 1",
|
||||
"% c black",
|
||||
" c gray100",
|
||||
" c None",
|
||||
"% c gray100",
|
||||
/* pixels */
|
||||
" % % % % % % % % %%%%% % %%%%% %%%%% % % ",
|
||||
" % % % % % % % % % %% % % % % ",
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
static char *square_[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"128 40 2 1",
|
||||
"% c black",
|
||||
" c gray100",
|
||||
" c None",
|
||||
"% c gray100",
|
||||
/* pixels */
|
||||
" % % % % %% % % % % % % %%%%% % %%%%% %%%%% % % ",
|
||||
" % % % % % %%%%% %% %%% % % % % % % % % % % % %% % % % % % % ",
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
static char *_test[] = {
|
||||
"106 72 5 1",
|
||||
" c None",
|
||||
". c grey95",
|
||||
"- c grey65",
|
||||
"o c grey45",
|
||||
"x c black",
|
||||
". c grey5",
|
||||
"- c grey35",
|
||||
"o c grey65",
|
||||
"x c grey100",
|
||||
" .... .-.. .-..- .-..- oxxxx- -.... -xxxx- .... .... .... .... .... .... .... .... .... ",
|
||||
". . .. . x .. . x .x . x .x x x .. x . x. x . x. . x .. . . x. x . .. x x x. . x .. . . .. . . .. . . .. . . x. ",
|
||||
"... .. ..x .. ..x .x ..x .x x.x .. xx. x. -o. x. . x .. . . x. -o. .. -ox x. . x .. . . .. . . .. . . .. . . x. ",
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
static char *_x_zx[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"128 48 2 1",
|
||||
"% c black",
|
||||
" c gray100",
|
||||
" c None",
|
||||
"% c gray100",
|
||||
/* pixels */
|
||||
" ",
|
||||
" % % % %%% % %% % % % % % %%%% %% ",
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
static char *_test[] = {
|
||||
"128 72 5 1",
|
||||
" c None",
|
||||
". c grey95",
|
||||
"- c grey65",
|
||||
"o c grey45",
|
||||
"x c black",
|
||||
". c grey5",
|
||||
"- c grey35",
|
||||
"o c grey55",
|
||||
"x c grey100",
|
||||
" ..... ..-.. ..-..- ..-..- -xxxxx- -..... -xxxxx- ..... ..... ..... ..... ..... ..... ..... ..... ..... ",
|
||||
".. . .. .. x .. .. x .x .. x .x x. x .. xo . x. .x . x. .. x .. .. . x. .x . .. .x x x. .. x .. .. . .. .. . .. .. . .. .. . x. ",
|
||||
".. . .. .. x .. .. x .x .. x .x x. x .. xx . x. .x . x. .. x .. .. . x. .x . .. .x x x. .. x .. .. . .. .. . .. .. . .. .. . x. ",
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
static char *c___low[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"128 48 2 1",
|
||||
"% c black",
|
||||
" c gray100",
|
||||
" c None",
|
||||
"% c gray100",
|
||||
/* pixels */
|
||||
" %% %% %% %% %% %% %% % %%%% %% %% %% ",
|
||||
" %% %% %% %% %% %%%%% %% %% %% %% %% %% %% %% %% %% %%",
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
static char *_x_zx[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"128 48 2 1",
|
||||
"% c black",
|
||||
" c gray100",
|
||||
" c None",
|
||||
"% c gray100",
|
||||
/* pixels */
|
||||
" ",
|
||||
" % % % %%% % %% % % % % % ",
|
||||
|
||||
@@ -179,6 +179,9 @@ def initPixmap(background=None,
|
||||
The XBM mask is created out of the XPM.
|
||||
"""
|
||||
|
||||
# initially all characters 32-126 are available...
|
||||
available = dict([(chr(ch), True) for ch in range(32,127)])
|
||||
|
||||
# a palette is a dictionary from one single letter to an hexadecimal
|
||||
# colour. per default we offer a 16 colours palette including what I
|
||||
# consider the basic colours:
|
||||
@@ -190,9 +193,12 @@ def initPixmap(background=None,
|
||||
alter_palette, palette = palette, {}
|
||||
for name, index in zip(basic_colours, range(16)):
|
||||
palette['%x'%index] = getColorCode(name)
|
||||
available['%x'%index] = False
|
||||
palette[' '] = 'None'
|
||||
available[' '] = False
|
||||
|
||||
# palette = {' ': None, '0':..., '1':..., ..., 'f':...}
|
||||
|
||||
# palette = {'0':..., '1':..., ..., 'f':...}
|
||||
|
||||
if alter_palette is not None:
|
||||
# alter_palette contains 0..15/chr -> 'name'/'#hex'
|
||||
# interpret that as chr -> '#hex'
|
||||
@@ -203,6 +209,7 @@ def initPixmap(background=None,
|
||||
if not v.startswith('#'):
|
||||
v = getColorCode(v)
|
||||
palette[k] = v
|
||||
available[k] = False
|
||||
|
||||
if isinstance(bg, int):
|
||||
bg = '%x' % bg
|
||||
@@ -247,7 +254,7 @@ def initPixmap(background=None,
|
||||
pattern_start = height
|
||||
|
||||
def readFont(font_name):
|
||||
# read xpm, skip header and color definitions, fill/trim to 48 lines.
|
||||
# read xpm, return cell_size, definition and palette.
|
||||
font_palette = {}
|
||||
fontdef = readXPM(__file__[:__file__.rfind(os.sep) + 1] + font_name + '.xpm')
|
||||
colorCount = int(fontdef[0].split(' ')[2])
|
||||
@@ -262,10 +269,51 @@ def initPixmap(background=None,
|
||||
if not m:
|
||||
raise ValueError("can't infer font size from name (does not contain wxh)")
|
||||
width, height = [int(item) for item in m.groups()]
|
||||
|
||||
replace = []
|
||||
for code, value in font_palette.items():
|
||||
if not available[code] and palette[code] != font_palette[code]:
|
||||
newcode = [k for k in available if available[k]][0]
|
||||
available[newcode] = False
|
||||
replace.append((code, newcode))
|
||||
for code, newcode in replace:
|
||||
for row, i in zip(fontdef,range(len(fontdef))):
|
||||
fontdef[i] = row.replace(code, newcode)
|
||||
font_palette[newcode] = font_palette[code]
|
||||
del font_palette[code]
|
||||
return width, height, fontdef, font_palette
|
||||
|
||||
def calibrateFontPalette(font_palette, fg, bg):
|
||||
"""computes modified font_palette
|
||||
|
||||
takes into account only intensity of original value.
|
||||
|
||||
fg, bg must be of the form #xxxxxx
|
||||
|
||||
the corresponding calibrated colour lies at a specific percentage of
|
||||
the vector going from background to foreground."""
|
||||
|
||||
bg_point = [int(bg[i*2+1:i*2+3],16) for i in range(3)]
|
||||
fg_point = [int(fg[i*2+1:i*2+3],16) for i in range(3)]
|
||||
|
||||
fg_vec = [f-b for (f,b) in zip(fg_point,bg_point)]
|
||||
|
||||
new_font_palette = {}
|
||||
for k, colourName in font_palette.items():
|
||||
if colourName == 'None':
|
||||
continue
|
||||
origColour = getColorCode(colourName)[1:]
|
||||
origRgb = [int(origColour[i*2:i*2+2],16)/256. for i in range(3)]
|
||||
intensity = sum(origRgb) / 3
|
||||
newRgb = [i * intensity + base for i,base in zip(fg_vec, bg_point)]
|
||||
new_font_palette[k] = '#'+''.join(["%02x"%i for i in newRgb])
|
||||
|
||||
return new_font_palette
|
||||
|
||||
global char_width, char_height
|
||||
char_width, char_height, fontdef, font_palette = readFont(font_name)
|
||||
font_palette = calibrateFontPalette(font_palette, palette[fg], palette[bg])
|
||||
|
||||
palette.update(font_palette)
|
||||
|
||||
global charset_start, charset_width
|
||||
@@ -276,14 +324,18 @@ def initPixmap(background=None,
|
||||
xpmheight = len(background)+len(patterns)+len(fontdef)
|
||||
|
||||
xpm = [
|
||||
'%s %s %d 1' % (xpmwidth, xpmheight, 1+len(palette)),
|
||||
] + [
|
||||
' \tc black'
|
||||
'%s %s %d 1' % (xpmwidth, xpmheight, len(palette)),
|
||||
] + [
|
||||
'%s\tc %s' % (k,v)
|
||||
for k,v in palette.items()
|
||||
if v == 'None'
|
||||
] + [
|
||||
item+' '*(xpmwidth-len(item)) for item in background + patterns
|
||||
'%s\tc %s' % (k,v)
|
||||
for k,v in palette.items()
|
||||
if v != 'None'
|
||||
] + [
|
||||
item+' '*(xpmwidth-len(item))
|
||||
for item in background + patterns
|
||||
] + [
|
||||
line.replace('%', fg).replace(' ', bg) + ' '*(xpmwidth-len(line))
|
||||
for line in fontdef
|
||||
|
||||
Reference in New Issue
Block a user