From db528ec468767ce5ed9d4aac4a37a5f8f01ff60f Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Mon, 09 Apr 2012 13:08:36 +0000 Subject: pep8 cleanup --- diff --git a/TurtleArt/sprites.py b/TurtleArt/sprites.py index 081b456..c400d88 100644 --- a/TurtleArt/sprites.py +++ b/TurtleArt/sprites.py @@ -83,6 +83,7 @@ import pango import pangocairo import cairo + class Sprites: ''' A class for the list of sprites and everything they share in common ''' @@ -402,14 +403,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]) cr.save() cr.translate(x, y) @@ -454,16 +455,13 @@ class Sprite: if x < 0 or x > (self.rect.width - 1) or \ y < 0 or y > (self.rect.height - 1): return(-1, -1, -1, -1) - - # create a new 1x1 cairo surface - cs = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1); + # Create a new 1x1 cairo surface. + cs = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1) cr = cairo.Context(cs) cr.set_source_surface(self.cached_surfaces[i], -x, -y) - cr.rectangle(0,0,1,1) + cr.rectangle(0, 0, 1, 1) cr.set_operator(cairo.OPERATOR_SOURCE) cr.fill() - cs.flush() # ensure all writing is done - # Read the pixel - pixels = cs.get_data() + cs.flush() # Ensure all the writing is done. + pixels = cs.get_data() # Read the pixel. return (ord(pixels[2]), ord(pixels[1]), ord(pixels[0]), 0) - diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py index fee1b12..b75522a 100644 --- a/TurtleArt/tabasics.py +++ b/TurtleArt/tabasics.py @@ -69,6 +69,7 @@ from talogo import primitive_dictionary, logoerror from tautils import convert, chr_to_ord, round_int, strtype from taconstants import BLACK, WHITE, CONSTANTS, XO30 + def _num_type(x): """ Is x a number type? """ if type(x) == int: @@ -416,8 +417,8 @@ in place of a number block)'), palette.add_block('gray', style='box-style', label=_('gray'), - help_string=_('holds current gray level (can be used \ -in place of a number block)'), + help_string=_('holds current gray level (can be \ +used in place of a number block)'), value_block=True, prim_name='gray') self.tw.lc.def_prim('gray', 0, lambda self: self.tw.canvas.gray) @@ -560,8 +561,8 @@ tasetshade :shade \r') top numeric input')) self.tw.lc.def_prim( 'minus', 2, lambda self, x, y: primitive_dictionary['minus'](x, y)) - define_logo_function('taminus', 'to taminus :y :x\routput sum :x minus \ -:y\rend\r') + define_logo_function('taminus', 'to taminus :y :x\routput sum :x \ +minus :y\rend\r') primitive_dictionary['product'] = self._prim_product palette.add_block('product2', @@ -582,8 +583,8 @@ top numeric input')) special_name=_('divide'), prim_name='division', logo_command='quotient', - help_string=_('divides top numeric input (numerator) \ -by bottom numeric input (denominator)')) + help_string=_('divides top numeric input \ +(numerator) by bottom numeric input (denominator)')) self.tw.lc.def_prim( 'division', 2, lambda self, x, y: primitive_dictionary['division'](x, y)) @@ -628,8 +629,8 @@ blocks')) default=[0, 100], prim_name='random', logo_command='tarandom', - help_string=_('returns random number between minimum \ -(top) and maximum (bottom) values')) + help_string=_('returns random number between \ +minimum (top) and maximum (bottom) values')) self.tw.lc.def_prim( 'random', 2, lambda self, x, y: primitive_dictionary['random']( x, y)) @@ -681,8 +682,8 @@ operators')) prim_name='equal?', logo_command='equal?', help_string=_('logical equal-to operator')) - self.tw.lc.def_prim( - 'equal?', 2, lambda self, x, y: primitive_dictionary['equal'](x, y)) + self.tw.lc.def_prim('equal?', 2, + lambda self, x, y: primitive_dictionary['equal'](x, y)) palette.add_block('not', style='not-style', @@ -740,7 +741,8 @@ number of seconds')) default=[None, 'vspace'], logo_command='forever', help_string=_('loops forever')) - self.tw.lc.def_prim('forever', 1, primitive_dictionary['forever'], True) + self.tw.lc.def_prim('forever', 1, primitive_dictionary['forever'], + True) primitive_dictionary['repeat'] = self._prim_repeat palette.add_block('repeat', diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py index b809930..f835994 100644 --- a/TurtleArt/tablock.py +++ b/TurtleArt/tablock.py @@ -512,7 +512,7 @@ class Block: if self.name in BOX_COLORS: self.colors = BOX_COLORS[self.name] elif self.name in special_block_colors: - self.colors = special_block_colors[self.name] + self.colors = special_block_colors[self.name] else: for p in range(len(palette_blocks)): if self.name in palette_blocks[p]: diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py index b52743d..6a78a17 100644 --- a/TurtleArt/tacanvas.py +++ b/TurtleArt/tacanvas.py @@ -107,7 +107,7 @@ class TurtleGraphics: self.tw = tw self.width = width self.height = height - + # Build a cairo.Context from a cairo.XlibSurface self.canvas = cairo.Context(self.tw.turtle_canvas) cr = gtk.gdk.CairoContext(self.canvas) @@ -131,7 +131,6 @@ class TurtleGraphics: def setup_svg_surface(self): ''' Set up a surface for saving to SVG ''' - debug_output('Setting up svg surface', True) if self.tw.running_sugar: svg_surface = cairo.SVGSurface( os.path.join(get_path(self.tw.activity, 'instance'), @@ -674,7 +673,8 @@ class TurtleGraphics: if self.tw.interactive_mode: 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.cy + y - self.tw.active_turtle.spr.rect.height / 2.)) + ) else: self.tw.active_turtle.move((int(self.cx + x), int(self.cy + y))) @@ -722,15 +722,14 @@ class TurtleGraphics: if x < 0 or x > (w - 1) or y < 0 or y > (h - 1): return(-1, -1, -1, -1) # create a new 1x1 cairo surface - cs = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1); + cs = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1) cr = cairo.Context(cs) cr.set_source_surface(self.tw.turtle_canvas, -x, -y) - cr.rectangle(0,0,1,1) + cr.rectangle(0, 0, 1, 1) cr.set_operator(cairo.OPERATOR_SOURCE) cr.fill() - cs.flush() # ensure all writing is done - # Read the pixel - pixels = cs.get_data() + cs.flush() # ensure all writing is done + pixels = cs.get_data() # Read the pixel return (ord(pixels[2]), ord(pixels[1]), ord(pixels[0]), 0) else: return(-1, -1, -1, -1) @@ -763,12 +762,10 @@ class TurtleGraphics: def svg_close(self): ''' Close current SVG graphic ''' - debug_output('svg_close', True) self.cr_svg.show_page() def svg_reset(self): ''' Reset svg flags ''' - debug_output('svg_reset', True) self.cr_svg = None def _get_my_nick(self): diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 66aafdb..73d0aea 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- #Copyright (c) 2007-8, Playful Invention Company. -#Copyright (c) 2008-11, Walter Bender +#Copyright (c) 2008-12, Walter Bender #Copyright (c) 2008-10, Raúl Gutiérrez Segalés #Permission is hereby granted, free of charge, to any person obtaining a copy @@ -67,6 +67,7 @@ class logoerror(Exception): def __str__(self): return repr(self.value) + class HiddenBlock: def __init__(self, name, value=None): @@ -82,6 +83,7 @@ class HiddenBlock: # Utility functions + def _just_stop(): """ yield False to stop stack """ yield False @@ -248,14 +250,6 @@ class LogoCode: dock = blk.docks[0] if len(dock) > 4: # There could be a '(', ')', '[' or ']'. code.append(dock[4]) - - ''' - if blk.name == 'savesvg': - debug_output('talogo: savesvg', True) - if self.tw.canvas.cr_svg is None: - self.tw.canvas.setup_svg_surface() - ''' - if blk.primitive is not None: # make a tuple (prim, blk) # special case: expand 'while' and 'until' primitives try: @@ -548,7 +542,7 @@ class LogoCode: def prim_clear(self): """ Clear screen """ - self.tw.clear_plugins() + self.tw.clear_plugins() if self.tw.gst_available: from tagplay import stop_media # stop_media(self) # TODO: gplay variable @@ -666,8 +660,10 @@ class LogoCode: self.y2ty() - int(h / 2), w, h, self.filepath) elif offset: - self.tw.canvas.draw_pixbuf(self.pixbuf, 0, 0, self.x2tx(), - self.y2ty() - h, w, h, self.filepath) + self.tw.canvas.draw_pixbuf(self.pixbuf, 0, 0, + self.x2tx(), + self.y2ty() - h, + w, h, self.filepath) else: self.tw.canvas.draw_pixbuf(self.pixbuf, 0, 0, self.x2tx(), @@ -739,11 +735,11 @@ class LogoCode: # into trouble if any of these block types (forever, while, # until. ifelse, stopstack, or stack) is changed in tablock.py if b.name == 'while': - while_blk = True + while_blk = True else: while_blk = False if b.name == 'until': - until_blk = True + until_blk = True else: until_blk = False @@ -855,7 +851,8 @@ class LogoCode: c = whileflow.connections[0] whileflow.connections[0] = None code = self._blocks_to_code(whileflow) - self.stacks['stack3' + str(action_flow_name)] = self._readline(code) + self.stacks['stack3' + str(action_flow_name)] = \ + self._readline(code) whileflow.connections[0] = c # Save the connections so we can restore them later diff --git a/TurtleArt/taturtle.py b/TurtleArt/taturtle.py index c13c494..c70f379 100644 --- a/TurtleArt/taturtle.py +++ b/TurtleArt/taturtle.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -#Copyright (c) 2010,11 Walter Bender +#Copyright (c) 2010,12 Walter Bender #Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal @@ -129,10 +129,10 @@ class Turtle: self._prep_shapes(key, turtles, turtle_colors) - # Choose a random angle from which to attach the turtle label + # Choose a random angle from which to attach the turtle label. if turtles.sprite_list is not None: self.spr = Sprite(turtles.sprite_list, 0, 0, self.shapes[0]) - angle = uniform(0, pi * 4 / 3.0) # 240 degrees + angle = uniform(0, pi * 4 / 3.0) # 240 degrees w = self.shapes[0].get_width() r = w * 0.67 # Restrict angle the the sides 30-150; 210-330 diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py index d3fd45e..d944118 100644 --- a/TurtleArt/tautils.py +++ b/TurtleArt/tautils.py @@ -1,5 +1,5 @@ #Copyright (c) 2007-8, Playful Invention Company. -#Copyright (c) 2008-11, Walter Bender +#Copyright (c) 2008-12, Walter Bender #Permission is hereby granted, free of charge, to any person obtaining a copy #of this software and associated documentation files (the "Software"), to deal @@ -288,13 +288,6 @@ def get_canvas_data(canvas): return img_surface.get_data() -def save_svg(string, file_name): - ''' Write a string to a file. ''' - file_handle = file(file_name, 'w') - file_handle.write(string) - file_handle.close() - - def get_pixbuf_from_journal(dsobject, w, h): ''' Load a pixbuf from a Journal object. ''' try: diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index f5bcc85..c1fa4a6 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -775,7 +775,8 @@ class TurtleArtWindow(): # Make sure all of the selectors are visible. (We don't need to do # this for 0.86+ toolbars since the selectors are toolbar buttons.) - if show and (self.activity is None or not self.activity.has_toolbarbox): + if show and \ + (self.activity is None or not self.activity.has_toolbarbox): self.selected_selector = self.selectors[n] self.selectors[n].set_shape(self.selector_shapes[n][1]) for i in range(len(palette_blocks)): @@ -783,7 +784,8 @@ class TurtleArtWindow(): # Show the palette with the current orientation. if self.palette_sprs[n][self.orientation] is not None: - self.palette_sprs[n][self.orientation].set_layer(CATEGORY_LAYER) + self.palette_sprs[n][self.orientation].set_layer( + CATEGORY_LAYER) self._display_palette_shift_button(n) # Create 'proto' blocks for each palette entry @@ -1101,11 +1103,13 @@ class TurtleArtWindow(): self.palette_button[2].move((PALETTE_WIDTH - 20, self.toolbar_offset)) if show: - self.palette_button[2].save_xy = self.palette_button[2].get_xy() + self.palette_button[2].save_xy = \ + self.palette_button[2].get_xy() if self.running_sugar and not self.hw in [XO1]: self.palette_button[2].move_relative( (self.activity.hadj_value, self.activity.vadj_value)) - self.palette_sprs[n][self.orientation].set_layer(CATEGORY_LAYER) + self.palette_sprs[n][self.orientation].set_layer( + CATEGORY_LAYER) self._display_palette_shift_button(n) def _make_palette_spr(self, n, x, y, w, h, regenerate=False): @@ -1123,11 +1127,9 @@ class TurtleArtWindow(): self.palette_sprs[n][self.orientation].move_relative( (self.activity.hadj_value, self.activity.vadj_value)) if self.orientation == 0 and w > self.width: - debug_output('setting to shiftable horizontal', True) self.palette_sprs[n][self.orientation].type = \ 'category-shift-horizontal' elif self.orientation == 1 and h > self.height - ICON_SIZE: - debug_output('setting to shiftable vertical', True) self.palette_sprs[n][self.orientation].type = \ 'category-shift-vertical' else: @@ -1155,7 +1157,8 @@ class TurtleArtWindow(): # Unselect things that may have been selected earlier if self.selected_blk is not None: - if self.selected_blk.name == 'number' and spr in self.triangle_sprs: + if self.selected_blk.name == 'number' and \ + spr in self.triangle_sprs: # increment or decrement a number block nf = float(self.selected_blk.spr.labels[0].replace(CURSOR, '')) ni = int(nf) @@ -1513,7 +1516,6 @@ class TurtleArtWindow(): newblk.connections[i + 1] = argblk self.drag_group = find_group(newblk) self.block_operation = 'new' - debug_output(newblk.name, True) if len(newblk.spr.labels) > 0 and newblk.spr.labels[0] is not None \ and newblk.name not in ['', 'number', 'string']: if len(self.used_block_list) > 0: @@ -2197,12 +2199,8 @@ class TurtleArtWindow(): self.lc.find_value_blocks() # Are there blocks to update? # Is there a savesvg block? if len(self.block_list.get_similar_blocks('block', 'savesvg')) > 0: - debug_output('savesvg block found!', True) if self.canvas.cr_svg is None: self.canvas.setup_svg_surface() - debug_output(self.canvas.cr_svg, True) - else: - debug_output('no savesvg blocks found', True) self._start_plugins() # Let the plugins know we are running. top = find_top_block(blk) self.lc.run_blocks(top, self.just_blocks(), True) @@ -2275,7 +2273,8 @@ class TurtleArtWindow(): if best_destination_dockn == 2 and \ (selected_block.name in block_styles['boolean-style'] or \ selected_block.name in block_styles['compare-style'] or \ - selected_block.name in block_styles['compare-porch-style']): + selected_block.name in block_styles['compare-porch-style'] + ): dy = selected_block.ey - best_destination.ey if selected_block.name in block_styles['boolean-style']: # Even without expanding, boolean blocks are @@ -2698,7 +2697,6 @@ class TurtleArtWindow(): else: n = 0 self.selected_blk.spr.set_label(str(n)) - debug_output(str(n), True) try: self.selected_blk.values[0] = \ float(str(n).replace(self.decimal_point, '.')) diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index efebb96..c6c00b9 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -1076,7 +1076,7 @@ in order to use the plugin.')) tmp_dir = tempfile.mkdtemp() - if True: # try: + try: tar_fd.extractall(tmp_dir) if not plugin: # Looking for a .ta file @@ -1087,10 +1087,10 @@ in order to use the plugin.')) self.tw.load_files(turtle_code, run_it) else: self._load_a_plugin(tmp_dir) - else: # except: + except: _logger.debug('Could not extract files from %s.' % ( file_path)) - if True: # finally: + finally: if not plugin: shutil.rmtree(tmp_dir) tar_fd.close() -- cgit v0.9.1