mirror of
https://github.com/gryf/wmdocklib.git
synced 2025-12-18 20:10:23 +01:00
Make pywmhelpers work on python3
This commit is contained in:
@@ -26,14 +26,16 @@ Some changes to handle the additional event handling in pywmgeneral
|
||||
First workingish version
|
||||
"""
|
||||
|
||||
import os, re, types
|
||||
import ConfigParser
|
||||
import os
|
||||
import re
|
||||
import types
|
||||
import configparser
|
||||
|
||||
charset_start = None
|
||||
charset_width = None
|
||||
pattern_start = None
|
||||
|
||||
import pywmgeneral
|
||||
from wmdocklib import pywmgeneral
|
||||
defaultRGBFileList = [
|
||||
'/etc/X11/rgb.txt',
|
||||
'/usr/lib/X11/rgb.txt',
|
||||
@@ -55,10 +57,10 @@ def readConfigFile(fileName, errOut):
|
||||
errOut.write(
|
||||
'Configuration file is not readable. Using defaults.\n')
|
||||
return {}
|
||||
cp = ConfigParser.ConfigParser()
|
||||
cp = configparser.ConfigParser()
|
||||
try:
|
||||
cp.read(fileName)
|
||||
except ConfigParser.Error, e:
|
||||
except configparser.Error as e:
|
||||
if errOut:
|
||||
errOut.write('Error in configuration file:\n')
|
||||
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
|
||||
# translate pos into chX, chY, rolling back and down each linelength
|
||||
# bits. character definition start at row 64, column 0.
|
||||
chY = (pos / linelength) * char_height + charset_start
|
||||
chX = pos % linelength
|
||||
targX = x + xOffset
|
||||
targY = y + yOffset
|
||||
chY = int((pos / linelength) * char_height + charset_start)
|
||||
chX = int(pos % linelength)
|
||||
targX = int(x + xOffset)
|
||||
targY = int(y + yOffset)
|
||||
chW = char_width
|
||||
if ch in "',.:;":
|
||||
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,
|
||||
drawable)
|
||||
lastW += w
|
||||
return lastW
|
||||
|
||||
def getVertSpacing(numLines, margin, height, yOffset):
|
||||
"""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
|
||||
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()]
|
||||
s = ''.join(lines)
|
||||
res = []
|
||||
@@ -218,7 +219,7 @@ def initPixmap(background=None,
|
||||
palette, background = readXPM(background)
|
||||
|
||||
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)
|
||||
available['%x'%index] = False
|
||||
palette[' '] = 'None'
|
||||
@@ -229,7 +230,7 @@ def initPixmap(background=None,
|
||||
if alter_palette is not None:
|
||||
# alter_palette contains 0..15/chr -> 'name'/'#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):
|
||||
k = '%x' % k
|
||||
k = k[0]
|
||||
@@ -261,7 +262,7 @@ def initPixmap(background=None,
|
||||
] + [
|
||||
' '*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)]
|
||||
for ((left, top),(right, bottom)) in background:
|
||||
for x in range(left, right+1):
|
||||
@@ -293,7 +294,7 @@ def initPixmap(background=None,
|
||||
thinwidth = int(m.groupdict().get('t') or width)
|
||||
|
||||
replace = []
|
||||
for code, value in font_palette.items():
|
||||
for code, value in list(font_palette.items()):
|
||||
if available[code]:
|
||||
continue
|
||||
if palette[code] != font_palette[code]:
|
||||
@@ -301,7 +302,7 @@ def initPixmap(background=None,
|
||||
available[newcode] = False
|
||||
replace.append((code, newcode))
|
||||
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)
|
||||
font_palette[newcode] = 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)]
|
||||
|
||||
new_font_palette = {}
|
||||
for k, colorName in font_palette.items():
|
||||
for k, colorName in list(font_palette.items()):
|
||||
if colorName == 'None':
|
||||
continue
|
||||
origColor = getColorCode(colorName)[1:]
|
||||
origRgb = [int(origColor[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])
|
||||
new_font_palette[k] = '#'+''.join(["%02x"% int(i) for i in newRgb])
|
||||
|
||||
return new_font_palette
|
||||
|
||||
@@ -351,11 +352,11 @@ def initPixmap(background=None,
|
||||
'%s %s %d 1' % (xpmwidth, xpmheight, len(palette)),
|
||||
] + [
|
||||
'%s\tc %s' % (k,v)
|
||||
for k,v in palette.items()
|
||||
for k,v in list(palette.items())
|
||||
if v == 'None'
|
||||
] + [
|
||||
'%s\tc %s' % (k,v)
|
||||
for k,v in palette.items()
|
||||
for k,v in list(palette.items())
|
||||
if v != 'None'
|
||||
] + [
|
||||
item+' '*(xpmwidth-len(item))
|
||||
@@ -365,10 +366,10 @@ def initPixmap(background=None,
|
||||
for line in fontdef
|
||||
]
|
||||
if debug:
|
||||
print '/* XPM */\nstatic char *_x_[] = {'
|
||||
print('/* XPM */\nstatic char *_x_[] = {')
|
||||
for item in xpm:
|
||||
print '"%s",' % item
|
||||
print '};'
|
||||
print(('"%s",' % item))
|
||||
print('};')
|
||||
pywmgeneral.includePixmap(xpm)
|
||||
return char_width, char_height
|
||||
|
||||
@@ -389,6 +390,9 @@ def redrawXY(x, y):
|
||||
|
||||
def copyXPMArea(sourceX, sourceY, width, height, targetX, targetY):
|
||||
"""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:
|
||||
pywmgeneral.copyXPMArea(sourceX, sourceY, width, height,
|
||||
targetX, targetY)
|
||||
@@ -437,7 +441,7 @@ def getColorCode(colorName, rgbFileName=None):
|
||||
if rgbFileName is None:
|
||||
raise ValueError('cannot find rgb file')
|
||||
|
||||
f = file(rgbFileName, 'r')
|
||||
f = open(rgbFileName, 'r')
|
||||
lines = f.readlines()
|
||||
f.close()
|
||||
for l in lines:
|
||||
|
||||
Reference in New Issue
Block a user