From 5584e23940e867d4c53c3d649e8768b74c16f503 Mon Sep 17 00:00:00 2001 From: Frederic Date: Wed, 21 Dec 2016 22:19:27 +0100 Subject: [PATCH] some 2to3 --- blmplay.py | 30 +++++++++++++++--------------- blup/animation.py | 11 +++++------ colorwischer.py | 29 +++++++++++++++-------------- writebml.py | 2 +- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/blmplay.py b/blmplay.py index 88474ad..8c75f5e 100644 --- a/blmplay.py +++ b/blmplay.py @@ -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(): 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(): 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(): 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() diff --git a/blup/animation.py b/blup/animation.py index 3a39fe6..9bfd54c 100644 --- a/blup/animation.py +++ b/blup/animation.py @@ -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): 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): 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): 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)] diff --git a/colorwischer.py b/colorwischer.py index ee0b252..c54ceb3 100644 --- a/colorwischer.py +++ b/colorwischer.py @@ -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 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) diff --git a/writebml.py b/writebml.py index f81e590..abe230d 100644 --- a/writebml.py +++ b/writebml.py @@ -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()