1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#Copyright (c) 2012, Tony Forster, Ian Daniher, Walter Bender
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from gettext import gettext as _
from plugins.plugin import Plugin
from WeDoMore import WeDo
from TurtleArt.tapalette import make_palette
from TurtleArt.taconstants import XO1, XO15
from TurtleArt.talogo import primitive_dictionary
import logging
_logger = logging.getLogger('turtleart-activity WeDo plugin')
class Wedo_plugin(Plugin):
def __init__(self, parent):
self.WeDo = WeDo()
self._parent = parent
if self.WeDo.dev is None:
self._status = False # no WeDo device found
else:
self._status = True
def setup(self):
palette = make_palette('WeDo', colors=["#FF6060", "#A06060"],
help_string=_('Palette of WeDo blocks'))
primitive_dictionary['wedotilt'] = self.WeDo.getTilt
palette.add_block('tilt',
style='box-style',
label=_('tilt'),
help_string=_('tilt sensor output: (-1 == no tilt,\
0 == tilt forward, 3 == tilt back, 1 == tilt left, 2 == tilt right)'),
value_block=True,
prim_name = 'wedotilt')
self._parent.lc.def_prim(
'wedotilt', 0, lambda self: primitive_dictionary['wedotilt']())
primitive_dictionary['wedodistance'] = self.WeDo.getDistance
palette.add_block('wedodistance',
style='box-style',
label=_('distance'),
help_string=_('distance sensor output'),
value_block=True,
prim_name = 'wedodistance')
self._parent.lc.def_prim(
'wedodistance', 0,
lambda self: primitive_dictionary['wedodistance']())
primitive_dictionary['wedogetMotorA'] = self.WeDo.getMotorA
palette.add_block('wedogetMotorA',
style='box-style',
label=_('Motor A'),
help_string=_('returns the current value of Motor A'),
value_block=True,
prim_name = 'wedogetMotorA')
self._parent.lc.def_prim('wedogetMotorA', 0,
lambda self: primitive_dictionary['wedogetMotorA']())
primitive_dictionary['wedogetMotorB'] = self.WeDo.getMotorB
palette.add_block('wedogetMotorB',
style='box-style',
label=_('Motor B'),
help_string=_('returns the current value of Motor B'),
value_block=True,
prim_name = 'wedogetMotorB')
self._parent.lc.def_prim(
'wedogetMotorB', 0,
lambda self: primitive_dictionary['wedogetMotorB']())
primitive_dictionary['wedosetMotorA'] = self.WeDo.setMotorA
palette.add_block('wedosetMotorA',
style = 'basic-style-1arg',
label = _('Motor A'),
default = 30,
prim_name = 'wedosetMotorA',
help_string = _('set the value for Motor A'))
self._parent.lc.def_prim(
'wedosetMotorA', 1,
lambda self, a: primitive_dictionary['wedosetMotorA'](a))
primitive_dictionary['wedosetMotorB'] = self.WeDo.setMotorB
palette.add_block('wedosetMotorB',
style = 'basic-style-1arg',
label = _('Motor B'),
default = 30,
prim_name = 'wedosetMotorB',
help_string = _('set the value for Motor B'))
self._parent.lc.def_prim(
'wedosetMotorB', 1,
lambda self, b: primitive_dictionary['wedosetMotorB'](b))
def start(self):
pass
def stop(self):
if self._status:
self.WeDo.setMotors(0, 0)
def goto_background(self):
pass
def return_to_foreground(self):
pass
def quit(self):
if self._status:
self.WeDo.setMotors(0, 0)
|