Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TurtleArt/tablock.py4
-rw-r--r--TurtleArt/tawindow.py69
2 files changed, 53 insertions, 20 deletions
diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py
index b0e3dc5..932085e 100644
--- a/TurtleArt/tablock.py
+++ b/TurtleArt/tablock.py
@@ -515,6 +515,8 @@ class Block:
def _set_label_attributes(self):
if self.spr is None:
return
+ if type(self.name) == unicode:
+ self.name = self.name.encode('ascii', 'replace')
if self.name in content_blocks:
n = len(self.values)
if n == 0:
@@ -586,6 +588,8 @@ class Block:
self._bottom = 0
self.svg.set_stroke_width(STANDARD_STROKE_WIDTH)
self.svg.clear_docks()
+ if type(self.name) == unicode:
+ self.name = self.name.encode('ascii', 'replace')
for k in block_styles.keys():
if self.name in block_styles[k]:
if type(self.block_methods[k]) == type([]):
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index f1fdc17..afa8a7c 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -1312,6 +1312,19 @@ class TurtleArtWindow():
'block', blk.name)) > 0:
self.showlabel('dupstack')
return True
+ # We need to check to see if there is already a
+ # similarly default named stack
+ elif blk.name in ['hat']:
+ similars = self.block_list.get_similar_blocks(
+ 'block', blk.name)
+ if len(similars) > 0:
+ defaults = [_('action')]
+ if self._find_proto_name('stack', defaults[0]):
+ defaults[0] = defaults[0] + '_2'
+ while self._find_proto_name('stack_%s' % (
+ defaults[0]), defaults[0]):
+ defaults[0] = defaults[0] + '_2'
+ self._new_stack_block(defaults[0])
# If we autogenerated a stack prototype, we need
# to change its name from 'stack_foo' to 'stack'
elif blk.name[0:6] == 'stack_':
@@ -1409,10 +1422,10 @@ class TurtleArtWindow():
''' change the label on action blocks of the same name '''
if type(name) in [float, int]:
return
- if type(name) == 'unicode':
- name = name.encode('ascii', 'replace')
if CURSOR in name:
name = name.replace(CURSOR, '')
+ if type(name) == 'unicode':
+ name = name.encode('ascii', 'replace')
for blk in self.just_blocks():
if self._action_name(blk, hat=False):
if CURSOR in blk.spr.labels[0]:
@@ -1429,10 +1442,10 @@ class TurtleArtWindow():
''' change the label on box blocks of the same name '''
if type(name) in [float, int]:
return
- if type(name) == 'unicode':
- name = name.encode('ascii', 'replace')
if CURSOR in name:
name = name.replace(CURSOR, '')
+ if type(name) == 'unicode':
+ name = name.encode('ascii', 'replace')
for blk in self.just_blocks():
if self._box_name(blk, storein=False):
if CURSOR in blk.spr.labels[0]:
@@ -1452,14 +1465,31 @@ class TurtleArtWindow():
# (2) The list of block styles
# (3) The list of proto blocks on the palette
# (4) The list of block names
+ if type(name) == unicode:
+ name = name.encode('ascii', 'replace')
+ if type(old) == unicode:
+ old = old.encode('ascii', 'replace')
+ if type(new) == unicode:
+ new = new.encode('ascii', 'replace')
+
if old == new:
debug_output('update_proto_name: %s == %s' % (old, new),
self.running_sugar)
return
found = False
+ if old in block_styles[style]:
+ block_styles[style].remove(old)
+ if not new in block_styles[style]:
+ block_styles[style].append(new)
+
+ if old in block_names:
+ del block_names[old]
+ if not new in block_names:
+ block_names[new] = name
+
i = palette_name_to_index(palette)
- for blk in self.palettes[i]: # self.just_protos():
+ for blk in self.palettes[i]:
if blk.name == old:
blk.name = new
blk.spr.labels[0] = name
@@ -1472,16 +1502,6 @@ class TurtleArtWindow():
if not new in palette_blocks[i]:
palette_blocks[i].append(new)
- if old in block_styles[style]:
- block_styles[style].remove(old)
- if not new in block_styles[style]:
- block_styles[style].append(new)
-
- if old in block_names:
- del block_names[old]
- if not new in block_names:
- block_names[new] = name
-
self.show_toolbar_palette(i, regenerate=True)
def _action_name(self, blk, hat=False):
@@ -3890,9 +3910,18 @@ class TurtleArtWindow():
def _find_proto_name(self, name, label, palette='blocks'):
''' Look for a protoblock with this name '''
+ if type(name) == unicode:
+ name = name.encode('ascii', 'replace')
+ if type(label) == unicode:
+ label = label.encode('ascii', 'replace')
i = palette_name_to_index(palette)
for blk in self.palettes[i]:
- if blk.name == name and blk.spr.labels[0] == label:
+ blk_label = blk.spr.labels[0]
+ if type(blk.name) == unicode:
+ blk.name = blk.name.encode('ascii', 'replace')
+ if type(blk_label) == unicode:
+ blk_label = blk_label.encode('ascii', 'replace')
+ if blk.name == name and blk_label == label:
return True
return False
@@ -3900,10 +3929,10 @@ class TurtleArtWindow():
''' Add a stack block to the 'blocks' palette '''
if type(name) in [float, int]:
return
- if type(name) == unicode:
- name = name.encode('ascii', 'replace')
if CURSOR in name:
name = name.replace(CURSOR, '')
+ if type(name) == unicode:
+ name = name.encode('ascii', 'replace')
if name == _('action'):
return
# Choose a palette for the new block.
@@ -3929,10 +3958,10 @@ class TurtleArtWindow():
''' Add a box block to the 'blocks' palette '''
if type(name) in [float, int]:
return
- if type(name) == unicode:
- name = name.encode('ascii', 'replace')
if CURSOR in name:
name = name.replace(CURSOR, '')
+ if type(name) == unicode:
+ name = name.encode('ascii', 'replace')
if name == _('box'):
return
# Choose a palette for the new block.