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 0000000..a0e9502 Binary files /dev/null and b/website/pictures/hdmon-41.png differ 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