Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TurtleArt/tautils.py18
-rw-r--r--TurtleArt/tawindow.py41
2 files changed, 54 insertions, 5 deletions
diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py
index 676c4ca..c54c65f 100644
--- a/TurtleArt/tautils.py
+++ b/TurtleArt/tautils.py
@@ -24,6 +24,7 @@ import cairo
import pickle
import subprocess
import os
+import string
from gettext import gettext as _
try:
@@ -109,6 +110,23 @@ def strtype(x):
return False
+def increment_name(name):
+ ''' If name is of the form foo_2, change it to foo_3. Otherwise,
+ return name_2'''
+ if '_' in name:
+ parts = name.split('_')
+ try:
+ i = int(parts[-1])
+ i += 1
+ parts[-1] = str(i)
+ newname = string.join(parts, '_')
+ except ValueError:
+ newname = '%s_2' % (name)
+ else:
+ newname = '%s_2' % (name)
+ return newname
+
+
def magnitude(pos):
''' Calculate the magnitude of the distance between to blocks. '''
x, y = pos
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index 7f8e156..6e11a3a 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -69,7 +69,8 @@ from tautils import magnitude, get_load_name, get_save_name, data_from_file, \
arithmetic_check, xy, find_block_to_run, find_top_block, journal_check, \
find_group, find_blk_below, data_to_string, find_start_stack, \
get_hardware, debug_output, error_output, data_to_string, convert, \
- find_bot_block, restore_clamp, collapse_clamp, data_from_string
+ find_bot_block, restore_clamp, collapse_clamp, data_from_string, \
+ increment_name
from tasprite_factory import SVG, svg_str_to_pixbuf, svg_from_file
from sprites import Sprites, Sprite
@@ -1322,10 +1323,10 @@ class TurtleArtWindow():
if len(similars) > 0:
defaults = [_('action')]
if self._find_proto_name('stack', defaults[0]):
- defaults[0] = defaults[0] + '_2'
+ defaults[0] = increment_name(defaults[0])
while self._find_proto_name('stack_%s' % (
defaults[0]), defaults[0]):
- defaults[0] = defaults[0] + '_2'
+ defaults[0] = increment_name(defaults[0])
self._new_stack_block(defaults[0])
# If we autogenerated a stack prototype, we need
# to change its name from 'stack_foo' to 'stack'
@@ -2665,6 +2666,36 @@ class TurtleArtWindow():
selected_block.connections[best_selected_block_dockn] = \
best_destination
+ # Are we renaming an action or variable?
+ if best_destination.name in ['hat', 'storein'] and \
+ selected_block.name == 'string' and best_destination_dockn == 1:
+ name = selected_block.values[0]
+ if best_destination.name == 'storein':
+ if not self._find_proto_name('storein_%s' % (name), name):
+ self._new_storein_block(name)
+ if not self._find_proto_name('box_%s' % (name), name):
+ self._new_box_block(name)
+ else: # 'hat'
+ # Check to see if it is unique...
+ unique = True
+ similars = self.block_list.get_similar_blocks(
+ 'block', 'hat')
+ for blk in similars:
+ if blk == best_destination:
+ continue
+ if blk.connections is not None and \
+ blk.connections[1] is not None and \
+ blk.connections[1].name == 'string':
+ if blk.connections[1].values[0] == name:
+ unique = False
+ if not unique:
+ while self._find_proto_name('stack_%s' % (name), name):
+ name = increment_name(name)
+ blk.connections[1].values[0] = name
+ blk.connections[1].spr.labels[0] = name
+ blk.resize()
+ self._new_stack_block(name)
+
# Some destination blocks expand to accomodate large blocks
if best_destination.name in block_styles['boolean-style']:
if best_destination_dockn == 2 and \
@@ -3443,7 +3474,7 @@ class TurtleArtWindow():
if self._check_for_duplicate(btype):
name = block_names[btype][0]
while self._find_proto_name('stack_%s' % (name), name):
- name += '_2'
+ name = increment_name(name)
i = len(self._process_block_data) + len(self._extra_block_data)
self._extra_block_data.append(
[i, ['string', name], 0, 0, [b[0], None]])
@@ -3460,7 +3491,7 @@ class TurtleArtWindow():
i = b[4][1] - len(self._process_block_data)
name = self._extra_block_data[i][1][1]
while self._find_proto_name('stack_%s' % (name), name):
- name += '_2'
+ name = increment_name(name)
if b[4][1] < len(self._process_block_data):
dblk = self._process_block_data[i]
self._process_block_data[i] = [dblk[0], (dblk[1][0], name),