From 959b2d0c58236129de4955e0c48431ad152985c4 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Tue, 30 Nov 2010 14:39:40 +0000 Subject: added media wait block --- (limited to 'TurtleArt') diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index f978fd3..c1f69d5 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -139,9 +139,9 @@ PALETTES = [['clean', 'forward', 'back', 'show', 'left', 'right', ['kbinput', 'keyboard', 'readpixel', 'see', 'sound', 'volume', 'pitch'], ['journal', 'audio', 'video', 'description', 'hideblocks', - 'showblocks', 'fullscreen', 'savepix', 'savesvg', 'picturelist', - 'picture1x1a', 'picture1x1', 'picture2x2', 'picture2x1', - 'picture1x2'], + 'showblocks', 'fullscreen', 'savepix', 'savesvg', 'mediawait', + 'picturelist', 'picture1x1a', 'picture1x1', 'picture2x2', + 'picture2x1', 'picture1x2'], ['empty', 'restoreall']] # @@ -205,7 +205,7 @@ BASIC_STYLE_TAIL = ['stopstack', 'empty'] BASIC_STYLE = [] BASIC_STYLE_EXTENDED_VERTICAL = ['clean', 'penup', 'pendown', 'stack1', 'stack2', 'hideblocks', 'showblocks', 'clearheap', 'printheap', 'kbinput', - 'fullscreen', 'cartesian', 'polar', 'startfill', + 'fullscreen', 'cartesian', 'polar', 'startfill', 'mediawait', 'stopfill', 'readpixel', 'vspace'] INVISIBLE = ['sandwichcollapsed'] BASIC_STYLE_EXTENDED = ['picturelist', 'picture1x1', 'picture2x2', @@ -353,6 +353,7 @@ BLOCK_NAMES = { 'leftx': [_('picture left')], 'less2': ['<'], 'list': ['list'], + 'mediawait': [_('media wait')], 'minus2': ['–'], 'myfunc': [_('Python'), 'f(x)', 'x'], 'myfunc1arg': [_('Python'), 'f(x)', 'x'], @@ -515,6 +516,7 @@ PRIMITIVES = { 'leftx': 'leftx', 'less2': 'less?', 'list': 'bulletlist', + 'mediawait': 'mediawait', 'minus2': 'minus', 'myfunc': 'myfunction', 'myfunc1arg': 'myfunction', @@ -824,6 +826,7 @@ HELP_STRINGS = { 'leftpos': _("xcor of left of screen"), 'left': _("turns turtle counterclockwise (angle in degrees)"), 'less2': _("logical less-than operator"), + 'mediawait': _("wait for current video or audio to complete"), 'minus2': _("subtracts bottom numeric input from top numeric input"), 'myfunc': _("a programmable block: used to add advanced math equations, e.g., sin(x)"), 'myfunc1arg': _("a programmable block: used to add advanced single-variable math equations, e.g., sin(x)"), diff --git a/TurtleArt/tagplay.py b/TurtleArt/tagplay.py index 4ebd9b0..4be7f5c 100644 --- a/TurtleArt/tagplay.py +++ b/TurtleArt/tagplay.py @@ -79,10 +79,9 @@ def stop_media(lc): def media_playing(lc): - if lc.gplay == None: return False - return lc.gplay.player.playing + return lc.gplay.player.is_playing() class Gplay(): @@ -257,18 +256,19 @@ class GstPlayer(gobject.GObject): self.player.set_property('video-sink', self.bin) def pause(self): - logging.debug('pausing player') self.player.set_state(gst.STATE_PAUSED) self.playing = False + logging.debug('pausing player') def play(self): - logging.debug('playing player') self.player.set_state(gst.STATE_PLAYING) self.playing = True self.error = False + logging.debug('playing player') def stop(self): self.player.set_state(gst.STATE_NULL) + self.playing = False logging.debug('stopped player') def get_state(self, timeout=1): diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index ce4228a..e35ae52 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -40,11 +40,11 @@ except ImportError: from taconstants import TAB_LAYER, BLACK, WHITE, \ DEFAULT_SCALE, ICON_SIZE, BLOCK_NAMES, CONSTANTS, SENSOR_DC_NO_BIAS, \ SENSOR_DC_BIAS, XO1, XO15 -from tagplay import play_audio_from_file, play_movie_from_file, stop_media +from tagplay import play_audio_from_file, play_movie_from_file, stop_media, \ + media_playing from tajail import myfunc, myfunc_import -from tautils import get_pixbuf_from_journal, convert, \ - text_media_type, round_int, chr_to_ord, \ - strtype, data_from_file +from tautils import get_pixbuf_from_journal, convert, data_from_file, \ + text_media_type, round_int, chr_to_ord, strtype from RtfParser import RtfTextOnly @@ -355,6 +355,7 @@ class LogoCode: 'leftx': [0, lambda self: CONSTANTS['leftx']], 'lpos': [0, lambda self: CONSTANTS['leftpos']], 'less?': [2, lambda self, x, y: _less(x, y)], + 'mediawait': [0, self._media_wait, True], 'minus': [2, lambda self, x, y: _minus(x, y)], 'mod': [2, lambda self, x, y: _mod(x, y)], 'myfunction': [2, lambda self, f, x: self._myfunction(f, [x])], @@ -1294,6 +1295,13 @@ class LogoCode: if media[0:5] == 'descr': self._show_description(media, x, y, w, h) + def _media_wait(self): + """ Wait for media to stop playing """ + while(media_playing(self)): + yield True + self._ireturn() + yield True + def _play_sound(self, audio): """ Sound file from Journal """ if audio == "" or audio[6:] == "": -- cgit v0.9.1