From 46c37f1c71c45f5763d32e4bfcb9dd1ffc9779bd Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 20 Nov 2010 14:33:39 +0000 Subject: pep8 cleanup --- 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: diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index d08310f..8b2ddb3 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -29,7 +29,7 @@ import logging _logger = logging.getLogger('turtleart-activity') from sugar.activity import activity -try: # 0.86 toolbar widgets +try: # 0.86 toolbar widgets from sugar.activity.widgets import ActivityToolbarButton, StopButton,\ EditToolbar, ActivityToolbox from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton @@ -708,8 +708,7 @@ class TurtleArtActivity(activity.Activity): journal_toolbar = gtk.Toolbar() journal_toolbar_button = ToolbarButton(page=journal_toolbar, - icon_name='activity-journal') - + icon_name='activity-journal') # Add the toolbars and buttons to the toolbox activity_toolbar_button.show() toolbox.toolbar.insert(activity_toolbar_button, -1) diff --git a/turtleart.py b/turtleart.py index 2ad69b2..d3a0f70 100755 --- a/turtleart.py +++ b/turtleart.py @@ -39,12 +39,12 @@ except ImportError, e: print "Import Error: %s. Project upload is disabled." % (e) _UPLOAD_AVAILABLE = False -try: +try: # Try to use XDG Base Directory standard for config files import xdg.BaseDirectory CONFIG_HOME = os.path.join(xdg.BaseDirectory.xdg_config_home, 'turtleart') except ImportError, e: - # Default to `.config` per the spec. + # Default to `.config` per the spec. CONFIG_HOME = os.path.expanduser(os.path.join('~', '.config', 'turtleart')) argv = sys.argv[:] # Workaround for import behavior of gst in tagplay @@ -59,7 +59,7 @@ from TurtleArt.taexporthtml import save_html from TurtleArt.taexportlogo import save_logo _HELP_MSG = 'turtleart.py: ' + _('usage is') + """ - \tturtleart.py + \tturtleart.py \tturtleart.py project.ta \tturtleart.py --output_png project.ta \tturtleart.py -o project""" @@ -79,7 +79,9 @@ def mkdir_p(path): except OSError as exc: if exc.errno == errno.EEXIST: pass - else: raise + else: + raise + def _make_sub_menu(menu, name): """ add a new submenu to the toolbar """ @@ -116,8 +118,8 @@ class TurtleMain(): def __init__(self): """ Parse command-line options and initialize class """ - # If we are invoked to start a project from Gnome, we should make - # sure our current directory is TA's source dir. + # If we are invoked to start a project from Gnome, we should make + # sure our current directory is TA's source dir. os.chdir(os.path.dirname(__file__)) self.ta_file = None @@ -160,8 +162,8 @@ class TurtleMain(): # make sure Sugar paths are present tapath = os.path.join(os.environ['HOME'], '.sugar', 'default', 'org.laptop.TurtleArtActivity') - map (makepath, (os.path.join(tapath, 'data/'), - os.path.join(tapath, 'instance/'))) + map(makepath, (os.path.join(tapath, 'data/'), + os.path.join(tapath, 'instance/'))) if self.output_png: pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, @@ -176,13 +178,13 @@ class TurtleMain(): except IOError: # Opening the config file failed # We'll assume it needs to be created - try: + try: mkdir_p(CONFIG_HOME) data_file = open(os.path.join(CONFIG_HOME, 'turtleartrc'), 'a+') except IOError, e: - # We can't write to the configuration file, use - # a faux file that will persist for the length of + # We can't write to the configuration file, use + # a faux file that will persist for the length of # the session. print _('Configuration directory not writable: %s') % (e) data_file = cStringIO.StringIO() @@ -326,7 +328,7 @@ class TurtleMain(): """ Dialog for save project """ dlg = gtk.MessageDialog(parent=None, type=gtk.MESSAGE_INFO, buttons=gtk.BUTTONS_OK_CANCEL, - message_format=\ + message_format= \ _('You have unsaved work. Would you like to save before quitting?')) dlg.set_title(_('Save project?')) dlg.set_property('skip-taskbar-hint', False) @@ -596,7 +598,7 @@ http://turtleartsite.sugarlabs.org to upload your project.')) self.Hbox5.add(self.cancel_button) self.pop_up.show_all() - + def _stop_uploading(self, widget, event=None): """ Hide the popup when the upload is complte """ self.uploading = False @@ -606,9 +608,9 @@ http://turtleartsite.sugarlabs.org to upload your project.')) """ Log into the upload server """ username = self.username_entry.get_text() password = self.password_entry.get_text() - server=xmlrpclib.ServerProxy(_UPLOAD_SERVER + '/call/xmlrpc') - logged_in = server.login_remote(username,password) - if logged_in: + server = xmlrpclib.ServerProxy(_UPLOAD_SERVER + '/call/xmlrpc') + logged_in = server.login_remote(username, password) + if logged_in: upload_key = logged_in self._do_submit_to_web(upload_key) else: @@ -641,7 +643,7 @@ http://turtleartsite.sugarlabs.org to upload your project.')) ('small_image', (c.FORM_FILE, imagefile)), ('title', title), ('description', description), - ('upload_key',key), ('_formname', + ('upload_key', key), ('_formname', 'image_create')]) c.perform() error_code = c.getinfo(c.HTTP_CODE) -- cgit v0.9.1