From b9f147f3f72f0ce0eecf7e6598cad4b785aa4719 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 29 Dec 2010 17:03:42 +0000 Subject: refactored camera code to use poll for MESSAGE_EOS instead of timeout --- (limited to 'TurtleArt/talogo.py') diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 399b5b4..5c8a771 100755 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -44,7 +44,7 @@ from taconstants import TAB_LAYER, BLACK, WHITE, \ SENSOR_DC_BIAS, XO1, XO15 from tagplay import play_audio_from_file, play_movie_from_file, stop_media, \ media_playing -from tacamera import save_camera_input_to_file +from tacamera import Camera 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 @@ -305,6 +305,8 @@ def stop_logo(tw): tw.step_time = 0 tw.lc.step = _just_stop() stop_media(tw.lc) + if tw.camera_available: + tw.lc.camera.stop_camera_input() tw.active_turtle.show() @@ -526,19 +528,17 @@ class LogoCode: if self.tw.hw == XO1: self.voltage_gain = 0.00002225 self.voltage_bias = 1.140 - self.camera_pause = 0.6 elif self.tw.hw == XO15: self.voltage_gain = -0.0001471 self.voltage_bias = 1.695 - self.camera_pause = 0.5 - else: - self.camera_pause = 2.0 - if self.tw.running_sugar: - self.imagepath = get_path(self.tw.activity, - 'data/turtlepic.jpg') - else: - self.imagepath = '/tmp/turtlepic.jpg' + if self.tw.camera_available: + if self.tw.running_sugar: + self.imagepath = get_path(self.tw.activity, + 'data/turtlepic.png') + else: + self.imagepath = '/tmp/turtlepic.png' + self.camera = Camera(self.imagepath) def _def_prim(self, name, args, fcn, rprim=False): """ Define the primitives associated with the blocks """ @@ -1327,9 +1327,9 @@ class LogoCode: self.filepath = None dsobject = None if string[6:] == 'CAMERA': - if self.tw.camera: - save_camera_input_to_file(self.imagepath, - self.camera_pause) + if self.tw.camera_available: + self.camera.save_camera_input_to_file() + self.camera.stop_camera_input() self.filepath = self.imagepath elif os.path.exists(string[6:]): # is it a path? self.filepath = string[6:] @@ -1476,8 +1476,9 @@ class LogoCode: array = None w = self._w() h = self._h() - if w > 0 and h > 0 and self.tw.camera: - save_camera_input_to_file(self.imagepath, self.camera_pause) + if w > 0 and h > 0 and self.tw.camera_available: + self.camera.save_camera_input_to_file() + self.camera.stop_camera_input() pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(self.imagepath, w, h) try: array = pixbuf.get_pixels() -- cgit v0.9.1