diff options
author | Pootle daemon <pootle@pootle.sugarlabs.org> | 2013-11-03 04:30:34 (GMT) |
---|---|---|
committer | Pootle daemon <pootle@pootle.sugarlabs.org> | 2013-11-03 04:30:34 (GMT) |
commit | 24d45621438938dab9e7c5ec28b46a0ed8bf3e58 (patch) | |
tree | 0b44d76db78ddf4308e6a3cdde8ea105e959a378 | |
parent | 4af89d1f979f2ca90f964746c92d40e38645a259 (diff) | |
parent | 11e09994d89396ddfa4f551a7194151320874367 (diff) |
Merge branch 'master' of git.sugarlabs.org:turtleart/mainline
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | TurtleArt/taexportpython.py | 2 | ||||
-rw-r--r-- | TurtleArt/tajail.py | 4 | ||||
-rw-r--r-- | TurtleArt/talogo.py | 8 | ||||
-rw-r--r-- | plugins/accelerometer/accelerometer.py | 5 | ||||
-rw-r--r-- | plugins/audio_sensors/audio_sensors.py | 247 | ||||
-rw-r--r-- | plugins/camera_sensor/camera_sensor.py | 45 | ||||
-rw-r--r-- | plugins/light_sensor/light_sensor.py | 20 | ||||
-rw-r--r-- | plugins/rfid/rfid.py | 12 | ||||
-rw-r--r-- | samples/graphics-bumps.tb | 38 | ||||
-rw-r--r-- | samples/thumbnails/graphics-bumps.png | bin | 0 -> 15893 bytes |
11 files changed, 242 insertions, 140 deletions
@@ -2,6 +2,7 @@ ENHANCEMENTS: * Add Marian Zepf's export Python +* Add busy cursor while project is loading from store * New translations 192 diff --git a/TurtleArt/taexportpython.py b/TurtleArt/taexportpython.py index 458b886..c7d903d 100644 --- a/TurtleArt/taexportpython.py +++ b/TurtleArt/taexportpython.py @@ -116,7 +116,7 @@ def _action_stack_to_python(block, tw, name="start"): # traverse the block stack and get the AST for every block ast_list = _walk_action_stack(block, tw.lc) - if not isinstance(ast_list[-1], ast.Yield): + if not ast_list or not isinstance(ast_list[-1], ast.Yield): ast_list.append(ast_yield_true()) action_stack_ast = ast.Module(body=ast_list) #debug_output(str(action_stack_ast)) diff --git a/TurtleArt/tajail.py b/TurtleArt/tajail.py index 539c126..1a89f1d 100644 --- a/TurtleArt/tajail.py +++ b/TurtleArt/tajail.py @@ -34,7 +34,7 @@ def myfunc(f, args): return userdefined.values()[0](*args) -def myfunc_import(parent, f, x): +def myfunc_import(parent, f, args): ''' Run Python code imported from Journal ''' if 'def myblock(lc,' in f: base_class = parent.tw.lc # pre-v107, we passed lc @@ -43,7 +43,7 @@ def myfunc_import(parent, f, x): userdefined = {} try: exec f in globals(), userdefined - return userdefined['myblock'](base_class, x) + return userdefined['myblock'](base_class, args) except: traceback.print_exc() return None diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 1ee11f2..82c35b7 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -248,7 +248,6 @@ class LogoCode: for b in blocks: b.unhighlight() - ''' # Hidden macro expansions for b in blocks: if b.name in ['while', 'until']: @@ -262,7 +261,6 @@ class LogoCode: blocks = new_blocks[:] if b == blk: blk = action_blk - ''' for b in blocks: if b.name in ('hat', 'hat1', 'hat2'): @@ -882,12 +880,10 @@ class LogoCode: def prim_myblock(self, *args): """ Run Python code imported from Journal """ if self.bindex is not None and self.bindex in self.tw.myblock: - # try: - myfunc_import(self, self.tw.myblock[self.bindex], args) - ''' + try: + myfunc_import(self, self.tw.myblock[self.bindex], args) except: raise logoerror("#syntaxerror") - ''' def prim_myfunction(self, f, *args): """ Programmable block (Call tajail.myfunc and convert any errors to diff --git a/plugins/accelerometer/accelerometer.py b/plugins/accelerometer/accelerometer.py index c364235..f2c39e6 100644 --- a/plugins/accelerometer/accelerometer.py +++ b/plugins/accelerometer/accelerometer.py @@ -24,6 +24,7 @@ from plugins.plugin import Plugin from TurtleArt.tapalette import make_palette from TurtleArt.talogo import primitive_dictionary from TurtleArt.tautils import debug_output +from TurtleArt.taprimitive import Primitive import logging _logger = logging.getLogger('turtleart-activity accelerometer plugin') @@ -50,7 +51,6 @@ class Accelerometer(Plugin): help_string=_('Palette of sensor blocks'), position=6) - primitive_dictionary['xyz'] = self.prim_xyz if self._status: palette.add_block('xyz', style='basic-style-extended-vertical', @@ -68,7 +68,8 @@ class Accelerometer(Plugin): prim_name='xyz') self._parent.lc.def_prim( - 'xyz', 0, lambda self: primitive_dictionary['xyz']()) + 'xyz', 0, + Primitive(self.prim_xyz)) def _status_report(self): debug_output('Reporting accelerator status: %s' % (str(self._status))) diff --git a/plugins/audio_sensors/audio_sensors.py b/plugins/audio_sensors/audio_sensors.py index 1e0ed01..f520330 100644 --- a/plugins/audio_sensors/audio_sensors.py +++ b/plugins/audio_sensors/audio_sensors.py @@ -35,6 +35,8 @@ from TurtleArt.tapalette import make_palette from TurtleArt.taconstants import XO1, XO15, XO175, XO30, XO4 from TurtleArt.talogo import primitive_dictionary from TurtleArt.tautils import debug_output +from TurtleArt.taprimitive import (ConstantArg, Primitive) +from TurtleArt.tatype import TYPE_NUMBER import logging _logger = logging.getLogger('turtleart-activity audio sensors plugin') @@ -59,6 +61,7 @@ class Audio_sensors(Plugin): def __init__(self, parent): Plugin.__init__(self) self._parent = parent + self.audio_started = False self._status = True # TODO: test for audio device # These flags are referenced by audiograb self.hw = self._parent.hw @@ -66,9 +69,13 @@ class Audio_sensors(Plugin): def setup(self): ''' set up audio-sensor-specific blocks ''' + self._sound = [0, 0] + self._volume = [0, 0] + self._pitch = [0, 0] + self._resistance = [0, 0] + self._voltage = [0, 0] self.max_samples = 1500 self.input_step = 1 - self.ringbuffer = [] palette = make_palette('sensor', @@ -76,8 +83,6 @@ class Audio_sensors(Plugin): help_string=_('Palette of sensor blocks'), position=6) - primitive_dictionary['sound'] = self.prim_sound - primitive_dictionary['volume'] = self.prim_volume if self._status: palette.add_block('sound', style='box-style', @@ -109,11 +114,19 @@ class Audio_sensors(Plugin): prim_name='volume') self._parent.lc.def_prim( - 'sound', 0, lambda self: primitive_dictionary['sound'](0)) + 'sound', 0, + Primitive(self.prim_sound, + return_type=TYPE_NUMBER, + kwarg_descs={'channel': ConstantArg(0)}, + call_afterwards=self.after_sound)) + self._parent.lc.def_prim( - 'volume', 0, lambda self: primitive_dictionary['volume'](0)) + 'volume', 0, + Primitive(self.prim_volume, + return_type=TYPE_NUMBER, + kwarg_descs={'channel': ConstantArg(0)}, + call_afterwards=self.after_volume)) - primitive_dictionary['pitch'] = self.prim_pitch if PITCH_AVAILABLE and self._status: palette.add_block('pitch', style='box-style', @@ -129,11 +142,13 @@ class Audio_sensors(Plugin): help_string=_('microphone input pitch'), value_block=True, prim_name='pitch') - self._parent.lc.def_prim('pitch', 0, - lambda self: primitive_dictionary['pitch'](0)) + self._parent.lc.def_prim( + 'pitch', 0, + Primitive(self.prim_pitch, + return_type=TYPE_NUMBER, + kwarg_descs={'channel': ConstantArg(0)}, + call_afterwards=self.after_pitch)) - primitive_dictionary['resistance'] = self.prim_resistance - primitive_dictionary['voltage'] = self.prim_voltage if self.hw in [XO1, XO15, XO175, XO4, XO30] and self._status: if self.hw == XO1: self.voltage_gain = 0.000022 @@ -202,16 +217,29 @@ class Audio_sensors(Plugin): prim_name='voltage2') self._parent.lc.def_prim( 'resistance', 0, - lambda self: primitive_dictionary['resistance'](0)) + Primitive(self.prim_resistance, + return_type=TYPE_NUMBER, + kwarg_descs={'channel': ConstantArg(0)}, + call_afterwards=self.after_resistance)) self._parent.lc.def_prim( - 'voltage', 0, lambda self: primitive_dictionary['voltage'](0)) + 'voltage', 0, + Primitive(self.prim_voltage, + return_type=TYPE_NUMBER, + kwarg_descs={'channel': ConstantArg(0)}, + call_afterwards=self.after_voltage)) self._parent.lc.def_prim( 'resistance2', 0, - lambda self: primitive_dictionary['resistance'](1)) + Primitive(self.prim_resistance, + return_type=TYPE_NUMBER, + kwarg_descs={'channel': ConstantArg(1)}, + call_afterwards=self.after_resistance)) self._parent.lc.def_prim( - 'voltage2', 0, lambda self: primitive_dictionary['voltage'](1)) + 'voltage2', 0, + Primitive(self.prim_voltage, + return_type=TYPE_NUMBER, + kwarg_descs={'channel': ConstantArg(1)}, + call_afterwards=self.after_voltage)) - self.audio_started = False if self.hw in [XO175, XO30, XO4]: self.PARAMETERS = { SENSOR_AC_BIAS: (False, True, 80, True), @@ -241,6 +269,11 @@ class Audio_sensors(Plugin): ''' Start grabbing audio if there is an audio block in use ''' if not self._status: return + self._sound = [0, 0] + self._volume = [0, 0] + self._pitch = [0, 0] + self._resistance = [0, 0] + self._voltage = [0, 0] if self.audio_started: self.audiograb.stop_grabbing() if len(self._parent.block_list.get_similar_blocks( @@ -293,105 +326,104 @@ class Audio_sensors(Plugin): self._parent.running_sugar) return self._status - # Block primitives used in talogo + # Block primitives - def prim_volume(self, channel): + def prim_sound(self, channel=0): if not self._status: return 0 # Return average of both channels if sampling in stereo if self._channels == 2: - chan0 = self._prim_volume(0) - chan1 = self._prim_volume(1) - return (chan0 + chan1) / 2 + self._prim_sound(0) + self._prim_sound(1) + return (self._sound[0] + self._sound[1]) / 2.0 else: - return self._prim_volume(0) + return self._sound[0] - def _prim_volume(self, channel): - ''' return mic in value ''' + def _prim_sound(self, channel): + ''' return raw mic in value ''' buf = self.ringbuffer[channel].read(None, self.input_step) if len(buf) > 0: - volume = float(_avg(buf, abs_value=True)) - self._parent.lc.update_label_value('volume', volume) - return volume + self._sound[channel] = float(buf[0]) else: - return 0 + self._sound[channel] = 0 - def prim_sound(self, channel): + def after_sound(self, channel=0): + if self._parent.lc.update_values: + self._parent.lc.update_label_value('sound', self._sound[channel]) + + def prim_volume(self, channel=0): if not self._status: return 0 # Return average of both channels if sampling in stereo if self._channels == 2: - chan0 = self._prim_sound(0) - chan1 = self._prim_sound(1) - return (chan0 + chan1) / 2 + self._prim_volume(0) + self._prim_volume(1) + return (self._volume[0] + self._volume[1]) / 2.0 else: - return self._prim_sound(0) + return self._volume[0] - def _prim_sound(self, channel): + def _prim_volume(self, channel): ''' return raw mic in value ''' buf = self.ringbuffer[channel].read(None, self.input_step) if len(buf) > 0: - sound = float(buf[0]) - if self._parent.lc.update_values: - self._parent.lc.update_label_value('sound', sound) - return sound + self._volume[channel] = float(_avg(buf, abs_value=True)) else: - return 0 + self._volume[channel] = 0 + + def after_volume(self, channel=0): + if self._parent.lc.update_values: + self._parent.lc.update_label_value('volume', self._volume[channel]) - def prim_pitch(self, channel): - if not PITCH_AVAILABLE or not self._status: + def prim_pitch(self, channel=0): + if not self._status: return 0 # Return average of both channels if sampling in stereo if self._channels == 2: - chan0 = self._prim_pitch(0) - chan1 = self._prim_pitch(1) - return (chan0 + chan1) / 2 + self._prim_pitch(0) + self._prim_pitch(1) + return (self._pitch[0] + self._pitch[1]) / 2.0 else: - return self._prim_pitch(0) + return self._pitch[0] def _prim_pitch(self, channel): - ''' return index of max value in fft of mic in values ''' + ''' return raw mic in value ''' buf = self.ringbuffer[channel].read(None, self.input_step) if len(buf) > 0: buf = rfft(buf) buf = abs(buf) maxi = buf.argmax() if maxi == 0: - pitch = 0 + self._pitch[channel] = 0 else: # Simple interpolation a, b, c = buf[maxi - 1], buf[maxi], buf[maxi + 1] maxi -= a / float(a + b + c) maxi += c / float(a + b + c) - pitch = maxi * 48000 / (len(buf) * 2) - - if self._parent.lc.update_values: - self._parent.lc.update_label_value('pitch', pitch) - return pitch + self._pitch[channel] = maxi * 48000 / (len(buf) * 2) else: - return 0 + self._pitch[channel] = 0 + + def after_pitch(self, channel=0): + if self._parent.lc.update_values: + self._parent.lc.update_label_value('pitch', self._pitch[channel]) - def prim_resistance(self, channel): + def prim_resistance(self, channel=0): if not self.hw in [XO1, XO15, XO175, XO30, XO4] or not self._status: return 0 if self.hw in [XO1, XO4]: - resistance = self._prim_resistance(0) - if self._parent.lc.update_values: - self._update_resistance_labels(0, resistance) - return resistance + self._prim_resistance(0) + return self._resistance[0] elif self.hw == XO15: - resistance = self._prim_resistance(channel) - if self._parent.lc.update_values: - self._update_resistance_labels(channel, resistance) - return resistance + self._prim_resistance(channel) + return self._resistance[channel] # FIXME: For XO175: channel assignment is seemingly random - # (#3675), so sum both channels (one of them will be 0) + # (#3675), one of them will be 0 else: - chan0 = self._prim_resistance(0) - chan1 = self._prim_resistance(1) - resistance = chan0 + chan1 - if self._parent.lc.update_values: - self._update_resistance_labels(0, resistance) - return resistance + self._prim_resistance(0) + if self._resistance[0] != 999999999: + return self._resistance[0] + else: + self._prim_resistance(1) + return self._resistance[1] def _prim_resistance(self, channel): ''' return resistance sensor value ''' @@ -401,69 +433,68 @@ class Audio_sensors(Plugin): # TODO: test this calibration on XO 1.5, XO 1.75 avg_buf = float(_avg(buf)) if self.hw == XO1: - resistance = 2.718 ** ((avg_buf * 0.000045788) + 8.0531) + self._resistance[channel] = \ + 2.718 ** ((avg_buf * 0.000045788) + 8.0531) elif self.hw == XO15: if avg_buf > 0: - resistance = (420000000 / avg_buf) - 13500 + self._resistance[channel] = (420000000 / avg_buf) - 13500 else: - resistance = 420000000 + self._resistance[channel] = 420000000 elif self.hw in [XO175, XO4]: if avg_buf < 30700: - resistance = .12 * ((180000000 / (30700 - avg_buf)) - 3150) + self._resistance[channel] = \ + 0.12 * ((180000000 / (30700 - avg_buf)) - 3150) else: - resistance = 999999999 + self._resistance[channel] = 999999999 else: # XO 3.0 if avg_buf < 30514: - resistance = (46000000 / (30514 - avg_buf)) - 1150 + self._resistance[channel] = \ + (46000000 / (30514 - avg_buf)) - 1150 else: - resistance = 999999999 - if resistance < 0: - resistance = 0 - return resistance + self._resistance[channel] = 999999999 + if self._resistance[channel] < 0: + self._resistance[channel] = 0 else: - return 0 + self._resistance[channel] = 0 - def _update_resistance_labels(self, channel, resistance): - if channel == 0: - self._parent.lc.update_label_value('resistance', resistance) - else: - self._parent.lc.update_label_value('resistance2', resistance) + def after_resistance(self, channel=0): + if self._parent.lc.update_values: + self._parent.lc.update_label_value( + ['resistance', 'resistance2'][channel], + self._resistance[channel]) - def prim_voltage(self, channel): + def prim_voltage(self, channel=0): if not self.hw in [XO1, XO15, XO175, XO30, XO4] or not self._status: return 0 if self.hw in [XO1, XO4]: - voltage = self._prim_voltage(0) - if self._parent.lc.update_values: - self._update_voltage_labels(0, voltage) - return voltage + self._prim_voltage(0) + return self._voltage[0] elif self.hw == XO15: - voltage = self._prim_voltage(channel) - if self._parent.lc.update_values: - self._update_voltage_labels(channel, voltage) - return voltage + self._prim_voltage(channel) + return self._voltage[channel] # FIXME: For XO175: channel assignment is seemingly random - # (#3675), so sum both channels (one of them will be 0) + # (#3675), one of them will be 0 else: - chan0 = self._prim_voltage(0) - chan1 = self._prim_voltage(1) - voltage = chan0 + chan1 - if self._parent.lc.update_values: - self._update_voltage_labels(0, voltage) - return voltage + self._prim_voltage(0) + if self._voltage[0] != 0: + return self._voltage[0] + else: + self._prim_voltage(1) + return self._voltage[1] def _prim_voltage(self, channel): ''' return voltage sensor value ''' buf = self.ringbuffer[channel].read(None, self.input_step) + buf = self.ringbuffer[channel].read(None, self.input_step) if len(buf) > 0: # See <http://bugs.sugarlabs.org/ticket/552#comment:7> - voltage = float(_avg(buf)) * self.voltage_gain + self.voltage_bias - return voltage + self._voltage[channel] = \ + float(_avg(buf)) * self.voltage_gain + self.voltage_bias else: - return 0 + self._voltage[channel] = 0 - def _update_voltage_labels(self, channel, voltage): - if channel == 0: - self._parent.lc.update_label_value('voltage', voltage) - else: - self._parent.lc.update_label_value('voltage2', voltage) + def after_voltage(self, channel=0): + if self._parent.lc.update_values: + self._parent.lc.update_label_value( + ['voltage', 'voltage2'][channel], + self._voltage[channel]) diff --git a/plugins/camera_sensor/camera_sensor.py b/plugins/camera_sensor/camera_sensor.py index 585174c..d6eac89 100644 --- a/plugins/camera_sensor/camera_sensor.py +++ b/plugins/camera_sensor/camera_sensor.py @@ -34,6 +34,8 @@ from TurtleArt.talogo import media_blocks_dictionary, primitive_dictionary from TurtleArt.tautils import get_path, debug_output from TurtleArt.taconstants import MEDIA_SHAPES, NO_IMPORT, SKIN_PATHS, \ BLOCKS_WITH_SKIN +from TurtleArt.taprimitive import (ConstantArg, Primitive) +from TurtleArt.tatype import TYPE_NUMBER class Camera_sensor(Plugin): @@ -46,6 +48,7 @@ class Camera_sensor(Plugin): self._ag_control = None self.devices = [] self.cameras = [] + self.luminance = 0 if os.path.exists('/dev/video0'): self.devices.append('/dev/video0') @@ -69,7 +72,6 @@ class Camera_sensor(Plugin): position=7) # set up camera-specific blocks - primitive_dictionary['read_camera'] = self.prim_read_camera media_blocks_dictionary['camera'] = self.prim_take_picture0 media_blocks_dictionary['camera1'] = self.prim_take_picture1 @@ -83,9 +85,12 @@ class Camera_sensor(Plugin): 'light level detected by camera'), value_block=True, prim_name='luminance') - self._parent.lc.def_prim('luminance', 0, - lambda self: primitive_dictionary['read_camera']( - luminance_only=True)) + self._parent.lc.def_prim( + 'luminance', 0, + Primitive(self.prim_read_camera, + return_type=TYPE_NUMBER, + kwarg_descs={'luminance_only': ConstantArg(True)}, + call_afterwards=self.after_luminance)) # Depreciated block sensors_palette.add_block('read_camera', @@ -97,8 +102,10 @@ class Camera_sensor(Plugin): is pushed to the stack'), value_block=True, prim_name='read_camera') - self._parent.lc.def_prim('read_camera', 0, - lambda self: primitive_dictionary['read_camera']()) + self._parent.lc.def_prim( + 'read_camera', 0, + Primitive(self.prim_read_camera, + kwarg_descs={'luminance_only': ConstantArg(False)})) media_palette.add_block('camera', style='box-style-media', @@ -131,9 +138,12 @@ is pushed to the stack'), _('light level detected by camera'), value_block=True, prim_name='read_camera') - self._parent.lc.def_prim('luminance', 0, - lambda self: primitive_dictionary['read_camera']( - luminance_only=True)) + self._parent.lc.def_prim( + 'luminance', 0, + Primitive(self.prim_read_camera, + return_type=TYPE_NUMBER, + kwarg_descs={'luminance_only': ConstantArg(True)}, + call_afterwards=self.after_luminance)) # Depreciated block sensors_palette.add_block('read_camera', @@ -145,8 +155,11 @@ is pushed to the stack'), is pushed to the stack'), value_block=True, prim_name='read_camera') - self._parent.lc.def_prim('read_camera', 0, - lambda self: primitive_dictionary['read_camera']()) + self._parent.lc.def_prim( + 'read_camera', 0, + Primitive(self.prim_read_camera, + return_type=TYPE_NUMBER, + kwarg_descs={'luminance_only': ConstantArg(False)})) media_palette.add_block('camera', hidden=True, @@ -228,19 +241,19 @@ is pushed to the stack'), self._parent.lc.heap.append(-1) self._parent.lc.heap.append(-1) self._parent.lc.heap.append(-1) - return + return array = None self._set_autogain(0, camera=camera) # disable AUTOGAIN self._get_pixbuf_from_camera(camera=camera) self.calc_luminance(camera=camera) if self.luminance_only: - self._parent.lc.update_label_value('luminance', self.luminance) - return self.luminance + return int(self.luminance) else: self._parent.lc.heap.append(self.b) self._parent.lc.heap.append(self.g) self._parent.lc.heap.append(self.r) + return def calc_luminance(self, camera=0): array = self.cameras[camera].pixbuf.get_pixels() @@ -282,6 +295,10 @@ is pushed to the stack'), self.g = -1 self.b = -1 + def after_luminance(self, luminance_only=False): + if self._parent.lc.update_values and luminance_only: + self._parent.lc.update_label_value('luminance', self.luminance) + def _set_autogain(self, state, camera=0): ''' 0 is off; 1 is on ''' if self._ag_control is not None and self._ag_control.value == state: diff --git a/plugins/light_sensor/light_sensor.py b/plugins/light_sensor/light_sensor.py index 97ab6b6..cd28c14 100644 --- a/plugins/light_sensor/light_sensor.py +++ b/plugins/light_sensor/light_sensor.py @@ -24,6 +24,8 @@ from plugins.plugin import Plugin from TurtleArt.tapalette import make_palette from TurtleArt.talogo import primitive_dictionary from TurtleArt.tautils import debug_output +from TurtleArt.taprimitive import Primitive +from TurtleArt.tatype import TYPE_NUMBER import logging _logger = logging.getLogger('turtleart-activity light-sensor plugin') @@ -41,6 +43,7 @@ class Light_sensor(Plugin): self._status = True else: self._status = False + self._light = 0 self.running_sugar = self._parent.running_sugar def setup(self): @@ -50,11 +53,11 @@ class Light_sensor(Plugin): help_string=_('Palette of sensor blocks'), position=6) - primitive_dictionary['lightsensor'] = self.prim_lightsensor if self._status: palette.add_block('lightsensor', style='box-style', label=_('brightness'), + value_block=True, help_string=\ _('light level detected by light sensor'), prim_name='lightsensor') @@ -62,6 +65,7 @@ class Light_sensor(Plugin): palette.add_block('lightsensor', style='box-style', label=_('brightness'), + value_block=True, help_string=\ _('light level detected by light sensor'), hidden=True, @@ -69,20 +73,26 @@ class Light_sensor(Plugin): self._parent.lc.def_prim( 'lightsensor', 0, - lambda self: primitive_dictionary['lightsensor']()) + Primitive(self.prim_lightsensor, + return_type=TYPE_NUMBER, + call_afterwards=self.after_light)) def _status_report(self): debug_output('Reporting light-sensor status: %s' % (str(self._status))) return self._status - # Block primitives used in talogo + # Block primitives def prim_lightsensor(self): - ''' push accelerometer xyz to stack ''' if not self._status: return -1 else: fh = open(LIGHT_SENSOR_DEVICE) string = fh.read() fh.close() - return float(string) + self._light = float(string) + return self._light + + def after_light(self): + if self._parent.lc.update_values: + self._parent.lc.update_label_value('lightsensor', self._light) diff --git a/plugins/rfid/rfid.py b/plugins/rfid/rfid.py index 1b3bc48..8deac63 100644 --- a/plugins/rfid/rfid.py +++ b/plugins/rfid/rfid.py @@ -26,6 +26,8 @@ from plugins.plugin import Plugin from TurtleArt.tapalette import make_palette from TurtleArt.talogo import primitive_dictionary from TurtleArt.tautils import debug_output +from TurtleArt.taprimitive import Primitive +from TurtleArt.tatype import TYPE_STRING import logging _logger = logging.getLogger('turtleart-activity RFID plugin') @@ -81,7 +83,6 @@ class Rfid(Plugin): def setup(self): # set up RFID-specific blocks - primitive_dictionary['rfid'] = self.prim_read_rfid palette = make_palette('sensor', colors=["#FF6060", "#A06060"], help_string=_('Palette of sensor blocks'), @@ -104,7 +105,10 @@ class Rfid(Plugin): prim_name='rfid') self._parent.lc.def_prim( - 'rfid', 0, lambda self: primitive_dictionary['rfid']()) + 'rfid', 0, + Primitive(self.prim_read_rfid, + return_type=TYPE_STRING, + call_afterwards=self.after_rfid)) def _status_report(self): debug_output('Reporting RFID status: %s' % (str(self._status))) @@ -150,3 +154,7 @@ class Rfid(Plugin): return self.rfid_idn else: return '0' + + def after_rfid(self): + if self._parent.lc.update_values: + self._parent.lc.update_label_value('rfid', self.rfid_idn) diff --git a/samples/graphics-bumps.tb b/samples/graphics-bumps.tb new file mode 100644 index 0000000..951a3fb --- /dev/null +++ b/samples/graphics-bumps.tb @@ -0,0 +1,38 @@ +[[0, ["start", 2.0], 180, 180, [null, 33]], +[1, ["repeat", 42], 758, 276, [10, 2, 3, 8]], +[2, ["number", 3.0], 817, 276, [1, null]], +[3, ["arc", 0], 776, 318, [1, 4, 5, 6]], +[4, ["number", 90], 834, 318, [3, null]], +[5, ["number", 50.0], 834, 360, [3, null]], +[6, "left", 776, 402, [3, 7, null]], +[7, ["number", 90], 834, 402, [6, null]], +[8, "left", 758, 462, [1, 9, null]], +[9, ["number", 180.0], 816, 462, [8, null]], +[10, ["repeat", 93], 740, 234, [16, 11, 1, null]], +[11, ["number", 2.0], 799, 234, [10, null]], +[12, ["repeat", 21], 440, 234, [20, 13, 18, null]], +[13, ["number", 12.0], 499, 234, [12, null]], +[14, "right", 458, 318, [18, 15, null]], +[15, ["number", 30.0], 516, 318, [14, null]], +[16, "hat", 740, 180, [null, 17, 10]], +[17, ["string", "action"], 798, 192, [16, null]], +[18, "stack", 458, 276, [12, 19, 14]], +[19, ["string", "action"], 516, 276, [18, null]], +[20, "hat", 440, 180, [null, 21, 12]], +[21, ["string", "bumps"], 498, 192, [20, null]], +[22, "stack", 180, 436, [27, 23, 29]], +[23, ["string", "bumps"], 238, 436, [22, null]], +[24, "stack", 180, 562, [28, 25, null]], +[25, ["string", "bumps"], 238, 562, [24, null]], +[26, "red", 257, 520, [28, null]], +[27, "setcolor", 180, 394, [31, 37, 22]], +[28, "setcolor", 180, 520, [29, 26, 24]], +[29, "setpensize", 180, 478, [22, 30, 28]], +[30, ["number", 5], 282, 478, [29, null]], +[31, "setpensize", 180, 352, [33, 32, 27]], +[32, ["number", 20.0], 282, 352, [31, null]], +[33, "fillscreen2", 180, 226, [0, 34, 35, 36, 31]], +[34, ["number", 60], 262, 226, [33, null]], +[35, ["number", 80], 262, 268, [33, null]], +[36, ["number", 100], 262, 310, [33, null]], +[37, "yellow", 257, 394, [27, null]]] diff --git a/samples/thumbnails/graphics-bumps.png b/samples/thumbnails/graphics-bumps.png Binary files differnew file mode 100644 index 0000000..9d32c25 --- /dev/null +++ b/samples/thumbnails/graphics-bumps.png |