From 6f21b8133cb583901810853b478a51fe6aaea311 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 26 Feb 2011 16:48:44 +0000 Subject: pep8 cleanup --- (limited to 'pysamples') diff --git a/pysamples/copy_from_heap.py b/pysamples/copy_from_heap.py index 8483fde..1978c26 100644 --- a/pysamples/copy_from_heap.py +++ b/pysamples/copy_from_heap.py @@ -21,7 +21,8 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected. -def myblock(lc, x): + +def myblock(lc, x): # second argument is ignored ########################################################################### # diff --git a/pysamples/dotted_line.py b/pysamples/dotted_line.py index 9db7f9d..86d5c7f 100644 --- a/pysamples/dotted_line.py +++ b/pysamples/dotted_line.py @@ -22,21 +22,21 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected. Some examples of how to use this block are included # below. Try uncommenting an example or write your own Python code. -# +# # To uncomment code, remove the '# ' in the Python code. Take care to preserve # the proper indentations. # -# +# # NOTES: -# +# # Turtle Art is created in object oriented Python code. This is based # around the definition of classes and the creation of object(s) which # are instance(s) of that class. These objects then have properties and # methods which are defined by their class. -# +# # See http://docs.python.org/tutorial/classes.html for a description of # classes in Python. -# +# # Class Defined in Instance Created in # TurtleArtWindow tawindow.py tw TurtleArtActivity.py # LogoCode talogo.py lc tawindow.py @@ -44,11 +44,11 @@ # Turtles, Turtle taturtle.py turtles tawindow.py, # tacanvas.py # Blocks, Block tablock.py block_list tawindow.py -# -# +# +# # Class TurtleArtWindow -- useful properties and methods (from within # tamyblock.py, lc.tw is the class instance) -# +# # Methods and data attributes Example # set_fullscreen(self) lc.tw.set_fullscreen() # Note: Hides the Sugar toolbar @@ -62,11 +62,11 @@ # Note: Toggles visibility of blocks and palettes # self.active_turtle lc.tw.active_turtle # Note: The active turtle instance -# -# +# +# # Class TurtleGraphics -- useful properties and methods (from within # tamyblock.py, lc.tw.canvas is the class instance) -# +# # Methods and data attributes Example # clearscreen(self) lc.tw.canvas.clearscreen() # Note: Clears the screen and resets all turtle and @@ -108,8 +108,8 @@ # (scaled to current units) # self.set_turtle(name) lc.tw.canvas.set_turtle(1) # Note: Set the current turtle to turtle '1' -# -# +# +# # Other useful Python functions # Module Example # from math import pow pow(2,3) returns 2 to the 3rd power @@ -124,28 +124,30 @@ # Note: See http://docs.python.org/tutorial/datastructures.html # -def myblock(lc, x): + +def myblock(lc, line_length): ########################################################################### # - # Draw a dotted line of length x. + # Draw a dotted line of length line_length. # ########################################################################### - try: # make sure x is a number - x = float(x) + try: # make sure line_length is a number + line_length = float(line_length) except ValueError: return if lc.tw.canvas.pendown: dist = 0 - while dist+lc.tw.canvas.pensize < x: # repeat drawing dots + while dist + lc.tw.canvas.pensize < line_length: # repeat drawing dots lc.tw.canvas.setpen(True) lc.tw.canvas.forward(1) lc.tw.canvas.setpen(False) - lc.tw.canvas.forward((lc.tw.canvas.pensize*2)-1) - dist += (lc.tw.canvas.pensize*2) - lc.tw.canvas.forward(x-dist) # make sure we have moved exactly x + lc.tw.canvas.forward((lc.tw.canvas.pensize * 2) - 1) + dist += (lc.tw.canvas.pensize * 2) + # make sure we have moved exactly line_length + lc.tw.canvas.forward(line_length - dist) lc.tw.canvas.setpen(True) else: - lc.tw.canvas.forward(x) + lc.tw.canvas.forward(line_length) return diff --git a/pysamples/load_block.py b/pysamples/load_block.py index 084786d..8fb9546 100644 --- a/pysamples/load_block.py +++ b/pysamples/load_block.py @@ -21,6 +21,7 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected. + def myblock(lc, blkname): ########################################################################### @@ -32,7 +33,6 @@ def myblock(lc, blkname): from taconstants import BLOCK_NAMES, PRIMITIVES from tautils import find_group - def new_block(lc, blkname, x, y): """ Create a new block. It is a bit more work than just calling _new_block(). We need to: @@ -66,4 +66,3 @@ def myblock(lc, blkname): y += int(new_block(lc, name, x, y)) else: new_block(lc, blkname, x, y) - diff --git a/pysamples/load_journal_entry_to_heap.py b/pysamples/load_journal_entry_to_heap.py index 7416554..cf2ec7e 100644 --- a/pysamples/load_journal_entry_to_heap.py +++ b/pysamples/load_journal_entry_to_heap.py @@ -21,7 +21,8 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected. -def myblock(lc, x): + +def myblock(lc, x): # ignore second argument ########################################################################### # diff --git a/pysamples/paste_to_heap.py b/pysamples/paste_to_heap.py index 9255a93..a7f67f9 100644 --- a/pysamples/paste_to_heap.py +++ b/pysamples/paste_to_heap.py @@ -21,7 +21,8 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected. -def myblock(lc, x): + +def myblock(lc, x): # ignore second argument ########################################################################### # diff --git a/pysamples/push_mouse_event.py b/pysamples/push_mouse_event.py index 485061f..6966310 100644 --- a/pysamples/push_mouse_event.py +++ b/pysamples/push_mouse_event.py @@ -22,7 +22,8 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected. -def myblock(lc, x): + +def myblock(lc, x): # ignore second argument ########################################################################### # diff --git a/pysamples/push_time.py b/pysamples/push_time.py index ae22684..2abf260 100644 --- a/pysamples/push_time.py +++ b/pysamples/push_time.py @@ -21,7 +21,8 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected. -def myblock(lc, x): + +def myblock(lc, x): # ignore second argument ########################################################################### # diff --git a/pysamples/save_heap_to_journal_entry.py b/pysamples/save_heap_to_journal_entry.py index c4f2d50..2589164 100644 --- a/pysamples/save_heap_to_journal_entry.py +++ b/pysamples/save_heap_to_journal_entry.py @@ -21,7 +21,8 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected. -def myblock(lc, x): + +def myblock(lc, title): ########################################################################### # @@ -39,7 +40,8 @@ def myblock(lc, x): from tautils import get_path, data_to_file # Save JSON-encoded heap to temporary file - heap_file = os.path.join(get_path(activity, 'instance'), str(x) + '.txt') + heap_file = os.path.join(get_path(activity, 'instance'), + str(title) + '.txt') data_to_file(lc.heap, heap_file) # Create a datastore object @@ -47,7 +49,7 @@ def myblock(lc, x): # Write any metadata (specifically set the title of the file # and specify that this is a plain text file). - dsobject.metadata['title'] = str(x) + dsobject.metadata['title'] = str(title) dsobject.metadata['icon-color'] = profile.get_color().to_string() dsobject.metadata['mime_type'] = 'text/plain' dsobject.set_file_path(heap_file) diff --git a/pysamples/set_rgb.py b/pysamples/set_rgb.py index f524ec6..0a556fe 100644 --- a/pysamples/set_rgb.py +++ b/pysamples/set_rgb.py @@ -22,7 +22,8 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected and expanded to 3 arguments. -def myblock(lc, x): + +def myblock(lc, rgb_array): ########################################################################### # @@ -30,21 +31,15 @@ def myblock(lc, x): # ########################################################################### - # assuming x is an array [r, g, b] - b = int(x[2]) - while b < 0: - b += 256 - while b > 255: - b -= 256 - g = int(x[1]) - while g < 0: - g += 256 - while g > 255: - g -= 256 - r = int(x[0]) - while r < 0: - r += 256 - while r > 255: - r -= 256 - rgb = "#%02x%02x%02x" % (r,g,b) + def mod(x): + while x < 0: + x += 256 + while b > 255: + x -= 256 + return x + + b = mod(int(rgb_array[2])) + g = mod(int(rgb_array[1])) + r = mod(int(rgb_array[0])) + rgb = "#%02x%02x%02x" % (r, g, b) lc.tw.canvas.fgcolor = lc.tw.canvas.cm.alloc_color(rgb) diff --git a/pysamples/sinewave.py b/pysamples/sinewave.py index eea975d..4ddf3b4 100644 --- a/pysamples/sinewave.py +++ b/pysamples/sinewave.py @@ -21,13 +21,14 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected. -def myblock(lc, x): + +def myblock(lc, frequency): ########################################################################### # - # Plays a sound at frequency x + # Plays a sound at frequency frequency # ########################################################################### import os - os.system('speaker-test -t sine -l 1 -f %d' % (int(x))) + os.system('speaker-test -t sine -l 1 -f %d' % (int(frequency))) diff --git a/pysamples/speak.py b/pysamples/speak.py index 594c296..666fc6b 100644 --- a/pysamples/speak.py +++ b/pysamples/speak.py @@ -22,7 +22,8 @@ # This procedure is invoked when the user-definable block on the "extras" # palette is selected. -def myblock(lc, x): + +def myblock(lc, text): ########################################################################### # @@ -34,8 +35,7 @@ def myblock(lc, x): # Turtle Art numbers are passed as float, # but they may be integer values. - if type(x) == float and int(x) == x: - x = int(x) - - os.system('espeak "%s" --stdout | aplay' % (x)) + if type(text) == float and int(text) == text: + text = int(text) + os.system('espeak "%s" --stdout | aplay' % (text)) -- cgit v0.9.1