1
0
mirror of https://github.com/gryf/wmdocklib.git synced 2025-12-19 04:20:17 +01:00

Make pywmhelpers work on python3

This commit is contained in:
2022-04-09 11:35:41 +02:00
parent 12fe776ec3
commit 7eb2042fb8

View File

@@ -26,14 +26,16 @@ Some changes to handle the additional event handling in pywmgeneral
First workingish version First workingish version
""" """
import os, re, types import os
import ConfigParser import re
import types
import configparser
charset_start = None charset_start = None
charset_width = None charset_width = None
pattern_start = None pattern_start = None
import pywmgeneral from wmdocklib import pywmgeneral
defaultRGBFileList = [ defaultRGBFileList = [
'/etc/X11/rgb.txt', '/etc/X11/rgb.txt',
'/usr/lib/X11/rgb.txt', '/usr/lib/X11/rgb.txt',
@@ -55,10 +57,10 @@ def readConfigFile(fileName, errOut):
errOut.write( errOut.write(
'Configuration file is not readable. Using defaults.\n') 'Configuration file is not readable. Using defaults.\n')
return {} return {}
cp = ConfigParser.ConfigParser() cp = configparser.ConfigParser()
try: try:
cp.read(fileName) cp.read(fileName)
except ConfigParser.Error, e: except configparser.Error as e:
if errOut: if errOut:
errOut.write('Error in configuration file:\n') errOut.write('Error in configuration file:\n')
errOut.write(str(e) + '\nUsing defaults.') errOut.write(str(e) + '\nUsing defaults.')
@@ -102,10 +104,10 @@ def addChar(ch, x, y, xOffset, yOffset, width, height, drawable=None):
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 = (pos / linelength) * char_height + charset_start chY = int((pos / linelength) * char_height + charset_start)
chX = pos % linelength chX = int(pos % linelength)
targX = x + xOffset targX = int(x + xOffset)
targY = y + yOffset targY = int(y + yOffset)
chW = char_width chW = char_width
if ch in "',.:;": if ch in "',.:;":
chW = char_twidth chW = char_twidth
@@ -125,7 +127,6 @@ def addString(s, x, y, xOffset=0, yOffset=0, width=None, height=None, drawable=N
xOffset, yOffset, width, height, xOffset, yOffset, width, height,
drawable) drawable)
lastW += w lastW += w
return lastW
def getVertSpacing(numLines, margin, height, yOffset): def getVertSpacing(numLines, margin, height, yOffset):
"""Return the optimal spacing between a number of lines. """Return the optimal spacing between a number of lines.
@@ -146,7 +147,7 @@ def readXPM(fileName):
Raise IOError if we run into trouble when trying to read the file. This Raise IOError if we run into trouble when trying to read the file. This
function has not been tested extensively. do not try to use more than function has not been tested extensively. do not try to use more than
""" """
f = file(fileName, 'r') f = open(fileName, 'r')
lines = [l.rstrip('\n') for l in f.readlines()] lines = [l.rstrip('\n') for l in f.readlines()]
s = ''.join(lines) s = ''.join(lines)
res = [] res = []
@@ -218,7 +219,7 @@ def initPixmap(background=None,
palette, background = readXPM(background) palette, background = readXPM(background)
alter_palette, palette = palette, {} alter_palette, palette = palette, {}
for name, index in zip(basic_colors, range(16)): for name, index in zip(basic_colors, list(range(16))):
palette['%x'%index] = getColorCode(name) palette['%x'%index] = getColorCode(name)
available['%x'%index] = False available['%x'%index] = False
palette[' '] = 'None' palette[' '] = 'None'
@@ -229,7 +230,7 @@ def initPixmap(background=None,
if alter_palette is not None: if alter_palette is not None:
# alter_palette contains 0..15/chr -> 'name'/'#hex' # alter_palette contains 0..15/chr -> 'name'/'#hex'
# interpret that as chr -> '#hex' # interpret that as chr -> '#hex'
for k,v in alter_palette.items(): for k,v in list(alter_palette.items()):
if isinstance(k, int): if isinstance(k, int):
k = '%x' % k k = '%x' % k
k = k[0] k = k[0]
@@ -261,7 +262,7 @@ def initPixmap(background=None,
] + [ ] + [
' '*width for item in range(margin) ' '*width for item in range(margin)
] ]
elif isinstance(background, types.ListType) and not isinstance(background[0], types.StringTypes): elif isinstance(background, list) and not isinstance(background[0], (str,)):
nbackground = [[' ']*width for i in range(height)] nbackground = [[' ']*width for i in range(height)]
for ((left, top),(right, bottom)) in background: for ((left, top),(right, bottom)) in background:
for x in range(left, right+1): for x in range(left, right+1):
@@ -293,7 +294,7 @@ def initPixmap(background=None,
thinwidth = int(m.groupdict().get('t') or width) thinwidth = int(m.groupdict().get('t') or width)
replace = [] replace = []
for code, value in font_palette.items(): for code, value in list(font_palette.items()):
if available[code]: if available[code]:
continue continue
if palette[code] != font_palette[code]: if palette[code] != font_palette[code]:
@@ -301,7 +302,7 @@ def initPixmap(background=None,
available[newcode] = False available[newcode] = False
replace.append((code, newcode)) replace.append((code, newcode))
for code, newcode in replace: for code, newcode in replace:
for row, i in zip(fontdef,range(len(fontdef))): for row, i in zip(fontdef,list(range(len(fontdef)))):
fontdef[i] = row.replace(code, newcode) fontdef[i] = row.replace(code, newcode)
font_palette[newcode] = font_palette[code] font_palette[newcode] = font_palette[code]
del font_palette[code] del font_palette[code]
@@ -323,14 +324,14 @@ def initPixmap(background=None,
fg_vec = [f-b for (f,b) in zip(fg_point,bg_point)] fg_vec = [f-b for (f,b) in zip(fg_point,bg_point)]
new_font_palette = {} new_font_palette = {}
for k, colorName in font_palette.items(): for k, colorName in list(font_palette.items()):
if colorName == 'None': if colorName == 'None':
continue continue
origColor = getColorCode(colorName)[1:] origColor = getColorCode(colorName)[1:]
origRgb = [int(origColor[i*2:i*2+2],16)/256. for i in range(3)] origRgb = [int(origColor[i*2:i*2+2],16)/256. for i in range(3)]
intensity = sum(origRgb) / 3 intensity = sum(origRgb) / 3
newRgb = [i * intensity + base for i,base in zip(fg_vec, bg_point)] newRgb = [i * intensity + base for i,base in zip(fg_vec, bg_point)]
new_font_palette[k] = '#'+''.join(["%02x"%i for i in newRgb]) new_font_palette[k] = '#'+''.join(["%02x"% int(i) for i in newRgb])
return new_font_palette return new_font_palette
@@ -351,11 +352,11 @@ def initPixmap(background=None,
'%s %s %d 1' % (xpmwidth, xpmheight, len(palette)), '%s %s %d 1' % (xpmwidth, xpmheight, len(palette)),
] + [ ] + [
'%s\tc %s' % (k,v) '%s\tc %s' % (k,v)
for k,v in palette.items() for k,v in list(palette.items())
if v == 'None' if v == 'None'
] + [ ] + [
'%s\tc %s' % (k,v) '%s\tc %s' % (k,v)
for k,v in palette.items() for k,v in list(palette.items())
if v != 'None' if v != 'None'
] + [ ] + [
item+' '*(xpmwidth-len(item)) item+' '*(xpmwidth-len(item))
@@ -365,10 +366,10 @@ def initPixmap(background=None,
for line in fontdef for line in fontdef
] ]
if debug: 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))
print '};' print('};')
pywmgeneral.includePixmap(xpm) pywmgeneral.includePixmap(xpm)
return char_width, char_height return char_width, char_height
@@ -389,6 +390,9 @@ def redrawXY(x, y):
def copyXPMArea(sourceX, sourceY, width, height, targetX, targetY): def copyXPMArea(sourceX, sourceY, width, height, targetX, targetY):
"""Copy an area of the global XPM.""" """Copy an area of the global XPM."""
(sourceX, sourceY, width, height, targetX,
targetY) = (int(sourceX), int(sourceY), int(width), int(height),
int(targetX), int(targetY))
if width > 0 or height > 0: if width > 0 or height > 0:
pywmgeneral.copyXPMArea(sourceX, sourceY, width, height, pywmgeneral.copyXPMArea(sourceX, sourceY, width, height,
targetX, targetY) targetX, targetY)
@@ -437,7 +441,7 @@ def getColorCode(colorName, rgbFileName=None):
if rgbFileName is None: if rgbFileName is None:
raise ValueError('cannot find rgb file') raise ValueError('cannot find rgb file')
f = file(rgbFileName, 'r') f = open(rgbFileName, 'r')
lines = f.readlines() lines = f.readlines()
f.close() f.close()
for l in lines: for l in lines: