From bcb715f4d8d9a1d161177393aec4c35d5fc4e3b7 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 16 Feb 2011 03:30:15 +0000 Subject: work around situations where gst is not available --- diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 2108f90..f968fb1 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -43,10 +43,6 @@ 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, \ - media_playing -from tacamera import Camera -import v4l2 from tajail import myfunc, myfunc_import from tautils import get_pixbuf_from_journal, convert, data_from_file, \ text_media_type, round_int, chr_to_ord, strtype, get_path @@ -308,7 +304,8 @@ def stop_logo(tw): """ Stop logo is called from the Stop button on the toolbar """ tw.step_time = 0 tw.lc.step = _just_stop() - stop_media(tw.lc) + if tw.gst_available: + stop_media(tw.lc) if tw.camera_available: tw.lc.camera.stop_camera_input() tw.active_turtle.show() @@ -330,6 +327,12 @@ class LogoCode: def __init__(self, tw): self.tw = tw + if self.tw.gst_available: + from tagplay import play_audio_from_file, play_movie_from_file, \ + stop_media, media_playing + from tacamera import Camera + import v4l2 + self.oblist = {} DEFPRIM = { @@ -897,7 +900,8 @@ class LogoCode: def prim_clear(self): """ Clear screen """ - stop_media(self) + if self.tw.gst_available: + stop_media(self) self.tw.canvas.clearscreen() self.scale = DEFAULT_SCALE # Note: users find this "feature" confusing @@ -1459,14 +1463,16 @@ class LogoCode: def _media_wait(self): """ Wait for media to stop playing """ - while(media_playing(self)): - yield True + if self.tw.gst_available: + while(media_playing(self)): + yield True self._ireturn() yield True def _play_sound(self): """ Sound file from Journal """ - play_audio_from_file(self, self.filepath) + if self.tw.gst_available: + play_audio_from_file(self, self.filepath) def _play_video(self): """ Movie file from Journal """ @@ -1474,8 +1480,9 @@ class LogoCode: h = self._h() if w < 1 or h < 1: return - play_movie_from_file(self, self.filepath, self._x(), self._y(), - self._w(), self._h()) + if self.tw.gst_available: + play_movie_from_file(self, self.filepath, self._x(), self._y(), + self._w(), self._h()) def _elapsed_time(self): """ Number of seconds since program execution has started or diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index 114f98d..a47be1c 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -27,7 +27,14 @@ import pygtk pygtk.require('2.0') import gtk import gobject -import gst + +try: + import gst + GST_AVAILABLE = True +except ImportError: + # Turtle Art should not fail if gst is not available + GST_AVAILABLE = False + import os import os.path import dbus @@ -76,12 +83,14 @@ from tautils import magnitude, get_load_name, get_save_name, data_from_file, \ dock_dx_dy, data_to_string, journal_check, chooser, \ get_hardware from tasprite_factory import SVG, svg_str_to_pixbuf, svg_from_file -from tagplay import stop_media from sprites import Sprites, Sprite -from audiograb import AudioGrab_Unknown, AudioGrab_XO1, AudioGrab_XO15 from rfidutils import strhex2bin, strbin2dec, find_device from dbus.mainloop.glib import DBusGMainLoop +if GST_AVAILABLE: + from tagplay import stop_media + from audiograb import AudioGrab_Unknown, AudioGrab_XO1, AudioGrab_XO15 + HAL_SERVICE = 'org.freedesktop.Hal' HAL_MGR_PATH = '/org/freedesktop/Hal/Manager' HAL_MGR_IFACE = 'org.freedesktop.Hal.Manager' @@ -103,6 +112,7 @@ class TurtleArtWindow(): self._sharing = False self.parent = parent self.send_event = None # method to send events over the network + self.gst_available = GST_AVAILABLE if type(win) == gtk.DrawingArea: self.interactive_mode = True self.window = win @@ -267,12 +277,13 @@ class TurtleArtWindow(): self.audio_started = False self.camera_available = False - v4l2src = gst.element_factory_make('v4l2src') - if v4l2src.props.device_name is not None: - PALETTES[PALETTE_NAMES.index('sensor')].append('readcamera') - PALETTES[PALETTE_NAMES.index('sensor')].append('luminance') - PALETTES[PALETTE_NAMES.index('sensor')].append('camera') - self.camera_available = True + if self.gst_available: + v4l2src = gst.element_factory_make('v4l2src') + if v4l2src.props.device_name is not None: + PALETTES[PALETTE_NAMES.index('sensor')].append('readcamera') + PALETTES[PALETTE_NAMES.index('sensor')].append('luminance') + PALETTES[PALETTE_NAMES.index('sensor')].append('camera') + self.camera_available = True self.lc = LogoCode(self) self.saved_pictures = [] @@ -426,6 +437,8 @@ class TurtleArtWindow(): def _start_audiograb(self): """ Start grabbing audio if there is an audio block in use """ + if not self.gst_available: + return if len(self.block_list.get_similar_blocks('block', ['volume', 'sound', 'pitch', 'resistance', 'voltage'])) > 0: if self.audio_started: @@ -2002,7 +2015,8 @@ class TurtleArtWindow(): elif keyname == 'q': if self.audio_started: self.audiograb.stop_grabbing() - stop_media(self.lc) + if self.gst_available: + stop_media(self.lc) exit() elif keyname == 'g': self._align_to_grid() -- cgit v0.9.1