From 3c127f98494e56e2a0da2de9a6ab67eb7695d3d7 Mon Sep 17 00:00:00 2001 From: mfrasca <> Date: Thu, 26 Oct 2006 08:41:00 +0000 Subject: [PATCH] 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. --- examples/pywmdatetime.py | 11 ++++-- examples/pywmgeneric.py | 30 ++++++++-------- examples/pywmhdmon.py | 8 +++-- website/pictures/hdmon-41.png | Bin 0 -> 1172 bytes wmdocklib/5x7.xpm | 4 +-- wmdocklib/5x8.xpm | 4 +-- wmdocklib/6x12.xpm | 4 +-- wmdocklib/6x8.xpm | 4 +-- wmdocklib/6x8orig.xpm | 4 +-- wmdocklib/6x8slant.xpm | 4 +-- wmdocklib/7x12-41c.xpm | 8 ++--- wmdocklib/7x8zx.xpm | 4 +-- wmdocklib/8x12-41c.xpm | 8 ++--- wmdocklib/8x8.xpm | 4 +-- wmdocklib/8x8zx.xpm | 4 +-- wmdocklib/pywmhelpers.py | 66 ++++++++++++++++++++++++++++++---- 16 files changed, 116 insertions(+), 51 deletions(-) create mode 100644 website/pictures/hdmon-41.png diff --git a/examples/pywmdatetime.py b/examples/pywmdatetime.py index b29b8fd..5d4dc42 100755 --- a/examples/pywmdatetime.py +++ b/examples/pywmdatetime.py @@ -38,6 +38,7 @@ Available options are: -e, --weekformat set the week format -r, --rgbfile set the rgb file to get color codes from -c, --configfile 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) diff --git a/examples/pywmgeneric.py b/examples/pywmgeneric.py index 41946a8..c81a1e6 100644 --- a/examples/pywmgeneric.py +++ b/examples/pywmgeneric.py @@ -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') diff --git a/examples/pywmhdmon.py b/examples/pywmhdmon.py index f095411..8c9fdd0 100755 --- a/examples/pywmhdmon.py +++ b/examples/pywmhdmon.py @@ -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): diff --git a/website/pictures/hdmon-41.png b/website/pictures/hdmon-41.png new file mode 100644 index 0000000000000000000000000000000000000000..a0e950292233884e1b60502f93aec9b4f2352463 GIT binary patch literal 1172 zcmV;F1Z(?=P)00009a7bBm0000; z0000;07l7cJ^%m&EJ;K`RA}DaT1|`7Kp1|u^prm%NcSL;6%=hn@#0~@m4XO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L>>Q literal 0 HcmV?d00001 diff --git a/wmdocklib/5x7.xpm b/wmdocklib/5x7.xpm index a7ff218..ac8368b 100644 --- a/wmdocklib/5x7.xpm +++ b/wmdocklib/5x7.xpm @@ -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 */ " % % % % % % % % % %% %%%% % %%%% %% %%%% %% ", " % % % % % %%% % % % % % % % % % % % % %% % % % %% % % % % % ", diff --git a/wmdocklib/5x8.xpm b/wmdocklib/5x8.xpm index a67a14b..098ae91 100644 --- a/wmdocklib/5x8.xpm +++ b/wmdocklib/5x8.xpm @@ -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 */ " % % % % % % % % %% % % % %% % %% %% % %%%% %% %%%% %% ", " % % % % % %%% % % % % % % % % % % % % % %% % % % % %% % % % % % % % ", diff --git a/wmdocklib/6x12.xpm b/wmdocklib/6x12.xpm index dd93f0e..ef3e3d6 100644 --- a/wmdocklib/6x12.xpm +++ b/wmdocklib/6x12.xpm @@ -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 */ " % % ", " % % % % % % % % % % % % % %%% %%%%% % %%%%% %%% %%%%% %%% %%% % % %%% ", diff --git a/wmdocklib/6x8.xpm b/wmdocklib/6x8.xpm index 267270d..c777296 100644 --- a/wmdocklib/6x8.xpm +++ b/wmdocklib/6x8.xpm @@ -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 */ " % % % % % % % % %% % % % %%% % %%% %%% % ", " % % % % % %%%% % % % % % % % % % % % % %% % % % % %% ", diff --git a/wmdocklib/6x8orig.xpm b/wmdocklib/6x8orig.xpm index f40a5d3..bc77cb4 100644 --- a/wmdocklib/6x8orig.xpm +++ b/wmdocklib/6x8orig.xpm @@ -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 */ " % % % % % % % % %%%%% % %%%%% %%%%% % % ", " % % % % % % % % % %% % % % % ", diff --git a/wmdocklib/6x8slant.xpm b/wmdocklib/6x8slant.xpm index 3b90b91..8b527c4 100644 --- a/wmdocklib/6x8slant.xpm +++ b/wmdocklib/6x8slant.xpm @@ -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 */ " % % % % %% % % % % % % %%%%% % %%%%% %%%%% % % ", " % % % % % %%%%% %% %%% % % % % % % % % % % % %% % % % % % % ", diff --git a/wmdocklib/7x12-41c.xpm b/wmdocklib/7x12-41c.xpm index 11125f9..7e494ed 100644 --- a/wmdocklib/7x12-41c.xpm +++ b/wmdocklib/7x12-41c.xpm @@ -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. ", diff --git a/wmdocklib/7x8zx.xpm b/wmdocklib/7x8zx.xpm index 124584b..24435d7 100644 --- a/wmdocklib/7x8zx.xpm +++ b/wmdocklib/7x8zx.xpm @@ -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 */ " ", " % % % %%% % %% % % % % % %%%% %% ", diff --git a/wmdocklib/8x12-41c.xpm b/wmdocklib/8x12-41c.xpm index 6239d43..14cc923 100644 --- a/wmdocklib/8x12-41c.xpm +++ b/wmdocklib/8x12-41c.xpm @@ -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. ", diff --git a/wmdocklib/8x8.xpm b/wmdocklib/8x8.xpm index 6b64493..9fe1ae4 100644 --- a/wmdocklib/8x8.xpm +++ b/wmdocklib/8x8.xpm @@ -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 */ " %% %% %% %% %% %% %% % %%%% %% %% %% ", " %% %% %% %% %% %%%%% %% %% %% %% %% %% %% %% %% %% %%", diff --git a/wmdocklib/8x8zx.xpm b/wmdocklib/8x8zx.xpm index 5c23eaf..ff957cf 100644 --- a/wmdocklib/8x8zx.xpm +++ b/wmdocklib/8x8zx.xpm @@ -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 */ " ", " % % % %%% % %% % % % % % ", diff --git a/wmdocklib/pywmhelpers.py b/wmdocklib/pywmhelpers.py index 1c051de..139f836 100644 --- a/wmdocklib/pywmhelpers.py +++ b/wmdocklib/pywmhelpers.py @@ -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