ported pywmgeneral to python3
This commit is contained in:
parent
d4d7fdf761
commit
667724990c
@ -26,14 +26,14 @@ Some changes to handle the additional event handling in pywmgeneral
|
||||
First workingish version
|
||||
"""
|
||||
|
||||
import os, re, types
|
||||
import ConfigParser
|
||||
import os, re
|
||||
import configparser
|
||||
|
||||
charset_start = None
|
||||
charset_width = None
|
||||
pattern_start = None
|
||||
|
||||
import pywmgeneral
|
||||
import wmdocklib.pywmgeneral as pywmgeneral
|
||||
defaultRGBFileList = [
|
||||
'/etc/X11/rgb.txt',
|
||||
'/usr/lib/X11/rgb.txt',
|
||||
@ -55,10 +55,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.')
|
||||
@ -75,7 +75,7 @@ def getCenterStartPos(s, areaWidth, offset):
|
||||
"""Get the x starting position if we want to paint s centred."""
|
||||
w = len(s) * char_width
|
||||
textArea = areaWidth - offset * 2 - 1
|
||||
return (textArea - w) / 2
|
||||
return (textArea - w) // 2
|
||||
|
||||
def addChar(ch, x, y, xOffset, yOffset, width, height, drawable=None):
|
||||
"""Paint the character ch at position x, y in the window.
|
||||
@ -102,13 +102,13 @@ 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
|
||||
chY = (pos // linelength) * char_height + charset_start
|
||||
chX = pos % linelength
|
||||
targX = x + xOffset
|
||||
targY = y + yOffset
|
||||
chW = char_width
|
||||
if ch in "',.:;":
|
||||
chW = char_twidth
|
||||
chW =char_twidth
|
||||
if drawable is None:
|
||||
pywmgeneral.copyXPMArea(chX, chY, chW, char_height, targX, targY)
|
||||
else:
|
||||
@ -131,7 +131,7 @@ def getVertSpacing(numLines, margin, height, yOffset):
|
||||
|
||||
margin is the space we want between the first line and the top."""
|
||||
h = height - (numLines * char_height + 1) - yOffset * 2 - margin
|
||||
return h / (numLines - 1)
|
||||
return h // (numLines - 1)
|
||||
|
||||
|
||||
def readXPM(fileName):
|
||||
@ -145,7 +145,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')
|
||||
with open(fileName, 'r') as f:
|
||||
lines = [l.rstrip('\n') for l in f.readlines()]
|
||||
s = ''.join(lines)
|
||||
res = []
|
||||
@ -260,7 +260,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):
|
||||
@ -329,7 +329,7 @@ def initPixmap(background=None,
|
||||
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
|
||||
|
||||
@ -364,10 +364,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
|
||||
|
||||
@ -436,9 +436,8 @@ def getColorCode(colorName, rgbFileName=None):
|
||||
if rgbFileName is None:
|
||||
raise ValueError('cannot find rgb file')
|
||||
|
||||
f = file(rgbFileName, 'r')
|
||||
with open(rgbFileName, 'r') as f:
|
||||
lines = f.readlines()
|
||||
f.close()
|
||||
for l in lines:
|
||||
if l[0] != '!':
|
||||
words = l.split()
|
||||
|
Loading…
Reference in New Issue
Block a user