Browse Source

some 2to3

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

11
blup/animation.py

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

29
colorwischer.py

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

2
writebml.py

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

Loading…
Cancel
Save