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/tabasics.py4
-rw-r--r--TurtleArt/tablock.py4
-rw-r--r--TurtleArt/tacollaboration.py6
-rw-r--r--TurtleArt/tagplay.py5
-rw-r--r--TurtleArt/taturtle.py31
-rw-r--r--TurtleArt/tautils.py6
-rw-r--r--TurtleArt/tawindow.py37
7 files changed, 50 insertions, 43 deletions
diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py
index 0346d0e..beccd2a 100644
--- a/TurtleArt/tabasics.py
+++ b/TurtleArt/tabasics.py
@@ -217,7 +217,7 @@ degrees)'))
'setxy2',
2,
lambda self, x, y: primitive_dictionary['move'](
- self.tw.turtles.get_active_turtle().set_xy, (x, y)))
+ self.tw.turtles.get_active_turtle().set_xy, x, y))
define_logo_function('tasetxy', 'to tasetxy :x :y\nsetxy :x :y\nend\n')
primitive_dictionary['set'] = self._prim_set
@@ -295,7 +295,7 @@ turtle (can be used in place of a number block)'),
'setxy',
2,
lambda self, x, y: primitive_dictionary['move'](
- self.tw.turtles.get_active_turtle().set_xy, (x, y),
+ self.tw.turtles.get_active_turtle().set_xy, x, y,
pendown=False))
define_logo_function('tasetxypenup', 'to tasetxypenup :x :y\npenup\n\
setxy :x :y\npendown\nend\n')
diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py
index 8d8ed4a..ff392e0 100644
--- a/TurtleArt/tablock.py
+++ b/TurtleArt/tablock.py
@@ -555,7 +555,7 @@ class Block:
if self.spr is None:
return
if isinstance(self.name, unicode):
- self.name = self.name.encode('ascii', 'replace')
+ self.name = self.name.encode('utf-8')
if self.name in content_blocks:
n = len(self.values)
if n == 0:
@@ -636,7 +636,7 @@ class Block:
self.svg.set_stroke_width(STANDARD_STROKE_WIDTH)
self.svg.clear_docks()
if isinstance(self.name, unicode):
- self.name = self.name.encode('ascii', 'replace')
+ self.name = self.name.encode('utf-8')
for k in block_styles.keys():
if self.name in block_styles[k]:
if isinstance(self.block_methods[k], list):
diff --git a/TurtleArt/tacollaboration.py b/TurtleArt/tacollaboration.py
index 26a21d7..4f4406b 100644
--- a/TurtleArt/tacollaboration.py
+++ b/TurtleArt/tacollaboration.py
@@ -75,7 +75,7 @@ class Collaboration():
'f': self._move_forward,
'a': self._move_in_arc,
'r': self._rotate_turtle,
- 'x': self._setxy,
+ 'x': self._set_xy,
'W': self._draw_text,
'c': self._set_pen_color,
'g': self._set_pen_gray_level,
@@ -347,12 +347,12 @@ class Collaboration():
self._tw.turtles.set_turtle(nick)
self._tw.turtles.get_active_turtle().set_heading(h, False)
- def _setxy(self, payload):
+ def _set_xy(self, payload):
if len(payload) > 0:
[nick, [x, y]] = data_from_string(payload)
if nick != self._tw.nick:
self._tw.turtles.set_turtle(nick)
- self._tw.turtles.get_active_turtle().set_xy(x, y, False)
+ self._tw.turtles.get_active_turtle().set_xy(x, y, share=False)
def _draw_text(self, payload):
if len(payload) > 0:
diff --git a/TurtleArt/tagplay.py b/TurtleArt/tagplay.py
index 9e9f821..2fc6919 100644
--- a/TurtleArt/tagplay.py
+++ b/TurtleArt/tagplay.py
@@ -235,8 +235,9 @@ class GstPlayer(gobject.GObject):
elif t == gst.MESSAGE_STATE_CHANGED:
old, new, pen = message.parse_state_changed()
if old == gst.STATE_READY and new == gst.STATE_PAUSED:
- self.emit('stream-info',
- self.player.props.stream_info_value_array)
+ if hasattr(self.player.props, 'stream_info_value_array'):
+ self.emit('stream-info',
+ self.player.props.stream_info_value_array)
# else:
# logging.debug(message.type)
diff --git a/TurtleArt/taturtle.py b/TurtleArt/taturtle.py
index 1ed557c..5e24ce7 100644
--- a/TurtleArt/taturtle.py
+++ b/TurtleArt/taturtle.py
@@ -157,7 +157,7 @@ class Turtles:
# if it is a new turtle, start it in the center of the screen
self._active_turtle = self.get_turtle(turtle_name, True, colors)
self._active_turtle.set_heading(0.0, False)
- self._active_turtle.set_xy((0.0, 0.0), False, pendown=False)
+ self._active_turtle.set_xy(0.0, 0.0, share=False, pendown=False)
self._active_turtle.set_pen_state(True)
elif colors is not None:
self._active_turtle = self.get_turtle(turtle_name, False)
@@ -333,6 +333,15 @@ class Turtle:
return
self._heading %= 360
+ self._update_sprite_heading()
+
+ if self._turtles.turtle_window.sharing() and share:
+ event = 'r|%s' % (data_to_string([self._turtles.turtle_window.nick,
+ round_int(self._heading)]))
+ self._turtles.turtle_window.send_event(event)
+
+ def _update_sprite_heading(self):
+ ''' Update the sprite to reflect the current heading '''
i = (int(self._heading + 5) % 360) / (360 / SHAPES)
if not self._hidden and self.spr is not None:
try:
@@ -340,11 +349,6 @@ class Turtle:
except IndexError:
self.spr.set_shape(self._shapes[0])
- if self._turtles.turtle_window.sharing() and share:
- event = 'r|%s' % (data_to_string([self._turtles.turtle_window.nick,
- round_int(self._heading)]))
- self._turtles.turtle_window.send_event(event)
-
def set_color(self, color=None, share=True):
''' Set the pen color for this turtle. '''
# Special case for color blocks
@@ -489,7 +493,7 @@ class Turtle:
self.spr.set_layer(TURTLE_LAYER)
self._hidden = False
self.move_turtle_spr((self._x, self._y))
- self.set_heading(self._heading)
+ self.set_heading(self._heading, share=False)
if self.label_block is not None:
self.label_block.spr.set_layer(TURTLE_LAYER + 1)
@@ -525,6 +529,8 @@ class Turtle:
return
self._heading %= 360
+ self._update_sprite_heading()
+
if self._turtles.turtle_window.sharing() and share:
event = 'r|%s' % (data_to_string([self._turtles.turtle_window.nick,
round_int(self._heading)]))
@@ -562,16 +568,15 @@ class Turtle:
int(distance)]))
self._turtles.turtle_window.send_event(event)
- def set_xy(self, pos, share=True, pendown=True, dragging=False):
+ def set_xy(self, x, y, share=True, pendown=True, dragging=False):
old = self.get_xy()
-
try:
if dragging:
- xcor = pos[0]
- ycor = pos[1]
+ xcor = x
+ ycor = y
else:
- xcor = pos[0] * self._turtles.turtle_window.coord_scale
- ycor = pos[1] * self._turtles.turtle_window.coord_scale
+ xcor = x * self._turtles.turtle_window.coord_scale
+ ycor = y * self._turtles.turtle_window.coord_scale
except (TypeError, ValueError):
debug_output('bad value sent to %s' % (__name__),
self._turtles.turtle_window.running_sugar)
diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py
index 07b72d9..b0aa368 100644
--- a/TurtleArt/tautils.py
+++ b/TurtleArt/tautils.py
@@ -186,7 +186,7 @@ def find_hat(data):
def _to_str(text):
''' Convert whatever to a str type '''
if isinstance(text, unicode):
- return text.encode('ascii', 'replace')
+ return text.encode('utf-8')
elif isinstance(text, str):
return text
else:
@@ -371,7 +371,7 @@ def data_from_string(text):
if isinstance(text, str):
return json_load(text.replace(']],\n', ']], '))
elif isinstance(text, unicode):
- text = text.encode('ascii', 'replace')
+ text = text.encode('utf-8')
return json_load(text.replace(']],\n', ']], '))
else:
print 'type error (%s) in data_from_string' % (type(text))
@@ -415,7 +415,7 @@ def save_picture(canvas, file_name):
cr.set_source_surface(x_surface)
cr.paint()
if isinstance(file_name, unicode):
- img_surface.write_to_png(str(file_name.encode('ascii', 'replace')))
+ img_surface.write_to_png(str(file_name.encode('utf-8')))
else:
img_surface.write_to_png(str(file_name))
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index 4e55d5b..af611a3 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -1458,7 +1458,7 @@ class TurtleArtWindow():
self.toolbar_shapes['stopiton'].set_layer(TAB_LAYER)
self.showlabel('status',
label=_('Please hit the Stop Button \
-before making changes to your Turtle Blocks program'))
+before making changes to your program'))
self._autohide_shape = True
return True
@@ -1591,13 +1591,13 @@ before making changes to your Turtle Blocks program'))
found_the_action_block = False
bname = _('action')
if isinstance(bname, unicode):
- bname = bname.encode('ascii', 'replace')
+ bname = bname.encode('utf-8')
for sblk in similars:
cblk = sblk.connections[1]
if cblk is not None:
blabel = cblk.spr.labels[0]
if isinstance(blabel, unicode):
- blabel = blabel.encode('ascii', 'replace')
+ blabel = blabel.encode('utf-8')
if bname == blabel:
found_the_action_block = True
# If there is an action block in use, change the name
@@ -1825,7 +1825,7 @@ before making changes to your Turtle Blocks program'))
if isinstance(name, (float, int)):
return
if isinstance(name, unicode):
- name = name.encode('ascii', 'replace')
+ name = name.encode('utf-8')
for blk in self.just_blocks():
if self._action_name(blk, hat=False):
if blk.spr.labels[0] == self._saved_action_name:
@@ -1843,7 +1843,7 @@ before making changes to your Turtle Blocks program'))
if isinstance(name, (float, int)):
return
if isinstance(name, unicode):
- name = name.encode('ascii', 'replace')
+ name = name.encode('utf-8')
for blk in self.just_blocks():
if self._box_name(blk, storein=False):
if blk.spr.labels[0] == self._saved_box_name:
@@ -1861,7 +1861,7 @@ before making changes to your Turtle Blocks program'))
if isinstance(name, (float, int)):
return
if isinstance(name, unicode):
- name = name.encode('ascii', 'replace')
+ name = name.encode('utf-8')
for blk in self.just_blocks():
if self._box_name(blk, storein=True):
if blk.spr.labels[0] == self._saved_box_name:
@@ -1884,11 +1884,11 @@ before making changes to your Turtle Blocks program'))
# (3) The list of proto blocks on the palette
# (4) The list of block names
if isinstance(name, unicode):
- name = name.encode('ascii', 'replace')
+ name = name.encode('utf-8')
if isinstance(old, unicode):
- old = old.encode('ascii', 'replace')
+ old = old.encode('utf-8')
if isinstance(new, unicode):
- new = new.encode('ascii', 'replace')
+ new = new.encode('utf-8')
if old == new:
'''
@@ -3901,7 +3901,8 @@ before making changes to your Turtle Blocks program'))
''' Restore a turtle from its saved state '''
tid, name, xcor, ycor, heading, color, shade, pensize = blk
self.turtles.set_turtle(key)
- self.turtles.get_active_turtle().set_xy(xcor, ycor, pendown=False)
+ self.turtles.get_active_turtle().set_xy(xcor, ycor, share=True,
+ pendown=False)
self.turtles.get_active_turtle().set_heading(heading)
self.turtles.get_active_turtle().set_color(color)
self.turtles.get_active_turtle().set_shade(shade)
@@ -4066,7 +4067,7 @@ before making changes to your Turtle Blocks program'))
if btype == 'string' and blk.spr is not None:
value = blk.values[0]
if isinstance(value, unicode):
- value = value.encode('ascii', 'replace')
+ value = value.encode('utf-8')
blk.spr.set_label(value.replace('\n', RETURN))
elif btype == 'start': # block size is saved in start block
if value is not None:
@@ -4541,16 +4542,16 @@ before making changes to your Turtle Blocks program'))
if not self.interactive_mode:
return False
if isinstance(name, unicode):
- name = name.encode('ascii', 'replace')
+ name = name.encode('utf-8')
if isinstance(label, unicode):
- label = label.encode('ascii', 'replace')
+ label = label.encode('utf-8')
i = palette_name_to_index(palette)
for blk in self.palettes[i]:
blk_label = blk.spr.labels[0]
if isinstance(blk.name, unicode):
- blk.name = blk.name.encode('ascii', 'replace')
+ blk.name = blk.name.encode('utf-8')
if isinstance(blk_label, unicode):
- blk_label = blk_label.encode('ascii', 'replace')
+ blk_label = blk_label.encode('utf-8')
if blk.name == name and blk_label == label:
return True
# Check labels[1] too (e.g., store in block)
@@ -4567,7 +4568,7 @@ before making changes to your Turtle Blocks program'))
if isinstance(name, (float, int)):
return
if isinstance(name, unicode):
- name = name.encode('ascii', 'replace')
+ name = name.encode('utf-8')
if name == _('action'):
return
# Choose a palette for the new block.
@@ -4596,7 +4597,7 @@ before making changes to your Turtle Blocks program'))
if isinstance(name, (float, int)):
return
if isinstance(name, unicode):
- name = name.encode('ascii', 'replace')
+ name = name.encode('utf-8')
if name == _('my box'):
return
# Choose a palette for the new block.
@@ -4626,7 +4627,7 @@ before making changes to your Turtle Blocks program'))
if isinstance(name, (float, int)):
return
if isinstance(name, unicode):
- name = name.encode('ascii', 'replace')
+ name = name.encode('utf-8')
if name == _('my box'):
return
# Choose a palette for the new block.