Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt/talogo.py
diff options
context:
space:
mode:
Diffstat (limited to 'TurtleArt/talogo.py')
-rw-r--r--TurtleArt/talogo.py78
1 files changed, 64 insertions, 14 deletions
diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py
index 1e5bf07..3e8fb0f 100644
--- a/TurtleArt/talogo.py
+++ b/TurtleArt/talogo.py
@@ -27,6 +27,8 @@ from time import time
from operator import isNumberType
from UserDict import UserDict
+from sugar.graphics import style
+
from taconstants import TAB_LAYER, DEFAULT_SCALE, PREFIX_DICTIONARY
from tapalette import block_names, value_blocks
from tautils import get_pixbuf_from_journal, convert, data_from_file, \
@@ -62,7 +64,6 @@ class symbol:
class logoerror(Exception):
def __init__(self, value):
- print value
self.value = value
def __str__(self):
@@ -149,7 +150,6 @@ class LogoCode:
def stop_logo(self):
""" Stop logo is called from the Stop button on the toolbar """
- self.tw.step_time = 0
self.step = _just_stop()
for plugin in self.tw._plugins:
plugin.stop()
@@ -157,6 +157,7 @@ class LogoCode:
from tagplay import stop_media
stop_media(self)
self.tw.active_turtle.show()
+ self.tw.running_blocks = False
def def_prim(self, name, args, fcn, rprim=False):
""" Define the primitives associated with the blocks """
@@ -192,9 +193,15 @@ 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:
- # Hidden macro expansions
- if b.name in ['while', 'until', 'forever']:
+ if b.name in ['forever']:
action_blk, new_blocks = self._expand_forever(b, blk, blocks)
blocks = new_blocks[:]
if b == blk:
@@ -216,6 +223,7 @@ class LogoCode:
except IndexError:
self.tw.showlabel('#nostack')
self.tw.showblocks()
+ self.tw.running_blocks = False
return None
if type(convert(x, float, False)) == float:
if int(float(x)) == x:
@@ -252,11 +260,10 @@ 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)
- # special case: expand 'while' and 'until' primitives
- try:
+ if blk in self.tw.block_list.list:
code.append((blk.primitive,
self.tw.block_list.list.index(blk)))
- except ValueError:
+ else:
code.append(blk.primitive) # Hidden block
elif len(blk.values) > 0: # Extract the value from content blocks.
if blk.name == 'number':
@@ -415,6 +422,7 @@ class LogoCode:
if self.bindex is not None:
self.tw.block_list.list[self.bindex].highlight()
self.tw.showblocks()
+ self.tw.display_coordinates()
raise logoerror(str(self.iresult))
self.iline = oldiline
self.ireturn()
@@ -454,6 +462,7 @@ class LogoCode:
if token.nargs == None:
self.tw.showblocks()
+ self.tw.display_coordinates()
raise logoerror("#noinput")
for i in range(token.nargs):
self._no_args_check()
@@ -497,6 +506,7 @@ class LogoCode:
except ValueError:
debug_output('generator already executing',
self.tw.running_sugar)
+ self.tw.running_blocks = False
return False
else:
return False
@@ -507,11 +517,14 @@ class LogoCode:
self.hidden_turtle = None
else:
self.tw.active_turtle.show()
+ self.tw.running_blocks = False
return False
except logoerror, e:
self.tw.showblocks()
+ self.tw.display_coordinates()
self.tw.showlabel('syntaxerror', str(e))
self.tw.turtles.show_all()
+ self.tw.running_blocks = False
return False
return True
@@ -540,6 +553,7 @@ class LogoCode:
if self.iline and self.iline[0] is not self.symnothing:
return
self.tw.showblocks()
+ self.tw.display_coordinates()
raise logoerror("#noinput")
#
@@ -562,7 +576,7 @@ class LogoCode:
self.tw.clear_plugins()
if self.tw.gst_available:
from tagplay import stop_media
- # stop_media(self) # TODO: gplay variable
+ stop_media(self)
self.tw.canvas.clearscreen()
self.scale = DEFAULT_SCALE
self.hidden_turtle = None
@@ -731,6 +745,30 @@ class LogoCode:
self.ireturn()
yield True
+ def media_stop(self):
+ """ Stop playing media"""
+ if self.tw.gst_available:
+ from tagplay import stop_media
+ stop_media(self)
+ self.ireturn()
+ yield True
+
+ def media_pause(self):
+ """ Pause media"""
+ if self.tw.gst_available:
+ from tagplay import pause_media
+ pause_media(self)
+ self.ireturn()
+ yield True
+
+ def media_play(self):
+ """ Play media"""
+ if self.tw.gst_available:
+ from tagplay import play_media
+ play_media(self)
+ self.ireturn()
+ yield True
+
def play_sound(self):
""" Sound file from Journal """
if self.tw.gst_available:
@@ -744,8 +782,17 @@ class LogoCode:
return
if self.tw.gst_available:
from tagplay import play_movie_from_file
- play_movie_from_file(self, self.filepath, self.x2tx(), self.y2ty(),
- w, h)
+ # The video window is an overlay, so we need to know where
+ # the canvas is relative to the window, e.g., which
+ # toolbars, if any are open.
+ yoffset = 0
+ if self.tw.running_sugar:
+ if not self.tw.activity.is_fullscreen():
+ yoffset += style.GRID_CELL_SIZE
+ if self.tw.activity.toolbars_expanded():
+ yoffset += style.GRID_CELL_SIZE
+ play_movie_from_file(self, self.filepath, self.x2tx(),
+ self.y2ty() + yoffset, w, h)
def _expand_forever(self, b, blk, blocks):
""" Expand a while or until block into: forever, ifelse, stopstack
@@ -755,6 +802,9 @@ class LogoCode:
# manage the connections and flows locally means we may run
# into trouble if any of these block types (forever, while,
# until. ifelse, stopstack, or stack) is changed in tablock.py
+
+ # TODO: Detect nesting, e.g., forever while
+
if b.name == 'while':
while_blk = True
else:
@@ -804,11 +854,11 @@ class LogoCode:
inflow.connections[i] = action_blk
else:
i = None
+ j = None
if outflow is not None:
- j = outflow.connections.index(b)
- outflow.connections[j] = action_blk
- else:
- j = None
+ if b in outflow.connections:
+ j = outflow.connections.index(b)
+ outflow.connections[j] = action_blk
if until_blk and whileflow is not None:
action_first.connections.append(inflow)