Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/plugins/light_sensor
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-11-02 20:49:52 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-11-02 20:49:52 (GMT)
commitff1bb3aad03aa51f53336850c9d67594f8f353ce (patch)
treed0e574eaca2ffabc41f04520a16d2ecf57638314 /plugins/light_sensor
parent4d61a169283503dbc2821c85a43c1222c0825ef5 (diff)
more conversions to new primitive format
Diffstat (limited to 'plugins/light_sensor')
-rw-r--r--plugins/light_sensor/light_sensor.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/plugins/light_sensor/light_sensor.py b/plugins/light_sensor/light_sensor.py
index 97ab6b6..2e81c28 100644
--- a/plugins/light_sensor/light_sensor.py
+++ b/plugins/light_sensor/light_sensor.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 light-sensor plugin')
@@ -41,6 +42,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 +52,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 +64,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 +72,25 @@ class Light_sensor(Plugin):
self._parent.lc.def_prim(
'lightsensor', 0,
- lambda self: primitive_dictionary['lightsensor']())
+ Primitive(self.prim_lightsensor,
+ 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)