From 46c37f1c71c45f5763d32e4bfcb9dd1ffc9779bd Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 20 Nov 2010 14:33:39 +0000 Subject: pep8 cleanup --- (limited to 'TurtleArt') diff --git a/TurtleArt/sprites.py b/TurtleArt/sprites.py index 9b12cdd..fdcd72f 100644 --- a/TurtleArt/sprites.py +++ b/TurtleArt/sprites.py @@ -100,7 +100,7 @@ class Sprites: def get_sprite(self, i): """ Return a sprint from the array """ - if i < 0 or i > len(self.list)-1: + if i < 0 or i > len(self.list) - 1: return(None) else: return(self.list[i]) @@ -368,14 +368,14 @@ class Sprite: x = int(self.rect.x + self._margins[0] + (my_width - w) / 2) elif self._horiz_align[i] == 'left': x = int(self.rect.x + self._margins[0]) - else: # right + else: # right x = int(self.rect.x + self.rect.width - w - self._margins[2]) h = pl.get_size()[1] / pango.SCALE if self._vert_align[i] == "middle": y = int(self.rect.y + self._margins[1] + (my_height - h) / 2) elif self._vert_align[i] == "top": y = int(self.rect.y + self._margins[1]) - else: # bottom + else: # bottom y = int(self.rect.y + self.rect.height - h - self._margins[3]) self._sprites.gc.set_foreground(self._color) self._sprites.area.draw_layout(self._sprites.gc, x, y, pl) diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py index 2df89c4..ae0856b 100644 --- a/TurtleArt/tablock.py +++ b/TurtleArt/tablock.py @@ -53,7 +53,7 @@ class Blocks: self.decimal_point = decimal_point def get_block(self, i): - if i < 0 or i > len(self.list)-1: + if i < 0 or i > len(self.list) - 1: return(None) else: return(self.list[i]) @@ -130,7 +130,7 @@ class Block: """ A class for the individual blocks """ def __init__(self, block_list, sprite_list, name, x, y, type='block', - values=[], scale=BLOCK_SCALE, colors=["#FF0000", "#A00000"]): + values=[], scale=BLOCK_SCALE, colors=['#FF0000', '#A00000']): self.block_list = block_list self.spr = None self.shapes = [None, None] @@ -194,7 +194,7 @@ class Block: return dx = (self.spr.label_width() - self.spr.label_safe_width()) / \ self.scale - if dx !=0: + if dx != 0: self.dx += dx if self.dx < 0: self.dx = 0 @@ -299,7 +299,7 @@ class Block: self.svg.set_hide(False) if self.type == 'block': self.svg.set_show(True) - else: # 'proto' + else: # 'proto' self.svg.set_show(False) self.refresh() return dy @@ -378,18 +378,18 @@ class Block: if self.name in CONTENT_BLOCKS: n = len(self.values) if n == 0: - n = 1 # Force a scale to be set, even if there is no value. + n = 1 # Force a scale to be set, even if there is no value. else: if self.name in BLOCK_NAMES: n = len(BLOCK_NAMES[self.name]) else: - _logger.debug("WARNING: unknown block name %s" % (self.name)) + _logger.debug('WARNING: unknown block name %s' % (self.name)) n = 0 for i in range(n): - if i == 1: # top + if i == 1: # top self.spr.set_label_attributes(int(self._font_size[1] + 0.5), True, 'right', 'top', i) - elif i == 2: # bottom + elif i == 2: # bottom self.spr.set_label_attributes(int(self._font_size[1] + 0.5), True, 'right', 'bottom', i) else: diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py index c527f0e..3e4dcf6 100644 --- a/TurtleArt/tacanvas.py +++ b/TurtleArt/tacanvas.py @@ -115,7 +115,7 @@ class TurtleGraphics: self.fgcolor = self.cm.alloc_color('red') self.bgrgb = [255, 248, 222] self.bgcolor = self.cm.alloc_color('#fff8de') - self.textsize = 48 # depreciated + self.textsize = 48 # depreciated self.textcolor = self.cm.alloc_color('blue') self.tw.active_turtle.show() self.shade = 0 @@ -410,7 +410,7 @@ class TurtleGraphics: return self.set_textcolor() - def settextsize(self, c): # depreciated + def settextsize(self, c): # depreciated """ Set the text size """ try: self.tw.textsize = c @@ -526,7 +526,7 @@ class TurtleGraphics: self.canvas.images[0].draw_layout(self.gc, int(x), int(y), pl) w, h = pl.get_pixel_size() self.invalt(x, y, w, h) - else: # pixmap doesn't support pango + else: # pixmap doesn't support pango message = str(label).replace('\0', ' ') context = self.canvas.images[0].cairo_create() context.set_font_size(size) @@ -551,7 +551,7 @@ class TurtleGraphics: miny, maxy = y1, y2 else: miny, maxy = y2, y1 - w, h = maxx-minx, maxy-miny + w, h = maxx - minx, maxy - miny self.canvas.images[0].draw_line(self.gc, x1, y1, x2, y2) if self.fill and self.poly_points == []: self.poly_points.append((x1, y1)) @@ -571,8 +571,8 @@ class TurtleGraphics: x, y = self.width / 2 + int(self.xcor), \ self.height / 2 - int(self.ycor) self.tw.active_turtle.move( - (int(self.cx + x - self.tw.active_turtle.spr.rect.width/2), - int(self.cy + y - self.tw.active_turtle.spr.rect.height/2))) + (int(self.cx + x - self.tw.active_turtle.spr.rect.width / 2), + int(self.cy + y - self.tw.active_turtle.spr.rect.height / 2))) def invalt(self, x, y, w, h): """ Mark a region for refresh """ diff --git a/TurtleArt/tajail.py b/TurtleArt/tajail.py index 6d6c293..081248f 100644 --- a/TurtleArt/tajail.py +++ b/TurtleArt/tajail.py @@ -29,17 +29,17 @@ from math import * def myfunc(f, args): # check to make sure no import calls are made if len(args) == 1: - myf = "def f(x): return " + f.replace("import","") + myf = 'def f(x): return ' + f.replace('import', '') userdefined = {} exec myf in globals(), userdefined return userdefined.values()[0](args[0]) elif len(args) == 2: - myf = "def f(x,y): return " + f.replace("import","") + myf = 'def f(x, y): return ' + f.replace('import', '') userdefined = {} exec myf in globals(), userdefined return userdefined.values()[0](args[0], args[1]) elif len(args) == 3: - myf = "def f(x,y,z): return " + f.replace("import","") + myf = 'def f(x, y, z): return ' + f.replace('import', '') userdefined = {} exec myf in globals(), userdefined return userdefined.values()[0](args[0], args[1], args[2]) diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 7a717d4..5dcbd8d 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -310,7 +310,8 @@ class LogoCode: DEFPRIM = { '(': [1, lambda self, x: self._prim_opar(x)], 'and': [2, lambda self, x, y: _and(x, y)], - 'arc': [2, lambda self, x, y: self._prim_arc(self.tw.canvas.arc, x, y)], + 'arc': [2, lambda self, x, y: self._prim_arc(self.tw.canvas.arc, x, + y)], 'audio': [1, lambda self, x: self._play_sound(x)], 'back': [1, lambda self, x: self._prim_move(self.tw.canvas.forward, -x)], @@ -333,7 +334,7 @@ class LogoCode: 'cyan': [0, lambda self: CONSTANTS['cyan']], 'define': [2, self._prim_define], 'division': [2, lambda self, x, y: _careful_divide(x, y)], - 'equal?': [2, lambda self,x, y: _equal(x, y)], + 'equal?': [2, lambda self, x, y: _equal(x, y)], 'fillscreen': [2, lambda self, x, y: self.tw.canvas.fillscreen(x, y)], 'forever': [1, self._prim_forever, True], 'forward': [1, lambda self, x: self._prim_move(self.tw.canvas.forward, @@ -407,11 +408,11 @@ class LogoCode: 'settextsize': [1, lambda self, x: self.tw.canvas.settextsize(x)], 'setxy2': [2, lambda self, x, y: self._prim_move(self.tw.canvas.setxy, x, y)], - 'setxy': [2, lambda self, x, y: self._prim_move(self.tw.canvas.setxy, x, - y, pendown=False)], + 'setxy': [2, lambda self, x, y: self._prim_move(self.tw.canvas.setxy, + x, y, pendown=False)], 'shade': [0, lambda self: self.tw.canvas.shade], 'show': [1, lambda self, x: self._show(x, True)], - 'showaligned': [1,lambda self, x: self._show(x, False)], + 'showaligned': [1, lambda self, x: self._show(x, False)], 'showblocks': [0, lambda self: self.tw.showblocks()], 'skin': [1, lambda self, x: self._reskin(x)], 'sound': [0, lambda self: self._get_sound()], @@ -566,11 +567,11 @@ class LogoCode: return ['%nothing%', '%nothing%'] code = [] dock = blk.docks[0] - if len(dock) > 4: # There could be a '(', ')', '[' or ']'. + if len(dock) > 4: # There could be a '(', ')', '[' or ']'. code.append(dock[4]) if blk.name == 'savesvg': self.tw.saving_svg = True - if blk.primitive is not None: # make a tuple (prim, blk) + if blk.primitive is not None: # make a tuple (prim, blk) code.append((blk.primitive, self.tw.block_list.list.index(blk))) elif len(blk.values) > 0: # Extract the value from content blocks. if blk.name == 'number': @@ -613,7 +614,7 @@ class LogoCode: for i in range(1, len(blk.connections)): b = blk.connections[i] dock = blk.docks[i] - if len(dock) > 4: # There could be a '(', ')', '[' or ']'. + if len(dock) > 4: # There could be a '(', ')', '[' or ']'. for c in dock[4]: code.append(c) if b is not None: @@ -625,7 +626,7 @@ class LogoCode: def _setup_cmd(self, string): """ Execute the psuedocode. """ self.hidden_turtle = self.tw.active_turtle - self.hidden_turtle.hide() # Hide the turtle while we are running. + self.hidden_turtle.hide() # Hide the turtle while we are running. self.procstop = False blklist = self._readline(string) self.step = self._start_eval(blklist) @@ -1124,7 +1125,7 @@ class LogoCode: elif self.update_values: if type(value) == float: valstring = str(round_int(value)).replace('.', - self.tw.decimal_point) + self.tw.decimal_point) else: valstring = str(value) for block in self.value_blocks[name]: @@ -1147,7 +1148,7 @@ class LogoCode: else: # print cmd, value1, value2, pendown cmd(float(value1), float(value2), pendown=pendown) - self.update_label_value('xcor', + self.update_label_value('xcor', self.tw.canvas.xcor / self.tw.coord_scale) self.update_label_value('ycor', self.tw.canvas.ycor / self.tw.coord_scale) @@ -1156,7 +1157,7 @@ class LogoCode: def _prim_arc(self, cmd, value1, value2): cmd(float(value1), float(value2)) - self.update_label_value('xcor', + self.update_label_value('xcor', self.tw.canvas.xcor / self.tw.coord_scale) self.update_label_value('ycor', self.tw.canvas.ycor / self.tw.coord_scale) @@ -1418,7 +1419,7 @@ class LogoCode: """ Read r, g, b from the canvas and return a corresponding palette color """ r, g, b, a = self.tw.canvas.get_pixel() - color_index = self.tw.canvas.get_color_index(r, g, b) + color_index = self.tw.canvas.get_color_index(r, g, b) self.update_label_value('see', color_index) return color_index @@ -1460,7 +1461,7 @@ class LogoCode: for j in rfft(buf): r.append(abs(j)) # Convert output to Hertz - pitch = r.index(max(r)) * 48000 / len(buf) + pitch = r.index(max(r)) * 48000 / len(buf) self.update_label_value('pitch', pitch) return pitch else: -- cgit v0.9.1