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
|
First workingish version
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os, re, types
|
import os, re
|
||||||
import ConfigParser
|
import configparser
|
||||||
|
|
||||||
charset_start = None
|
charset_start = None
|
||||||
charset_width = None
|
charset_width = None
|
||||||
pattern_start = None
|
pattern_start = None
|
||||||
|
|
||||||
import pywmgeneral
|
import wmdocklib.pywmgeneral as pywmgeneral
|
||||||
defaultRGBFileList = [
|
defaultRGBFileList = [
|
||||||
'/etc/X11/rgb.txt',
|
'/etc/X11/rgb.txt',
|
||||||
'/usr/lib/X11/rgb.txt',
|
'/usr/lib/X11/rgb.txt',
|
||||||
@ -55,10 +55,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.')
|
||||||
@ -75,7 +75,7 @@ def getCenterStartPos(s, areaWidth, offset):
|
|||||||
"""Get the x starting position if we want to paint s centred."""
|
"""Get the x starting position if we want to paint s centred."""
|
||||||
w = len(s) * char_width
|
w = len(s) * char_width
|
||||||
textArea = areaWidth - offset * 2 - 1
|
textArea = areaWidth - offset * 2 - 1
|
||||||
return (textArea - w) / 2
|
return (textArea - w) // 2
|
||||||
|
|
||||||
def addChar(ch, x, y, xOffset, yOffset, width, height, drawable=None):
|
def addChar(ch, x, y, xOffset, yOffset, width, height, drawable=None):
|
||||||
"""Paint the character ch at position x, y in the window.
|
"""Paint the character ch at position x, y in the window.
|
||||||
@ -102,7 +102,7 @@ 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 = (pos // linelength) * char_height + charset_start
|
||||||
chX = pos % linelength
|
chX = pos % linelength
|
||||||
targX = x + xOffset
|
targX = x + xOffset
|
||||||
targY = y + yOffset
|
targY = y + yOffset
|
||||||
@ -131,7 +131,7 @@ def getVertSpacing(numLines, margin, height, yOffset):
|
|||||||
|
|
||||||
margin is the space we want between the first line and the top."""
|
margin is the space we want between the first line and the top."""
|
||||||
h = height - (numLines * char_height + 1) - yOffset * 2 - margin
|
h = height - (numLines * char_height + 1) - yOffset * 2 - margin
|
||||||
return h / (numLines - 1)
|
return h // (numLines - 1)
|
||||||
|
|
||||||
|
|
||||||
def readXPM(fileName):
|
def readXPM(fileName):
|
||||||
@ -145,7 +145,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')
|
with open(fileName, 'r') as f:
|
||||||
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 = []
|
||||||
@ -260,7 +260,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):
|
||||||
@ -329,7 +329,7 @@ def initPixmap(background=None,
|
|||||||
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
|
||||||
|
|
||||||
@ -364,10 +364,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
|
||||||
|
|
||||||
@ -436,9 +436,8 @@ 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')
|
with open(rgbFileName, 'r') as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
f.close()
|
|
||||||
for l in lines:
|
for l in lines:
|
||||||
if l[0] != '!':
|
if l[0] != '!':
|
||||||
words = l.split()
|
words = l.split()
|
||||||
|
Loading…
Reference in New Issue
Block a user