Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pysamples
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-03-21 19:53:04 (GMT)
committer Walter Bender <walter.bender@gmail.com>2011-03-21 19:53:04 (GMT)
commitfc4b6a64cc06bb35328835a382c14a8af542d20c (patch)
treef9bf8fcab89ab16489de05142d06d482b6df6bea /pysamples
parent1eede14372ceaaec094c55ca01f4c8f6dbfd0ab4 (diff)
FLAG DAY: passing TurtleWindow instead of LogoCode instance as 1st argument
Diffstat (limited to 'pysamples')
-rw-r--r--pysamples/copy_from_heap.py4
-rw-r--r--pysamples/dotted_line.py74
-rw-r--r--pysamples/load_block.py51
-rw-r--r--pysamples/load_journal_entry_to_heap.py4
-rw-r--r--pysamples/paste_to_heap.py6
-rw-r--r--pysamples/push_mouse_event.py14
-rw-r--r--pysamples/push_time.py8
-rw-r--r--pysamples/save_heap_to_journal_entry.py4
-rw-r--r--pysamples/set_rgb.py4
-rw-r--r--pysamples/sinewave.py2
-rw-r--r--pysamples/speak.py2
-rw-r--r--pysamples/uturn.py10
12 files changed, 92 insertions, 91 deletions
diff --git a/pysamples/copy_from_heap.py b/pysamples/copy_from_heap.py
index 1978c26..23c4dac 100644
--- a/pysamples/copy_from_heap.py
+++ b/pysamples/copy_from_heap.py
@@ -22,7 +22,7 @@
# palette is selected.
-def myblock(lc, x): # second argument is ignored
+def myblock(tw, x): # second argument is ignored
###########################################################################
#
@@ -33,4 +33,4 @@ def myblock(lc, x): # second argument is ignored
from gtk import Clipboard
from tautils import data_to_string
- Clipboard().set_text(data_to_string(lc.heap))
+ Clipboard().set_text(data_to_string(tw.lc.heap))
diff --git a/pysamples/dotted_line.py b/pysamples/dotted_line.py
index 86d5c7f..b59e38f 100644
--- a/pysamples/dotted_line.py
+++ b/pysamples/dotted_line.py
@@ -47,66 +47,66 @@
#
#
# Class TurtleArtWindow -- useful properties and methods (from within
-# tamyblock.py, lc.tw is the class instance)
+# tamyblock.py, tw is the class instance)
#
# Methods and data attributes Example
-# set_fullscreen(self) lc.tw.set_fullscreen()
+# set_fullscreen(self) tw.set_fullscreen()
# Note: Hides the Sugar toolbar
-# set_cartesian(self, flag) lc.tw.set_cartesian(True)
+# set_cartesian(self, flag) tw.set_cartesian(True)
# Note: True will make the overlay visible;
# False will make it invisible
-# set_polar(self, flag) lc.tw.set_polar(True)
+# set_polar(self, flag) tw.set_polar(True)
# Note: True will make the overlay visible;
# False will make it invisible
-# hideshow_button(self, flag) lc.tw.hideshow_button()
+# hideshow_button(self, flag) tw.hideshow_button()
# Note: Toggles visibility of blocks and palettes
-# self.active_turtle lc.tw.active_turtle
+# self.active_turtle 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)
+# tamyblock.py, tw.canvas is the class instance)
#
# Methods and data attributes Example
-# clearscreen(self) lc.tw.canvas.clearscreen()
+# clearscreen(self) tw.canvas.clearscreen()
# Note: Clears the screen and resets all turtle and
# pen attributes to default values
-# setpen(self, flag) lc.tw.canvas.setpen(True)
+# setpen(self, flag) tw.canvas.setpen(True)
# Note: True will set the pen "down", enabling drawing;
# False will set the pen "up"
-# forward(self, n) lc.tw.canvas.forward(100)
+# forward(self, n) tw.canvas.forward(100)
# Note: Move the turtle forward 100 units
-# arc(self, a, r) lc.tw.canvas.arc(120, 50)
+# arc(self, a, r) tw.canvas.arc(120, 50)
# Note: Move the turtle along an arc of 120 degrees
# (clockwise) and radius of 50 units
-# setheading(self, a) lc.tw.canvas.setheading(180)
+# setheading(self, a) tw.canvas.setheading(180)
# Note: Set the turtle heading to 180
# (towards the bottom of the screen)
-# self.heading lc.tw.canvas.heading
+# self.heading tw.canvas.heading
# Note: The current heading
-# setpensize(self, n) lc.tw.canvas.setpensize(25)
+# setpensize(self, n) tw.canvas.setpensize(25)
# Note: Set the turtle pensize to 25 units
-# self.pensize lc.tw.canvas.pensize
+# self.pensize tw.canvas.pensize
# Note: The current pensize
-# setcolor(self, c) lc.tw.canvas.color(70)
+# setcolor(self, c) tw.canvas.color(70)
# Note: Set the pen color to 70 (blue)
-# self.color lc.tw.canvas.color
+# self.color tw.canvas.color
# Note: The current pen color
-# setshade(self, s) lc.tw.canvas.shade(50)
+# setshade(self, s) tw.canvas.shade(50)
# Note: Set the pen shade to 50
-# self.shade lc.tw.canvas.shade
+# self.shade tw.canvas.shade
# Note: The current pen shade
-# fillscreen(self, c, s) lc.tw.canvas.fillscreen(70, 90)
+# fillscreen(self, c, s) tw.canvas.fillscreen(70, 90)
# Note: Fill the screen with color 70, shade 90 (light blue)
-# setxy(self, x, y) lc.tw.canvas.setxy(100,100)
+# setxy(self, x, y) tw.canvas.setxy(100,100)
# Note: Move the turtle to position (100, 100)
-# self.xcor lc.tw.canvas.xcor
+# self.xcor tw.canvas.xcor
# Note: The current x coordinate of the turtle
# (scaled to current units)
-# self.ycor lc.tw.canvas.ycor
+# self.ycor tw.canvas.ycor
# Note: The current y coordinate of the turtle
# (scaled to current units)
-# self.set_turtle(name) lc.tw.canvas.set_turtle(1)
+# self.set_turtle(name) tw.canvas.set_turtle(1)
# Note: Set the current turtle to turtle '1'
#
#
@@ -118,14 +118,14 @@
# Note: See http://docs.python.org/library/math.html
# from time import localtime localtime().tm_hour returns the current hour
# Note: See http://docs.python.org/library/time.html
-# lc.heap.append(data) adds data to the heap
+# tw.lc.heap.append(data) adds data to the heap
# Note: See http://docs.python.org/tutorial/datastructures.html
-# data = lc.heap.pop(-1) pops data off the heap
+# data = tw.lc.heap.pop(-1) pops data off the heap
# Note: See http://docs.python.org/tutorial/datastructures.html
#
-def myblock(lc, line_length):
+def myblock(tw, line_length):
###########################################################################
#
@@ -137,17 +137,17 @@ def myblock(lc, line_length):
line_length = float(line_length)
except ValueError:
return
- if lc.tw.canvas.pendown:
+ if tw.canvas.pendown:
dist = 0
- 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)
+ while dist + tw.canvas.pensize < line_length: # repeat drawing dots
+ tw.canvas.setpen(True)
+ tw.canvas.forward(1)
+ tw.canvas.setpen(False)
+ tw.canvas.forward((tw.canvas.pensize * 2) - 1)
+ dist += (tw.canvas.pensize * 2)
# make sure we have moved exactly line_length
- lc.tw.canvas.forward(line_length - dist)
- lc.tw.canvas.setpen(True)
+ tw.canvas.forward(line_length - dist)
+ tw.canvas.setpen(True)
else:
- lc.tw.canvas.forward(line_length)
+ tw.canvas.forward(line_length)
return
diff --git a/pysamples/load_block.py b/pysamples/load_block.py
index 4f46a73..b42df4f 100644
--- a/pysamples/load_block.py
+++ b/pysamples/load_block.py
@@ -22,7 +22,7 @@
# palette is selected.
-def myblock(lc, blkname):
+def myblock(tw, blkname):
###########################################################################
#
@@ -30,29 +30,29 @@ def myblock(lc, blkname):
#
###########################################################################
- from taconstants import BLOCK_NAMES, PRIMITIVES, CONTENT_BLOCKS, \
- SPECIAL_NAMES
- from tautils import find_group
+ from TurtleArt.tapalette import block_names, block_primitives, \
+ special_names, content_blocks
+ from TurtleArt.tautils import find_group
- def make_block(lc, name, x, y, defaults):
+ def make_block(tw, name, x, y, defaults):
x_pos = x + 20
y_pos = y + 20
- lc.tw._new_block(name, x_pos, y_pos, defaults)
+ tw._new_block(name, x_pos, y_pos, defaults)
# Find the block we just created and attach it to a stack.
- lc.tw.drag_group = None
- spr = lc.tw.sprite_list.find_sprite((x_pos, y_pos))
+ tw.drag_group = None
+ spr = tw.sprite_list.find_sprite((x_pos, y_pos))
if spr is not None:
- blk = lc.tw.block_list.spr_to_block(spr)
+ blk = tw.block_list.spr_to_block(spr)
if blk is not None:
- lc.tw.drag_group = find_group(blk)
- lc.tw._snap_to_dock()
+ tw.drag_group = find_group(blk)
+ tw._snap_to_dock()
# Disassociate new block from mouse.
- lc.tw.drag_group = None
+ tw.drag_group = None
return blk.height
- def find_block(lc, blkname, x, y, defaults=None):
+ def find_block(tw, blkname, x, y, defaults=None):
""" Create a new block. It is a bit more work than just calling
_new_block(). We need to:
(1) translate the label name into the internal block name;
@@ -60,27 +60,28 @@ def myblock(lc, blkname):
(3) disassociate the new block from the mouse. """
print blkname
- for name in BLOCK_NAMES:
+ for name in block_names:
# Translate label name into block/prim name.
- if blkname in BLOCK_NAMES[name]:
- if (name in PRIMITIVES and PRIMITIVES[name] == name) or \
- name in CONTENT_BLOCKS:
- return make_block(lc, name, x, y, defaults)
- for name in SPECIAL_NAMES:
+ if blkname in block_names[name]:
+ if (name in block_primitives and \
+ block_primitives[name] == name) or \
+ name in content_blocks:
+ return make_block(tw, name, x, y, defaults)
+ for name in special_names:
# Translate label name into block/prim name.
- if blkname in SPECIAL_NAMES[name]:
- return make_block(lc, name, x, y, defaults)
+ if blkname in special_names[name]:
+ return make_block(tw, name, x, y, defaults)
return -1
# Place the block at the active turtle (x, y) and
# push height to stack.
- x, y = lc.tw.active_turtle.get_xy()
+ x, y = tw.active_turtle.get_xy()
if type(blkname) == type([]):
name = blkname[0]
value = blkname[1:]
- dy = int(find_block(lc, name, x, y, value))
+ dy = int(find_block(tw, name, x, y, value))
else:
name = blkname
- dy = int(find_block(lc, name, x, y))
+ dy = int(find_block(tw, name, x, y))
if dy != -1:
- lc.heap.append(dy)
+ tw.lc.heap.append(dy)
diff --git a/pysamples/load_journal_entry_to_heap.py b/pysamples/load_journal_entry_to_heap.py
index cf2ec7e..4ee713c 100644
--- a/pysamples/load_journal_entry_to_heap.py
+++ b/pysamples/load_journal_entry_to_heap.py
@@ -22,7 +22,7 @@
# palette is selected.
-def myblock(lc, x): # ignore second argument
+def myblock(tw, x): # ignore second argument
###########################################################################
#
@@ -33,4 +33,4 @@ def myblock(lc, x): # ignore second argument
from tautils import chooser
# Choose a datastore object and push data to heap (Sugar only)
- chooser(lc.tw.parent, '', lc.push_file_data_to_heap)
+ chooser(tw.parent, '', tw.lc.push_file_data_to_heap)
diff --git a/pysamples/paste_to_heap.py b/pysamples/paste_to_heap.py
index a7f67f9..eccd973 100644
--- a/pysamples/paste_to_heap.py
+++ b/pysamples/paste_to_heap.py
@@ -22,7 +22,7 @@
# palette is selected.
-def myblock(lc, x): # ignore second argument
+def myblock(tw, x): # ignore second argument
###########################################################################
#
@@ -36,5 +36,5 @@ def myblock(lc, x): # ignore second argument
text = Clipboard().wait_for_text()
if text is not None:
for val in data_from_string(text):
- lc.heap.append(val)
- lc.update_label_value('pop', val)
+ tw.lc.heap.append(val)
+ tw.lc.update_label_value('pop', val)
diff --git a/pysamples/push_mouse_event.py b/pysamples/push_mouse_event.py
index 6966310..26301ac 100644
--- a/pysamples/push_mouse_event.py
+++ b/pysamples/push_mouse_event.py
@@ -23,7 +23,7 @@
# palette is selected.
-def myblock(lc, x): # ignore second argument
+def myblock(tw, x): # ignore second argument
###########################################################################
#
@@ -31,11 +31,11 @@ def myblock(lc, x): # ignore second argument
#
###########################################################################
- if lc.tw.mouse_flag == 1:
+ if tw.mouse_flag == 1:
# push y first so x will be popped first
- lc.heap.append((lc.tw.canvas.height / 2) - lc.tw.mouse_y)
- lc.heap.append(lc.tw.mouse_x - (lc.tw.canvas.width / 2))
- lc.heap.append(1) # mouse event
- lc.tw.mouse_flag = 0
+ tw.lc.heap.append((tw.canvas.height / 2) - tw.mouse_y)
+ tw.lc.heap.append(tw.mouse_x - (tw.canvas.width / 2))
+ tw.lc.heap.append(1) # mouse event
+ tw.mouse_flag = 0
else:
- lc.heap.append(0) # no mouse event
+ tw.lc.heap.append(0) # no mouse event
diff --git a/pysamples/push_time.py b/pysamples/push_time.py
index 2abf260..ed823ee 100644
--- a/pysamples/push_time.py
+++ b/pysamples/push_time.py
@@ -22,7 +22,7 @@
# palette is selected.
-def myblock(lc, x): # ignore second argument
+def myblock(tw, x): # ignore second argument
###########################################################################
#
@@ -33,6 +33,6 @@ def myblock(lc, x): # ignore second argument
#
###########################################################################
- lc.heap.append(localtime().tm_hour)
- lc.heap.append(localtime().tm_min)
- lc.heap.append(localtime().tm_sec)
+ tw.lc.heap.append(localtime().tm_hour)
+ tw.lc.heap.append(localtime().tm_min)
+ tw.lc.heap.append(localtime().tm_sec)
diff --git a/pysamples/save_heap_to_journal_entry.py b/pysamples/save_heap_to_journal_entry.py
index 2589164..96ac845 100644
--- a/pysamples/save_heap_to_journal_entry.py
+++ b/pysamples/save_heap_to_journal_entry.py
@@ -22,7 +22,7 @@
# palette is selected.
-def myblock(lc, title):
+def myblock(tw, title):
###########################################################################
#
@@ -42,7 +42,7 @@ def myblock(lc, title):
# Save JSON-encoded heap to temporary file
heap_file = os.path.join(get_path(activity, 'instance'),
str(title) + '.txt')
- data_to_file(lc.heap, heap_file)
+ data_to_file(tw.lc.heap, heap_file)
# Create a datastore object
dsobject = datastore.create()
diff --git a/pysamples/set_rgb.py b/pysamples/set_rgb.py
index 0a556fe..f0f70ee 100644
--- a/pysamples/set_rgb.py
+++ b/pysamples/set_rgb.py
@@ -23,7 +23,7 @@
# palette is selected and expanded to 3 arguments.
-def myblock(lc, rgb_array):
+def myblock(tw, rgb_array):
###########################################################################
#
@@ -42,4 +42,4 @@ def myblock(lc, rgb_array):
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)
+ tw.canvas.fgcolor = tw.canvas.cm.alloc_color(rgb)
diff --git a/pysamples/sinewave.py b/pysamples/sinewave.py
index 4ddf3b4..f825317 100644
--- a/pysamples/sinewave.py
+++ b/pysamples/sinewave.py
@@ -22,7 +22,7 @@
# palette is selected.
-def myblock(lc, frequency):
+def myblock(tw, frequency):
###########################################################################
#
diff --git a/pysamples/speak.py b/pysamples/speak.py
index e8d3864..f7a1cf7 100644
--- a/pysamples/speak.py
+++ b/pysamples/speak.py
@@ -23,7 +23,7 @@
# palette is selected.
-def myblock(lc, arg):
+def myblock(tw, arg):
###########################################################################
#
diff --git a/pysamples/uturn.py b/pysamples/uturn.py
index b38542a..bba165a 100644
--- a/pysamples/uturn.py
+++ b/pysamples/uturn.py
@@ -22,7 +22,7 @@
# This procedure is invoked when the user-definable block on the "extras"
# palette is selected.
-def myblock(parent, arg):
+def myblock(tw, arg):
''' Add a uturn block to the 'turtle' palette '''
from TurtleArt.tapalette import make_palette, palette_name_to_index
@@ -40,10 +40,10 @@ def myblock(parent, arg):
help_string=_('make a uturn'))
# Add its primitive to the LogoCode dictionary.
- parent.tw.lc.def_prim('uturn', 0,
- lambda self: primitive_dictionary['set'](
- 'heading', parent.tw.canvas.seth, parent.tw.canvas.heading + 180))
+ tw.lc.def_prim('uturn', 0,
+ lambda self: primitive_dictionary['set'](
+ 'heading', tw.canvas.seth, tw.canvas.heading + 180))
# Regenerate the palette, which will now include the new block.
- parent.tw.show_toolbar_palette(palette_name_to_index('turtle'),
+ tw.show_toolbar_palette(palette_name_to_index('turtle'),
regenerate=True)