Browse Source

some 2to3

master
Fr3deric 8 years ago committed by Frederic
parent
commit
5584e23940
  1. 30
      blmplay.py
  2. 11
      blup/animation.py
  3. 29
      colorwischer.py
  4. 2
      writebml.py

30
blmplay.py

@ -8,13 +8,13 @@ import blup.output @@ -8,13 +8,13 @@ import blup.output
def printUsage(errMsg=None):
if errMsg is not None:
print 'error: %s\n' % (errMsg)
print 'usage: %s [OPTIONS] FILENAME' % (sys.argv[0])
print 'supported options:'
print ' -o OUTPUT where to output the frames (default: shell)'
print ' --output OUTPUT\n'
print ' -h print this text'
print ' --help'
print('error: %s\n' % (errMsg))
print('usage: %s [OPTIONS] FILENAME' % (sys.argv[0]))
print('supported options:')
print(' -o OUTPUT where to output the frames (default: shell)')
print(' --output OUTPUT\n')
print(' -h print this text')
print(' --help')
def main():
try:
@ -24,13 +24,13 @@ def main(): @@ -24,13 +24,13 @@ def main():
printUsage(e.msg)
sys.exit(1)
if opts.has_key('--help'):
if '--help' in opts:
printUsage()
sys.exit(0)
if opts.has_key('-o'):
if '-o' in opts:
output = opts['-o']
elif opts.has_key('--output'):
elif '--output' in opts:
output = opts['--output']
else:
output = 'shell'
@ -38,12 +38,12 @@ def main(): @@ -38,12 +38,12 @@ def main():
try:
out = blup.output.getOutput(output)
except blup.output.IllegalOutputSpecificationError:
print 'illegal output specification'
print 'available outputs:'
print blup.output.getOutputDescriptions()
print('illegal output specification')
print('available outputs:')
print(blup.output.getOutputDescriptions())
sys.exit(1)
except Exception as e:
print 'could not initialize output: %s' % (str(e))
print('could not initialize output: %s' % (str(e)))
sys.exit(1)
if len(args) != 2:
@ -53,7 +53,7 @@ def main(): @@ -53,7 +53,7 @@ def main():
try:
anim = blup.animation.load(args[1])
except blup.animation.AnimationFileError:
print 'could not load animation'
print('could not load animation')
sys.exit(1)
player = blup.animation.AnimationPlayer()

11
blup/animation.py

@ -8,8 +8,8 @@ import re @@ -8,8 +8,8 @@ import re
import time
import xml.etree.ElementTree as ET
from frame import Frame
from frame import FrameDimension
from blup.frame import Frame
from blup.frame import FrameDimension
class AnimationFileError(Exception):
@ -38,7 +38,7 @@ class AnimationIterator(object): @@ -38,7 +38,7 @@ class AnimationIterator(object):
self.__animation = animation
self.__pos = 0
def next(self):
def __next__(self):
""" Return the next frame (if available). """
if self.__pos >= len(self.__animation):
raise StopIteration
@ -191,7 +191,6 @@ def loadBlm(filename): @@ -191,7 +191,6 @@ def loadBlm(filename):
frm = AnimationFrame(FrameDimension(w, h, 2, 1),
delay=framedelay)
frm.pixels = frame
print frame.pixels
animframes.append(frm)
frame = []
continue
@ -285,12 +284,12 @@ def loadBml(filename): @@ -285,12 +284,12 @@ def loadBml(filename):
charsPerPixel *= 2
rowPixels = []
for i in xrange(0, width * charsPerPixel, charsPerPixel):
for i in range(0, width * charsPerPixel, charsPerPixel):
if channels == 1:
pixel = row.text[i:(i + charsPerPixel)]
rowPixels.append(int(pixel, 16))
elif channels == 3:
charsPerColor = charsPerPixel / 3
charsPerColor = charsPerPixel // 3
r = row.text[i:(i + charsPerColor)]
g = row.text[(i + charsPerColor):(i + 2*charsPerColor)]
b = row.text[(i + 2*charsPerColor):(i + charsPerPixel)]

29
colorwischer.py

@ -7,7 +7,7 @@ import blup.frame @@ -7,7 +7,7 @@ import blup.frame
import writebml
import random
dim = blup.frame.FrameDimension(18, 8, 16, 3)
dim = blup.frame.FrameDimension(22, 16, 256, 3)
newanim = blup.animation.Animation(dim)
@ -15,19 +15,20 @@ num = 10 @@ -15,19 +15,20 @@ num = 10
horiz = True
delay = 100
for i in range(num):
newcolor = (random.randint(0, 15), random.randint(0, 15), random.randint(0, 15))
horiz = not horiz
newframe = blup.animation.AnimationFrame(dim, delay)
if horiz:
for x in range(dim.size()[0]):
for y in range(dim.size()[1]):
newframe.setPixel(x, y, newcolor)
newanim.addFrame(newframe)
else:
for y in range(dim.size()[1]):
for x in range(dim.size()[0]):
newframe.setPixel(x, y, newcolor)
newanim.addFrame(newframe)
newcolor = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
horiz = not horiz
if horiz:
for x in range(dim.size()[0]):
newframe = blup.animation.AnimationFrame(dim, delay)
for y in range(dim.size()[1]):
newframe.setPixel(x, y, newcolor)
newanim.addFrame(newframe)
else:
for y in range(dim.size()[1]):
newframe = blup.animation.AnimationFrame(dim, delay)
for x in range(dim.size()[0]):
newframe.setPixel(x, y, newcolor)
newanim.addFrame(newframe)

2
writebml.py

@ -42,7 +42,7 @@ def writeBml(anim, filename): @@ -42,7 +42,7 @@ def writeBml(anim, filename):
frame.append(row)
root.append(frame)
f = open(filename, 'w')
f = open(filename, 'wb')
ET.ElementTree(root).write(f)
f.close()

Loading…
Cancel
Save