Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-02-25 15:34:01 (GMT)
committer Walter Bender <walter.bender@gmail.com>2011-02-25 15:34:01 (GMT)
commitc5eb935834b6957e50abf7c82245d3040ac269b3 (patch)
treeb56636ce8025dcfc14c20ab8cbc3e513bf0e07de /plugins
parent01eb74926f7b0e223802675bb8838e52be1ef319 (diff)
made class for block primitives
Diffstat (limited to 'plugins')
-rw-r--r--plugins/audio_sensors_plugin.py89
-rw-r--r--plugins/camera_plugin.py61
-rw-r--r--plugins/rfid_plugin.py28
3 files changed, 99 insertions, 79 deletions
diff --git a/plugins/audio_sensors_plugin.py b/plugins/audio_sensors_plugin.py
index c99321f..8f0e2d4 100644
--- a/plugins/audio_sensors_plugin.py
+++ b/plugins/audio_sensors_plugin.py
@@ -37,10 +37,9 @@ from audio.audiograb import AudioGrab_Unknown, AudioGrab_XO1, AudioGrab_XO15, \
from audio.ringbuffer import RingBuffer1d
-from TurtleArt.taconstants import PALETTES, PALETTE_NAMES, BOX_STYLE_MEDIA, \
- CONTENT_BLOCKS, BLOCK_NAMES, DEFAULTS, SPECIAL_NAMES, HELP_STRINGS, \
- BOX_STYLE, PRIMITIVES, XO1, XO15
-from TurtleArt.talogo import VALUE_BLOCKS, PLUGIN_DICTIONARY
+from TurtleArt.taprimitive import Primitive
+from TurtleArt.taconstants import BOX_STYLE, XO1, XO15
+from TurtleArt.talogo import PLUGIN_DICTIONARY
from TurtleArt.tautils import get_path
import logging
@@ -85,54 +84,68 @@ class Audio_sensors_plugin(Plugin):
self.voltage_gain = -0.0001471
self.voltage_bias = 1.695
- PALETTES[PALETTE_NAMES.index('sensor')].append('sound')
- BOX_STYLE.append('sound')
- BLOCK_NAMES['sound'] = [_('sound')]
- HELP_STRINGS['sound'] = _('raw microphone input signal')
- VALUE_BLOCKS.append('sound')
- PRIMITIVES['sound'] = 'sound'
+ sound = Primitive('sound')
+ sound.set_palette('sensor')
+ sound.set_style(BOX_STYLE)
+ sound.set_label(_('sound'))
+ sound.set_help(_('raw microphone input signal'))
+ sound.set_value_block(True)
+ sound.set_prim_name('sound')
PLUGIN_DICTIONARY['sound'] = self.prim_sound
self._parent.lc._def_prim('sound', 0,
- lambda self: PLUGIN_DICTIONARY['sound']())
- PALETTES[PALETTE_NAMES.index('sensor')].append('volume')
- BOX_STYLE.append('volume')
- BLOCK_NAMES['volume'] = [_('volume')]
- HELP_STRINGS['volume'] = _('microphone input volume')
- VALUE_BLOCKS.append('volume')
- PRIMITIVES['volume'] = 'volume'
+ lambda self: PLUGIN_DICTIONARY['sound']())
+ sound.add_prim()
+
+ volume = Primitive('volume')
+ volume.set_palette('sensor')
+ volume.set_style(BOX_STYLE)
+ volume.set_label(_('volume'))
+ volume.set_help(_('microphone input volume'))
+ volume.set_value_block(True)
+ volume.set_prim_name('volume')
PLUGIN_DICTIONARY['volume'] = self.prim_volume
self._parent.lc._def_prim('volume', 0,
- lambda self: PLUGIN_DICTIONARY['volume']())
- PALETTES[PALETTE_NAMES.index('sensor')].append('pitch')
- BOX_STYLE.append('pitch')
- BLOCK_NAMES['pitch'] = [_('pitch')]
- HELP_STRINGS['pitch'] = _('microphone input pitch')
- VALUE_BLOCKS.append('pitch')
- PRIMITIVES['pitch'] = 'pitch'
+ lambda self: PLUGIN_DICTIONARY['volume']())
+ volume.add_prim()
+
+ pitch = Primitive('pitch')
+ if PITCH_AVAILABLE:
+ pitch.set_palette('sensor')
+ pitch.set_style(BOX_STYLE)
+ pitch.set_label(_('pitch'))
+ pitch.set_help(_('microphone input pitch'))
+ pitch.set_value_block(True)
+ pitch.set_prim_name('pitch')
PLUGIN_DICTIONARY['pitch'] = self.prim_pitch
self._parent.lc._def_prim('pitch', 0,
- lambda self: PLUGIN_DICTIONARY['pitch']())
+ lambda self: PLUGIN_DICTIONARY['pitch']())
+ pitch.add_prim()
if self.hw in [XO1, XO15]:
- PALETTES[PALETTE_NAMES.index('sensor')].append('resistance')
- BOX_STYLE.append('resistance')
- BLOCK_NAMES['resistance'] = [_('resistance')]
- HELP_STRINGS['resistance'] = _('sensor input resistance')
- VALUE_BLOCKS.append('resistance')
- PRIMITIVES['resistance'] = 'resistance'
+ resistance = Primitive('resistance')
+ resistance.set_palette('sensor')
+ resistance.set_style(BOX_STYLE)
+ resistance.set_label(_('resistance'))
+ resistance.set_help(_('sensor input resistance'))
+ resistance.set_value_block(True)
+ resistance.set_prim_name('resistance')
PLUGIN_DICTIONARY['resistance'] = self.prim_resistance
self._parent.lc._def_prim('resistance', 0,
lambda self: PLUGIN_DICTIONARY['resistance']())
-
- PALETTES[PALETTE_NAMES.index('sensor')].append('voltage')
- BOX_STYLE.append('voltage')
- BLOCK_NAMES['voltage'] = [_('voltage')]
- HELP_STRINGS['voltage'] = _('sensor voltage')
- VALUE_BLOCKS.append('voltage')
- PRIMITIVES['voltage'] = 'voltage'
+ resistance.add_prim()
+
+ voltage = Primitive('voltage')
+ voltage.set_palette('sensor')
+ voltage.set_style(BOX_STYLE)
+ voltage.set_label(_('voltage'))
+ voltage.set_help(_('sensor input voltage'))
+ voltage.set_value_block(True)
+ voltage.set_prim_name('voltage')
PLUGIN_DICTIONARY['voltage'] = self.prim_voltage
self._parent.lc._def_prim('voltage', 0,
lambda self: PLUGIN_DICTIONARY['voltage']())
+ voltage.add_prim()
+
self.audio_started = False
def start(self):
diff --git a/plugins/camera_plugin.py b/plugins/camera_plugin.py
index 3061d39..960dc54 100644
--- a/plugins/camera_plugin.py
+++ b/plugins/camera_plugin.py
@@ -30,11 +30,10 @@ from camera.v4l2 import v4l2_control, V4L2_CID_AUTOGAIN, VIDIOC_G_CTRL, \
VIDIOC_S_CTRL
from plugin import Plugin
-from TurtleArt.taconstants import PALETTES, PALETTE_NAMES, BOX_STYLE_MEDIA, \
- CONTENT_BLOCKS, BLOCK_NAMES, DEFAULTS, SPECIAL_NAMES, HELP_STRINGS, \
- BOX_STYLE, PRIMITIVES
-from TurtleArt.talogo import VALUE_BLOCKS, MEDIA_BLOCKS_DICTIONARY, \
- PLUGIN_DICTIONARY
+
+from TurtleArt.taprimitive import Primitive
+from TurtleArt.taconstants import BOX_STYLE_MEDIA, BOX_STYLE
+from TurtleArt.talogo import MEDIA_BLOCKS_DICTIONARY, PLUGIN_DICTIONARY
from TurtleArt.tautils import get_path
import logging
@@ -62,35 +61,41 @@ class Camera_plugin(Plugin):
def setup(self):
# set up camera-specific blocks
if self._status:
- PALETTES[PALETTE_NAMES.index('sensor')].append('luminance')
- BOX_STYLE.append('luminance')
- BLOCK_NAMES['luminance'] = [_('brightness')]
- HELP_STRINGS['luminance'] = _("light level detected by camera")
- VALUE_BLOCKS.append('luminance')
- PRIMITIVES['luminance'] = 'luminance'
+ luminance = Primitive('luminance')
+ luminance.set_palette('sensor')
+ luminance.set_style(BOX_STYLE)
+ luminance.set_label(_('brightness'))
+ luminance.set_help(_('light level detected by camera'))
+ luminance.set_value_block(True)
+ luminance.set_prim_name('luminance')
PLUGIN_DICTIONARY['luminance'] = self.prim_read_camera
self._parent.lc._def_prim('luminance', 0,
lambda self: PLUGIN_DICTIONARY['luminance'](True))
+ luminance.add_prim()
# Depreciated block
- BOX_STYLE.append('readcamera')
- BLOCK_NAMES['readcamera'] = [_('read camera')]
- HELP_STRINGS['readcamera'] = \
- _("Average RGB color from camera is pushed to the stack")
- VALUE_BLOCKS.append('readcamera')
- PRIMITIVES['readcamera'] = 'readcamera'
- PLUGIN_DICTIONARY['readcamera'] = self.prim_read_camera
- self._parent.lc._def_prim('readcamera', 0,
- lambda self: PLUGIN_DICTIONARY['readcamera'](True))
-
- PALETTES[PALETTE_NAMES.index('sensor')].append('camera')
- BOX_STYLE_MEDIA.append('camera')
- CONTENT_BLOCKS.append('camera')
- BLOCK_NAMES['camera'] = [' ']
- DEFAULTS['camera'] = ['CAMERA']
- SPECIAL_NAMES['camera'] = _('camera')
- HELP_STRINGS['camera'] = _('camera output')
+ read_camera = Primitive('read_camera')
+ read_camera.set_style(BOX_STYLE)
+ read_camera.set_label(_('brightness'))
+ read_camera.set_help(
+ _('Average RGB color from camera is pushed to the stack'))
+ read_camera.set_value_block(True)
+ read_camera.set_prim_name('read_camera')
+ PLUGIN_DICTIONARY['read_camera'] = self.prim_read_camera
+ self._parent.lc._def_prim('read_camera', 0,
+ lambda self: PLUGIN_DICTIONARY['read_camera'](True))
+ read_camera.add_prim()
+
+ camera = Primitive('camera')
+ camera.set_palette('sensor')
+ camera.set_style(BOX_STYLE_MEDIA)
+ camera.set_label([' '])
+ camera.set_help(_('camera output'))
+ camera.set_special_name(_('camera'))
+ camera.set_content_block(True)
+ camera.set_default(['CAMERA'])
MEDIA_BLOCKS_DICTIONARY['camera'] = self.prim_take_picture
+ camera.add_prim()
def start(self):
# This gets called by the start button
diff --git a/plugins/rfid_plugin.py b/plugins/rfid_plugin.py
index e0cfafc..82f431a 100644
--- a/plugins/rfid_plugin.py
+++ b/plugins/rfid_plugin.py
@@ -27,9 +27,10 @@ from gettext import gettext as _
from rfid.rfidutils import strhex2bin, strbin2dec, find_device
from plugin import Plugin
-from TurtleArt.taconstants import PALETTES, PALETTE_NAMES, BLOCK_NAMES, \
- HELP_STRINGS, BOX_STYLE
-from TurtleArt.talogo import VALUE_BLOCKS, PLUGIN_DICTIONARY
+
+from TurtleArt.taprimitive import Primitive
+from TurtleArt.taconstants import BOX_STYLE
+from TurtleArt.talogo import PLUGIN_DICTIONARY
import logging
_logger = logging.getLogger('turtleart-activity RFID plugin')
@@ -83,18 +84,19 @@ class Rfid_plugin(Plugin):
self._status = True
def setup(self):
- # set up camera-specific blocks
+ # set up RFID-specific blocks
if self._status:
- PALETTES[PALETTE_NAMES.index('sensor')].append('rfid')
- BOX_STYLE.append('rfid')
- BLOCK_NAMES['rfid'] = [_('RFID')]
- HELP_STRINGS['rfid'] = _("read value from RFID device")
- PRIMITIVES['rfid'] = 'rfid'
- VALUE_BLOCKS.append('rfid')
- PLUGIN_DICTIONARY['rfid'] = self.prim_read_rfid
+ rfid = Primitive('rfid')
+ rfid.set_palette('sensor')
+ rfid.set_style(BOX_STYLE)
+ rfid.set_label(_('RFID'))
+ rfid.set_help(_('read value from RFID device'))
+ rfid.set_value_block(True)
+ rfid.set_prim_name('rfid')
+ PLUGIN_DICTIONARY['rfid'] = self.prim_read_camera
self._parent.lc._def_prim('rfid', 0,
- lambda self: PLUGIN_DICTIONARY['rfid']())
-
+ lambda self: PLUGIN_DICTIONARY['rfid'](True))
+ rfid.add_prim()
def start(self):
# This gets called by the start button