Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt
diff options
context:
space:
mode:
Diffstat (limited to 'TurtleArt')
-rw-r--r--TurtleArt/talogo.py23
-rw-r--r--TurtleArt/tawindow.py138
2 files changed, 15 insertions, 146 deletions
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py
index 3037bb5..e935ea3 100644
--- a/TurtleArt/talogo.py
+++ b/TurtleArt/talogo.py
@@ -194,15 +194,9 @@ class LogoCode:
for b in blocks:
b.unhighlight()
- # Hidden macro expansions
for b in blocks:
- if b.name in ['while', 'until']:
- action_blk, new_blocks = self._expand_forever(b, blk, blocks)
- blocks = new_blocks[:]
- if b == blk:
- blk = action_blk
- for b in blocks:
- if b.name in ['forever']:
+ # Hidden macro expansions
+ if b.name in ['while', 'until', 'forever']:
action_blk, new_blocks = self._expand_forever(b, blk, blocks)
blocks = new_blocks[:]
if b == blk:
@@ -261,10 +255,11 @@ class LogoCode:
if len(dock) > 4: # There could be a '(', ')', '[' or ']'.
code.append(dock[4])
if blk.primitive is not None: # make a tuple (prim, blk)
- if blk in self.tw.block_list.list:
+ # special case: expand 'while' and 'until' primitives
+ try:
code.append((blk.primitive,
self.tw.block_list.list.index(blk)))
- else:
+ except ValueError:
code.append(blk.primitive) # Hidden block
elif len(blk.values) > 0: # Extract the value from content blocks.
if blk.name == 'number':
@@ -855,11 +850,11 @@ class LogoCode:
inflow.connections[i] = action_blk
else:
i = None
- j = None
if outflow is not None:
- if b in outflow.connections:
- j = outflow.connections.index(b)
- outflow.connections[j] = action_blk
+ j = outflow.connections.index(b)
+ outflow.connections[j] = action_blk
+ else:
+ j = None
if until_blk and whileflow is not None:
action_first.connections.append(inflow)
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index 3c93fe9..ebe952c 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -54,9 +54,8 @@ from taconstants import HORIZONTAL_PALETTE, VERTICAL_PALETTE, BLOCK_SCALE, \
CONSTANTS, EXPAND_SKIN, PROTO_LAYER
from tapalette import palette_names, palette_blocks, expandable_blocks, \
block_names, content_blocks, default_values, special_names, block_styles, \
- help_strings, hidden_proto_blocks, string_or_number_args, \
- make_palette, palette_name_to_index
-from talogo import LogoCode, primitive_dictionary
+ help_strings, hidden_proto_blocks, string_or_number_args
+from talogo import LogoCode
from tacanvas import TurtleGraphics
from tablock import Blocks, Block
from taturtle import Turtles, Turtle
@@ -174,7 +173,6 @@ class TurtleArtWindow():
self.coord_scale = 1
self.buddies = []
self.saved_string = ''
- self._saved_action_name = ''
self.dx = 0
self.dy = 0
self.media_shapes = {}
@@ -534,7 +532,7 @@ class TurtleArtWindow():
def stop_button(self):
""" Stop button """
self.lc.stop_logo()
- # self._stop_plugins() ## _stop_plugins is called from stop_logo()
+ self._stop_plugins()
def set_userdefined(self, blk=None):
""" Change icon for user-defined blocks after loading Python code. """
@@ -1191,11 +1189,6 @@ class TurtleArtWindow():
n -= 1
self.selected_blk.spr.set_label(str(n) + CURSOR)
return True
- elif self._action_name(self.selected_blk, hat_only=True):
- if self.selected_blk.values[0] == _('action'):
- self._new_stack_block(self.selected_blk.spr.labels[0])
- self._update_action_names(self.selected_blk.spr.labels[0])
-
# Un-highlight any blocks in the stack
grp = find_group(self.selected_blk)
for blk in grp:
@@ -1232,8 +1225,6 @@ class TurtleArtWindow():
elif blk.type == 'trash':
self._restore_from_trash(find_top_block(blk))
elif blk.type == 'proto':
- defaults = None
- name = blk.name
if blk.name == 'restoreall':
self._restore_all_from_trash()
elif blk.name == 'restore':
@@ -1253,11 +1244,6 @@ class TurtleArtWindow():
'block', blk.name)) > 0:
self.showlabel('dupstack')
return True
- # If we autogenerated a stack prototype, we need
- # to change its name from 'stack_foo' to 'stack'
- elif blk.name[0:6] == 'stack_':
- defaults = [blk.name[6:]]
- name = 'stack'
# You cannot mix and match sensor blocks
elif blk.name in ['sound', 'volume', 'pitch']:
if len(self.block_list.get_similar_blocks(
@@ -1283,10 +1269,7 @@ class TurtleArtWindow():
self.showlabel('incompatible')
return True
blk.highlight()
- if defaults == None:
- self._new_block(name, x, y)
- else:
- self._new_block(name, x, y, defaults=defaults)
+ self._new_block(blk.name, x, y)
blk.unhighlight()
return True
@@ -1344,44 +1327,6 @@ class TurtleArtWindow():
self._select_toolbar_button(spr)
return True
- def _update_action_names(self, name):
- """ change the label on action blocks of the same name """
- if CURSOR in self._saved_action_name:
- self._saved_action_name = \
- self._saved_action_name.replace(CURSOR, '')
- if CURSOR in name:
- name = name.replace(CURSOR, '')
- for blk in self.just_blocks():
- if self._action_name(blk):
- if CURSOR in blk.spr.labels[0]:
- blk.spr.labels[0] = \
- blk.spr.labels[0].replace(CURSOR, '')
- if blk.spr.labels[0] == self._saved_action_name:
- blk.spr.labels[0] = name
- blk.values[0] = name
- blk.spr.set_layer(BLOCK_LAYER)
- # Also change the name of the proto block
- for blk in self.just_protos():
- if blk.name == 'stack_%s' % (self._saved_action_name):
- blk.name = 'stack_%s' % (name)
- blk.spr.labels[0] = name
- blk.spr.set_layer(PROTO_LAYER)
- return
-
- def _action_name(self, blk, hat_only=False):
- """ is this a label for an action block? """
- if blk is None:
- return False
- if blk.name != 'string': # Ignoring int names
- return False
- if self.selected_blk.connections[0] is None:
- return False
- if self.selected_blk.connections[0].name in ['hat', 'stack']:
- if hat_only and self.selected_blk.connections[0].name =='stack':
- return False
- return True
- return False
-
def _select_category(self, spr):
""" Select a category from the toolbar """
i = self.selectors.index(spr)
@@ -1456,18 +1401,6 @@ class TurtleArtWindow():
for gblk in group:
gblk.spr.hide()
- # if there was a named hat, remove it from the proto palette
- for gblk in group:
- if gblk.name == 'hat' and \
- gblk.connections is not None and \
- gblk.connections[1] is not None and \
- gblk.connections[1].name == 'string' and \
- gblk.connections[1].values[0] != _('action'):
- i = palette_name_to_index('blocks')
- palette_blocks[i].remove('stack_%s' % (
- gblk.connections[1].values[0]))
- self.show_toolbar_palette(i, regenerate=True)
-
def _restore_all_from_trash(self):
""" Restore all the blocks in the trash can. """
for blk in self.block_list.list:
@@ -1545,7 +1478,7 @@ class TurtleArtWindow():
def _unselect_block(self):
""" Unselect block """
- # After unselecting a 'number' or 'string' block, check its value
+ # After unselecting a 'number' block, we need to check its value
if self.selected_blk.name == 'number':
self._number_check()
for spr in self.triangle_sprs:
@@ -2087,16 +2020,8 @@ class TurtleArtWindow():
return
self.selected_blk = blk
- if blk.name == 'number' or blk.name == 'string':
+ if blk.name == 'number' or blk.name == 'string':
self.saved_string = blk.spr.labels[0]
- if self._action_name(blk):
- if CURSOR in self.saved_string:
- self._saved_action_name = \
- self.saved_string.replace(CURSOR, '')
- else:
- self._saved_action_name = self.saved_string
- else:
- self._saved_action_name = None
blk.spr.labels[0] += CURSOR
if blk.name == 'number':
bx, by = blk.spr.get_xy()
@@ -3418,14 +3343,6 @@ class TurtleArtWindow():
just_blocks_list.append(_blk)
return just_blocks_list
- def just_protos(self):
- """ Filter out 'blocks', 'trash', and 'deleted' blocks """
- just_protos_list = []
- for _blk in self.block_list.list:
- if _blk.type == 'proto':
- just_protos_list.append(_blk)
- return just_protos_list
-
def _width_and_height(self, blk):
""" What are the width and height of a stack? """
minx = 10000
@@ -3506,49 +3423,6 @@ class TurtleArtWindow():
x, y = self._calc_image_offset('', blk.spr, w, h)
blk.scale_image(x, y, w, h)
- def _new_stack_block(self, name):
- ''' Add a stack block to the 'blocks' palette '''
- if CURSOR in name:
- name = name.replace(CURSOR, '')
- if name == _('action'):
- return
- # Choose a palette for the new block.
- palette = make_palette('blocks')
-
- # Create a new block prototype.
- primitive_dictionary['stack'] = self._prim_stack
- palette.add_block('stack_%s' % (name),
- style='basic-style-1arg',
- label=name,
- string_or_number=True,
- prim_name='stack',
- logo_command='action',
- default=name,
- help_string=_('invokes named action stack'))
- self.lc.def_prim('stack', 1, primitive_dictionary['stack'], True)
-
- # Regenerate the palette, which will now include the new block.
- self.show_toolbar_palette(palette_name_to_index('blocks'),
- regenerate=True)
-
- def _prim_stack(self, x):
- """ Process a named stack """
- from TurtleArt.tautils import convert
- from talogo import logoerror
-
- if type(convert(x, float, False)) == float:
- if int(float(x)) == x:
- x = int(x)
- if 'stack3' + str(x) not in self.lc.stacks or \
- self.lc.stacks['stack3' + str(x)] is None:
- raise logoerror("#nostack")
- self.lc.icall(self.lc.evline,
- self.lc.stacks['stack3' + str(x)][:])
- yield True
- self.lc.procstop = False
- self.lc.ireturn()
- yield True
-
def dock_dx_dy(block1, dock1n, block2, dock2n):
""" Find the distance between the dock points of two blocks. """