Ejemplo n.º 1
0
    def setup(self):
        ''' Set up the palettes '''
        sensors_palette = make_palette(
            'sensor',
            colors=["#FF6060", "#A06060"],
            help_string=_('Palette of sensor blocks'),
            position=6)
        media_palette = make_palette('media',
                                     colors=["#A0FF00", "#80A000"],
                                     help_string=_('Palette of media objects'),
                                     position=7)

        # set up camera-specific blocks
        media_blocks_dictionary['camera'] = self.prim_take_picture0
        media_blocks_dictionary['camera1'] = self.prim_take_picture1

        SKIN_PATHS.append('plugins/camera_sensor/images')

        hidden = True
        second_cam = False
        if self._status:
            hidden = False
            if len(self.devices) > 1:
                second_cam = True

        sensors_palette.add_block(
            'luminance',
            hidden=hidden,
            style='box-style',
            label=_('brightness'),
            help_string=_('light level detected by camera'),
            value_block=True,
            prim_name='luminance')
        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))

        media_palette.add_block('camera',
                                hidden=hidden,
                                style='box-style-media',
                                label=' ',
                                default='CAMERA',
                                help_string=_('camera output'),
                                content_block=True)

        media_palette.add_block('camera1',
                                hidden=not (second_cam),
                                style='box-style-media',
                                label=' ',
                                default='CAMERA',
                                help_string=_('camera output'),
                                content_block=True)

        # Depreciated block
        sensors_palette.add_block(
            'read_camera',
            hidden=True,
            style='box-style',
            label=_('brightness'),
            help_string=_(
                'Average RGB color from camera is pushed to the stack'),
            value_block=True,
            prim_name='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)}))

        NO_IMPORT.append('camera')
        BLOCKS_WITH_SKIN.append('camera')
        NO_IMPORT.append('camera1')
        BLOCKS_WITH_SKIN.append('camera1')
        MEDIA_SHAPES.append('camerasmall')
        MEDIA_SHAPES.append('cameraoff')
        MEDIA_SHAPES.append('camera1small')
        MEDIA_SHAPES.append('camera1off')
Ejemplo n.º 2
0
    def setup(self):
        """ Setup is called once, when the Turtle Window is created. """
        palette = make_palette('butia',
                               COLOR_NOTPRESENT,
                               _('Butia Robot'),
                               init_on_start=True,
                               translation=_('butia'))

        #add block about movement of butia, this blocks don't allow multiple instances

        palette.add_block(
            'refreshButia',
            style='basic-style',
            label=_('refresh Butia'),
            prim_name='refreshButia',
            help_string=_('refresh the state of the Butia palette and blocks'))
        self.tw.lc.def_prim('refreshButia', 0, Primitive(self.refresh))
        special_block_colors['refreshButia'] = COLOR_PRESENT[:]

        palette.add_block(
            'batterychargeButia',
            style='box-style',
            label=_('battery charge Butia'),
            prim_name='batterychargeButia',
            help_string=
            _('returns the battery charge in volts. If no motors present, it returns 255'
              ))
        self.tw.lc.def_prim('batterychargeButia', 0,
                            Primitive(self.getBatteryCharge, TYPE_FLOAT))
        special_block_colors['batterychargeButia'] = COLOR_NOTPRESENT[:]

        palette.add_block('speedButia',
                          style='basic-style-1arg',
                          label=[_('speed Butia')],
                          prim_name='speedButia',
                          default=[600],
                          help_string=_('set the speed of the Butia motors'))
        self.tw.lc.def_prim(
            'speedButia', 1,
            Primitive(self.speed, arg_descs=[ArgSlot(TYPE_NUMBER)]))
        special_block_colors['speedButia'] = COLOR_NOTPRESENT[:]

        palette.add_block(
            'moveButia',
            style='basic-style-2arg',
            label=[_('move Butia'), _('left'),
                   _('right')],
            prim_name='moveButia',
            default=[600, 600],
            help_string=_('moves the Butia motors at the specified speed'))
        self.tw.lc.def_prim(
            'moveButia', 2,
            Primitive(self.move,
                      arg_descs=[ArgSlot(TYPE_NUMBER),
                                 ArgSlot(TYPE_NUMBER)]))
        special_block_colors['moveButia'] = COLOR_NOTPRESENT[:]

        palette.add_block('stopButia',
                          style='basic-style',
                          label=_('stop Butia'),
                          prim_name='stopButia',
                          help_string=_('stop the Butia robot'))
        self.tw.lc.def_prim(
            'stopButia', 0, Primitive(self.stop,
                                      arg_descs=[ConstantArg(True)]))
        special_block_colors['stopButia'] = COLOR_NOTPRESENT[:]

        palette.add_block('forwardButia',
                          style='basic-style',
                          label=_('forward Butia'),
                          prim_name='forwardButia',
                          help_string=_('move the Butia robot forward'))
        self.tw.lc.def_prim('forwardButia', 0, Primitive(self.forward))
        special_block_colors['forwardButia'] = COLOR_NOTPRESENT[:]

        palette.add_block('leftButia',
                          style='basic-style',
                          label=_('left Butia'),
                          prim_name='leftButia',
                          help_string=_('turn the Butia robot at left'))
        self.tw.lc.def_prim('leftButia', 0, Primitive(self.left))
        special_block_colors['leftButia'] = COLOR_NOTPRESENT[:]

        palette.add_block('rightButia',
                          style='basic-style',
                          label=_('right Butia'),
                          prim_name='rightButia',
                          help_string=_('turn the Butia robot at right'))
        self.tw.lc.def_prim('rightButia', 0, Primitive(self.right))
        special_block_colors['rightButia'] = COLOR_NOTPRESENT[:]

        palette.add_block('backwardButia',
                          style='basic-style',
                          label=_('backward Butia'),
                          prim_name='backwardButia',
                          help_string=_('move the Butia robot backward'))
        self.tw.lc.def_prim('backwardButia', 0, Primitive(self.backward))
        special_block_colors['backwardButia'] = COLOR_NOTPRESENT[:]

        # Extra palette
        palette2 = make_palette('butia-extra',
                                COLOR_NOTPRESENT,
                                _('Butia Robot extra blocks'),
                                init_on_start=True,
                                translation=_('butia-extra'))

        # cast sensor block
        palette2.add_block(
            'castSenButia',
            style='basic-style-3arg',
            hidden=True,
            label=[_('CAST\nsensor'),
                   _('name'),
                   _('original'),
                   _('f(x)=')],
            default=[_('name'), 'A', 'x'],
            help_string=_('Cast a new sensor block'),
            prim_name='castSenButia')
        self.tw.lc.def_prim(
            'castSenButia', 3,
            Primitive(self.castSenButia,
                      arg_descs=[
                          ArgSlot(TYPE_STRING),
                          ArgSlot(TYPE_STRING),
                          ArgSlot(TYPE_STRING)
                      ]))
        special_block_colors['castSenButia'] = COLOR_PRESENT[:]

        palette2.add_block('castSenButiaMacro',
                           style='basic-style-extended-vertical',
                           label=_('CAST sensor'),
                           help_string=_('Cast a new actuator block'))

        global MACROS
        MACROS['castSenButiaMacro'] = [[
            0, 'castSenButia', 0, 0, [None, 1, 2, 3, None]
        ], [1, ['string', _('name')], 0, 0, [0, None]],
                                       [2, ['string', 'A'], 0, 0, [0, None]],
                                       [3, ['string', 'x'], 0, 0, [0, None]]]

        # cast actuator block
        palette2.add_block(
            'castActButia',
            style='basic-style-2arg',
            hidden=True,
            label=[_('CAST\nactuator'),
                   _('name'), _('original')],
            default=[_('name'), 'A'],
            help_string=_('Cast a new actuator block'),
            prim_name='castActButia')
        self.tw.lc.def_prim(
            'castActButia', 2,
            Primitive(self.castActButia,
                      arg_descs=[ArgSlot(TYPE_STRING),
                                 ArgSlot(TYPE_STRING)]))
        special_block_colors['castActButia'] = COLOR_PRESENT[:]

        palette2.add_block('castActButiaMacro',
                           style='basic-style-extended-vertical',
                           label=_('CAST actuator'),
                           help_string=_('Cast a new actuator block'))

        MACROS['castActButiaMacro'] = [[
            0, 'castActButia', 0, 0, [None, 1, 2, None]
        ], [1, ['string', _('name')], 0, 0, [0, None]],
                                       [2, ['string', 'A'], 0, 0, [0, None]]]

        # Cast palette
        palette3 = make_palette('butia-cast',
                                COLOR_NOTPRESENT,
                                _('Butia Robot cast blocks'),
                                init_on_start=True,
                                translation=_('butia-cast'))

        for j in ['led', 'modActA', 'modActB', 'modActC']:
            if (j in ['modActA', 'modActB', 'modActC']):
                pal = palette2
            else:
                pal = palette
            for m in range(MAX_SENSOR_PER_TYPE):
                if (m == 0):
                    isHidden = False
                    k = ''
                else:
                    isHidden = True
                    k = m
                module = j + str(k)
                block_name = module + 'Butia'
                pal.add_block(block_name,
                              style='basic-style-1arg',
                              label=(label_name_from_device_id[j] + str(k) +
                                     ' ' + _('Butia')),
                              prim_name=block_name,
                              default=1,
                              help_string=_(modules_help[j]),
                              hidden=isHidden)
                self.tw.lc.def_prim(
                    block_name, 1,
                    Primitive(d[j],
                              arg_descs=[ArgSlot(TYPE_NUMBER),
                                         ConstantArg(k)]))
                special_block_colors[block_name] = COLOR_NOTPRESENT[:]

        for j in [
                'button', 'gray', 'light', 'distance', 'resistanceB',
                'voltageB', 'temperature', 'modSenA', 'modSenB', 'modSenC'
        ]:
            if (j in [
                    'resistanceB', 'voltageB', 'temperature', 'modSenA',
                    'modSenB', 'modSenC'
            ]):
                pal = palette2
            else:
                pal = palette
            for m in range(MAX_SENSOR_PER_TYPE):
                if (m == 0):
                    isHidden = False
                    k = ''
                else:
                    isHidden = True
                    k = m
                module = j + str(k)
                block_name = module + 'Butia'
                pal.add_block(block_name,
                              style='box-style',
                              label=(label_name_from_device_id[j] + str(k) +
                                     ' ' + _('Butia')),
                              prim_name=block_name,
                              help_string=_(modules_help[j]),
                              hidden=isHidden)
                self.tw.lc.def_prim(
                    block_name, 0, Primitive(d[j], TYPE_INT, [ConstantArg(k)]))
                special_block_colors[block_name] = COLOR_NOTPRESENT[:]

        # hack pines

        palette3.add_block(
            'pinmodeButia',
            style='basic-style-2arg',
            label=[_('pin mode Butia'),
                   _('pin'), _('mode')],
            help_string=_('Select the pin function (INPUT, OUTPUT).'),
            default=[1],
            prim_name='pinmodeButia')
        self.tw.lc.def_prim(
            'pinmodeButia', 2,
            Primitive(self.pinMode,
                      arg_descs=[ArgSlot(TYPE_NUMBER),
                                 ArgSlot(TYPE_STRING)]))
        special_block_colors['pinmodeButia'] = COLOR_NOTPRESENT[:]

        palette3.add_block('getpinButia',
                           style='number-style-1arg',
                           label=[_('read pin Butia')],
                           prim_name='getpinButia',
                           default=1,
                           help_string=_('read the value of a pin'))
        self.tw.lc.def_prim(
            'getpinButia', 1,
            Primitive(self.getPin, TYPE_INT, [ArgSlot(TYPE_NUMBER)]))
        special_block_colors['getpinButia'] = COLOR_NOTPRESENT[:]

        palette3.add_block('setpinButia',
                           style='basic-style-2arg',
                           label=[_('write pin Butia'),
                                  _('pin'),
                                  _('value')],
                           prim_name='setpinButia',
                           default=[1, 0],
                           help_string=_('set a hack pin to 0 or 1'))
        self.tw.lc.def_prim(
            'setpinButia', 2,
            Primitive(self.setPin,
                      arg_descs=[ArgSlot(TYPE_NUMBER),
                                 ArgSlot(TYPE_NUMBER)]))
        special_block_colors['setpinButia'] = COLOR_NOTPRESENT[:]

        global CONSTANTS
        CONSTANTS['INPUT'] = _('INPUT')
        palette3.add_block(
            'inputButia',
            style='box-style',
            label=_('INPUT'),
            help_string=_('Configure hack pin for digital input.'),
            prim_name='inputButia')
        self.tw.lc.def_prim(
            'inputButia', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('INPUT')]))
        special_block_colors['inputButia'] = COLOR_NOTPRESENT[:]

        CONSTANTS['HIGH'] = 1
        palette3.add_block('highButia',
                           style='box-style',
                           label=_('HIGH'),
                           help_string=_('Set HIGH value for digital pin.'),
                           prim_name='highButia')
        self.tw.lc.def_prim(
            'highButia', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('HIGH')]))
        special_block_colors['highButia'] = COLOR_NOTPRESENT[:]

        CONSTANTS['LOW'] = 0
        palette3.add_block('lowButia',
                           style='box-style',
                           label=_('LOW'),
                           help_string=_('Set LOW value for digital port.'),
                           prim_name='lowButia')
        self.tw.lc.def_prim(
            'lowButia', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('LOW')]))
        special_block_colors['lowButia'] = COLOR_NOTPRESENT[:]

        CONSTANTS['OUTPUT'] = _('OUTPUT')
        palette3.add_block(
            'outputButia',
            style='box-style',
            label=_('OUTPUT'),
            help_string=_('Configure hack port for digital output.'),
            prim_name='outputButia')
        self.tw.lc.def_prim(
            'outputButia', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('OUTPUT')]))
        special_block_colors['outputButia'] = COLOR_NOTPRESENT[:]

        palette3.add_block(
            'firmwareButia',
            style='box-style',
            label=_('firmware Butia'),
            prim_name='firmwareButia',
            help_string=_('returns the Firmware version of Butia robot'))
        self.tw.lc.def_prim('firmwareButia', 0,
                            Primitive(self.getFirmware, TYPE_INT))
        special_block_colors['firmwareButia'] = COLOR_PRESENT[:]

        palette3.add_block(
            'actualIpButia',
            style='number-style-1arg',
            label=_('get IP'),
            default='wlan0',
            prim_name='actualIpButia',
            help_string=_('returns the current IP of the computer'))
        self.tw.lc.def_prim(
            'actualIpButia', 1,
            Primitive(self.getActualIP, TYPE_INT, [ArgSlot(TYPE_STRING)]))
        special_block_colors['actualIpButia'] = COLOR_PRESENT[:]

        palette3.add_block('changeIpButia',
                           style='basic-style-1arg',
                           label=_('Butia IP'),
                           default='localhost',
                           help_string=_('change the IP of Butia robot'),
                           prim_name='changeIpButia')
        self.tw.lc.def_prim(
            'changeIpButia', 1,
            Primitive(self.prim_change_ipButia,
                      arg_descs=[ArgSlot(TYPE_STRING)]))
        special_block_colors['changeIpButia'] = COLOR_PRESENT[:]

        CONSTANTS['wireless network'] = 'wlan0'
        palette3.add_block('const_wirelessButia',
                           style='box-style',
                           label=_('wireless'),
                           help_string=_('wireless network'),
                           prim_name='const_wirelessButia')
        self.tw.lc.def_prim(
            'const_wirelessButia', 0,
            Primitive(CONSTANTS.get, TYPE_STRING,
                      [ConstantArg('wireless network')]))
        special_block_colors['const_wirelessButia'] = COLOR_PRESENT[:]

        CONSTANTS['wired network'] = 'eth0'
        palette3.add_block('const_wiredButia',
                           style='box-style',
                           label=_('wired'),
                           help_string=_('wired network'),
                           prim_name='const_wiredButia')
        self.tw.lc.def_prim(
            'const_wiredButia', 0,
            Primitive(CONSTANTS.get, TYPE_STRING,
                      [ConstantArg('wired network')]))
        special_block_colors['const_wiredButia'] = COLOR_PRESENT[:]

        palette3.add_block('selectButia',
                           style='basic-style-1arg',
                           default=1,
                           label=_('Butia'),
                           help_string=_('set current Butia robot'),
                           prim_name='selectButia')
        self.tw.lc.def_prim(
            'selectButia', 1,
            Primitive(self.selectButia, arg_descs=[ArgSlot(TYPE_NUMBER)]))
        special_block_colors['selectButia'] = COLOR_PRESENT[:]
Ejemplo n.º 3
0
    def change_butia_palette_colors(self, force_refresh, change_statics_blocks,
                                    change_extras_blocks):

        self.make_match_dict()

        self.getCastButia()

        for blk in self.tw.block_list.list:
            #NOTE: blocks types: proto, block, trash, deleted
            if (blk.type in ['proto', 'block']) and blk.name.endswith('Butia'):
                if (blk.name in static_block_list):
                    if change_statics_blocks:
                        if (blk.name == 'batterychargeButia'):
                            if self.use_cc:
                                blk.set_visibility(False)
                            else:
                                blk.set_visibility(True)
                            special_block_colors[
                                blk.name] = self.battery_color[:]
                        else:
                            special_block_colors[
                                blk.name] = self.statics_color[:]
                        blk.refresh()
                elif (blk.name in extras_block_list):
                    if change_extras_blocks:
                        special_block_colors[blk.name] = self.extras_color[:]
                        blk.refresh()
                else:
                    blk_name, blk_index = self.block_2_index_and_name(blk.name)
                    if (blk_name in refreshable_block_list):
                        module = modules_name_from_device_id[blk_name]
                        if (module in self.modules_changed) or force_refresh:
                            s = module + blk_index

                            label = label_name_from_device_id[blk_name]

                            if not (s in self.match_dict):
                                if blk_index != '':
                                    if blk.type == 'proto':  # only make invisible the block in the palette not in the program area
                                        blk.set_visibility(False)
                                    value = str(blk_index)
                                else:
                                    value = '0'
                                label = label + ' ' + _('Butia')
                                board = '0'
                                special_block_colors[
                                    blk.name] = COLOR_NOTPRESENT[:]
                            else:
                                val = self.match_dict[s]
                                value = val[0]
                                board = val[1]
                                label = label + ':' + val[0] + ' ' + _('Butia')
                                if self.butia_count > 1:
                                    label = label + ' ' + val[1]
                                if blk.type == 'proto':  # don't has sense to change the visibility of a block in the program area
                                    blk.set_visibility(True)
                                special_block_colors[
                                    blk.name] = COLOR_PRESENT[:]

                            if module in [
                                    'led', 'modActA', 'modActB', 'modActC'
                            ]:
                                self.tw.lc.def_prim(
                                    blk.name, 1,
                                    Primitive(d[blk_name],
                                              arg_descs=[
                                                  ArgSlot(TYPE_NUMBER),
                                                  ConstantArg(value),
                                                  ConstantArg(board)
                                              ]))
                            else:
                                self.tw.lc.def_prim(
                                    blk.name, 0,
                                    Primitive(d[blk_name],
                                              return_type=TYPE_INT,
                                              arg_descs=[
                                                  ConstantArg(value),
                                                  ConstantArg(board)
                                              ]))

                            blk.spr.set_label(label)
                            block_names[blk.name][0] = label
                            blk.refresh()

        try:
            index = palette_name_to_index('butia')
            self.tw.regenerate_palette(index)
        except:
            pass

        try:
            index = palette_name_to_index('butia-extra')
            self.tw.regenerate_palette(index)
        except:
            pass

        try:
            index = palette_name_to_index('butia-cast')
            self.tw.regenerate_palette(index)
        except:
            pass
Ejemplo n.º 4
0
    def setup(self):

        # Palette of Motors
        palette_motors = make_palette(
            'nxt-motors',
            COLOR_NOTPRESENT,
            _('Palette of LEGO NXT blocks of motors'),
            translation=_('nxt-motors'))

        palette_motors.add_block(
            'nxtrefresh',
            style='basic-style',
            label=_('refresh NXT'),
            prim_name='nxtrefresh',
            help_string=_('Search for a connected NXT brick.'))
        self.tw.lc.def_prim('nxtrefresh', 0, Primitive(self.refresh))
        special_block_colors['nxtrefresh'] = COLOR_PRESENT[:]

        palette_motors.add_block('nxtselect',
                                 style='basic-style-1arg',
                                 default=1,
                                 label=_('NXT'),
                                 help_string=_('set current NXT device'),
                                 prim_name='nxtselect')
        self.tw.lc.def_prim(
            'nxtselect', 1,
            Primitive(self.select, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette_motors.add_block('nxtcount',
                                 style='box-style',
                                 label=_('number of NXTs'),
                                 help_string=_('number of NXT devices'),
                                 prim_name='nxtcount')
        self.tw.lc.def_prim('nxtcount', 0, Primitive(self.count, TYPE_INT))

        palette_motors.add_block('nxtbrickname',
                                 style='number-style-1arg',
                                 label=_('brick name'),
                                 default=[1],
                                 help_string=_('Get the name of a brick.'),
                                 prim_name='nxtbrickname')
        self.tw.lc.def_prim(
            'nxtbrickname', 1,
            Primitive(self.brickname, TYPE_STRING, [ArgSlot(TYPE_NUMBER)]))

        palette_motors.add_block(
            'nxtplaytone',
            style='basic-style-2arg',
            label=[_('play tone'), _('frequency'),
                   _('time')],
            default=[433, 500],
            help_string=_('Play a tone at frequency for time.'),
            prim_name='nxtplaytone')
        self.tw.lc.def_prim(
            'nxtplaytone', 2,
            Primitive(self.playtone,
                      arg_descs=[ArgSlot(TYPE_NUMBER),
                                 ArgSlot(TYPE_NUMBER)]))

        palette_motors.add_block(
            'nxtsyncmotors',
            style='basic-style-2arg',
            label=[
                _('synchronize %s motors') % SYNC_STRING1,
                _('power'),
                _('rotations')
            ],
            default=[100, 1],
            help_string=_(
                'synchronize two motors connected in PORT B and PORT C'),
            prim_name='nxtsyncmotors')
        self.tw.lc.def_prim(
            'nxtsyncmotors', 2,
            Primitive(self.syncmotors,
                      arg_descs=[ArgSlot(TYPE_NUMBER),
                                 ArgSlot(TYPE_NUMBER)]))

        palette_motors.add_block(
            'nxtsyncmotorsforever',
            style='basic-style-1arg',
            label=[_('synchronize %s motors') % SYNC_STRING2,
                   _('power')],
            default=[100],
            help_string=_(
                'synchronize two motors connected in PORT B and PORT C'),
            prim_name='nxtsyncmotorsforever')
        self.tw.lc.def_prim(
            'nxtsyncmotorsforever', 1,
            Primitive(self.syncmotorsforever,
                      arg_descs=[ArgSlot(TYPE_NUMBER)]))

        global CONSTANTS
        CONSTANTS['PORT A'] = 'A'
        palette_motors.add_block('nxtporta',
                                 style='box-style',
                                 label=_('PORT %s') % 'A',
                                 help_string=_('PORT %s of the brick') % 'A',
                                 prim_name='nxtporta')
        self.tw.lc.def_prim(
            'nxtporta', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('PORT A')]))

        CONSTANTS['PORT B'] = 'B'
        palette_motors.add_block('nxtportb',
                                 style='box-style',
                                 label=_('PORT %s') % 'B',
                                 help_string=_('PORT %s of the brick') % 'B',
                                 prim_name='nxtportb')
        self.tw.lc.def_prim(
            'nxtportb', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('PORT B')]))

        CONSTANTS['PORT C'] = 'C'
        palette_motors.add_block('nxtportc',
                                 style='box-style',
                                 label=_('PORT %s') % 'C',
                                 help_string=_('PORT %s of the brick') % 'C',
                                 prim_name='nxtportc')
        self.tw.lc.def_prim(
            'nxtportc', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('PORT C')]))

        palette_motors.add_block(
            'nxtstartmotor',
            style='basic-style-2arg',
            label=[_('start motor'), _('port'),
                   _('power')],
            default=['A', 100],
            help_string=_('Run a motor forever.'),
            prim_name='nxtstartmotor')
        self.tw.lc.def_prim(
            'nxtstartmotor', 2,
            Primitive(self.startmotor,
                      arg_descs=[ArgSlot(TYPE_STRING),
                                 ArgSlot(TYPE_NUMBER)]))

        palette_motors.add_block('nxtbrake',
                                 style='basic-style-1arg',
                                 label=_('brake motor'),
                                 default=['A'],
                                 help_string=_('Stop a specified motor.'),
                                 prim_name='nxtbrake')
        self.tw.lc.def_prim(
            'nxtbrake', 1,
            Primitive(self.brake, arg_descs=[ArgSlot(TYPE_STRING)]))

        palette_motors.add_block('nxtturnmotor',
                                 style='basic-style-3arg',
                                 hidden=True,
                                 label=[
                                     _('turn motor %s') % '\n\n',
                                     _('port'),
                                     _('rotations'),
                                     _('power')
                                 ],
                                 default=['A', 1, 100],
                                 help_string=_('turn a motor'),
                                 prim_name='nxtturnmotor')
        self.tw.lc.def_prim(
            'nxtturnmotor', 3,
            Primitive(self.turnmotor,
                      arg_descs=[
                          ArgSlot(TYPE_STRING),
                          ArgSlot(TYPE_NUMBER),
                          ArgSlot(TYPE_NUMBER)
                      ]))

        palette_motors.add_block('nxtturnmotorMacro',
                                 style='basic-style-extended-vertical',
                                 label=_('turn motor %s') % '',
                                 help_string=_('turn a motor'))

        global MACROS
        MACROS['nxtturnmotorMacro'] = [[
            0, 'nxtturnmotor', 0, 0, [None, 1, 2, 3, None]
        ], [1, ['string', 'A'], 0, 0, [0, None]],
                                       [2, ['number', 1], 0, 0, [0, None]],
                                       [3, ['number', 100], 0, 0, [0, None]]]

        palette_motors.add_block('nxtmotorreset',
                                 style='basic-style-1arg',
                                 label=_('reset motor'),
                                 default=['A'],
                                 help_string=_('Reset the motor counter.'),
                                 prim_name='nxtmotorreset')
        self.tw.lc.def_prim(
            'nxtmotorreset', 1,
            Primitive(self.motorreset, arg_descs=[ArgSlot(TYPE_STRING)]))

        palette_motors.add_block('nxtmotorposition',
                                 style='number-style-1arg',
                                 label=_('motor position'),
                                 default=['A'],
                                 help_string=_('Get the motor position.'),
                                 prim_name='nxtmotorposition')
        self.tw.lc.def_prim(
            'nxtmotorposition', 1,
            Primitive(self.motorposition,
                      TYPE_INT,
                      arg_descs=[ArgSlot(TYPE_STRING)]))

        ######################### Palette of Sensors ###########################

        palette_sensors = make_palette(
            'nxt-sensors',
            COLOR_NOTPRESENT,
            _('Palette of LEGO NXT blocks of sensors'),
            translation=_('nxt-sensors'))

        palette_sensors.add_block('nxtlight',
                                  style='number-style-1arg',
                                  label=_('light'),
                                  default=[1],
                                  help_string=_('light sensor'),
                                  prim_name='nxtlight')
        self.tw.lc.def_prim(
            'nxtlight', 1,
            Primitive(self.getLight, TYPE_INT, [ArgSlot(TYPE_INT)]))

        palette_sensors.add_block('nxtgray',
                                  style='number-style-1arg',
                                  label=_('gray'),
                                  default=[1],
                                  help_string=_('gray sensor'),
                                  prim_name='nxtgray')
        self.tw.lc.def_prim(
            'nxtgray', 1, Primitive(self.getGray, TYPE_INT,
                                    [ArgSlot(TYPE_INT)]))

        palette_sensors.add_block('nxtbutton',
                                  style='number-style-1arg',
                                  label=_('button'),
                                  default=[1],
                                  help_string=_('button sensor'),
                                  prim_name='nxtbutton')
        self.tw.lc.def_prim(
            'nxtbutton', 1,
            Primitive(self.getButton, TYPE_INT, [ArgSlot(TYPE_INT)]))

        palette_sensors.add_block('nxtdistance',
                                  style='number-style-1arg',
                                  label=_('distance'),
                                  default=[1],
                                  help_string=_('distance sensor'),
                                  prim_name='nxtdistance')
        self.tw.lc.def_prim(
            'nxtdistance', 1,
            Primitive(self.getDistance, TYPE_INT, [ArgSlot(TYPE_INT)]))

        palette_sensors.add_block('nxtsound',
                                  style='number-style-1arg',
                                  label=_('sound'),
                                  default=[1],
                                  help_string=_('sound sensor'),
                                  prim_name='nxtsound')
        self.tw.lc.def_prim(
            'nxtsound', 1,
            Primitive(self.getSound, TYPE_INT, [ArgSlot(TYPE_INT)]))

        palette_sensors.add_block('nxtcolor',
                                  style='number-style-1arg',
                                  label=_('color'),
                                  default=[1],
                                  help_string=_('color sensor'),
                                  prim_name='nxtcolor')
        self.tw.lc.def_prim(
            'nxtcolor', 1,
            Primitive(self.getColor, TYPE_INT, [ArgSlot(TYPE_INT)]))

        CONSTANTS['PORT 1'] = 1
        palette_sensors.add_block('nxtport1',
                                  style='box-style',
                                  label=_('PORT %s') % 1,
                                  help_string=_('PORT %s of the brick') % 1,
                                  prim_name='nxtport1')
        self.tw.lc.def_prim(
            'nxtport1', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('PORT 1')]))

        CONSTANTS['PORT 2'] = 2
        palette_sensors.add_block('nxtport2',
                                  style='box-style',
                                  label=_('PORT %s') % 2,
                                  help_string=_('PORT %s of the brick') % 2,
                                  prim_name='nxtport2')
        self.tw.lc.def_prim(
            'nxtport2', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('PORT 2')]))

        CONSTANTS['PORT 3'] = 3
        palette_sensors.add_block('nxtport3',
                                  style='box-style',
                                  label=_('PORT %s') % 3,
                                  help_string=_('PORT %s of the brick') % 3,
                                  prim_name='nxtport3')
        self.tw.lc.def_prim(
            'nxtport3', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('PORT 3')]))

        CONSTANTS['PORT 4'] = 4
        palette_sensors.add_block('nxtport4',
                                  style='box-style',
                                  label=_('PORT %s') % 4,
                                  help_string=_('PORT %s of the brick') % 4,
                                  prim_name='nxtport4')
        self.tw.lc.def_prim(
            'nxtport4', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('PORT 4')]))

        palette_sensors.add_block(
            'nxtbattery',
            style='box-style',
            label=_('battery level'),
            help_string=_('Get the battery level of the brick in millivolts'),
            prim_name='nxtbattery')
        self.tw.lc.def_prim('nxtbattery', 0, Primitive(self.battery, TYPE_INT))

        palette_sensors.add_block(
            'nxtlightcolor',
            style='number-style-1arg',
            label=_('color as light'),
            default=[1],
            help_string=_('use color sensor as light sensor'),
            prim_name='nxtlightcolor')
        self.tw.lc.def_prim(
            'nxtlightcolor', 1,
            Primitive(self.getLightColor, TYPE_INT, [ArgSlot(TYPE_INT)]))

        palette_sensors.add_block(
            'nxtsetcolor',
            style='basic-style-2arg',
            label=[_('set light'), _('port'),
                   _('color')],
            default=[1],
            help_string=_('Set color sensor light.'),
            prim_name='nxtsetcolor')
        self.tw.lc.def_prim(
            'nxtsetcolor', 2,
            Primitive(self.setcolor,
                      arg_descs=[ArgSlot(TYPE_INT),
                                 ArgSlot(TYPE_INT)]))

        palette_sensors.add_block('nxtcompass',
                                  style='number-style-1arg',
                                  label=_('compass'),
                                  default=[1],
                                  help_string=_('compass sensor'),
                                  prim_name='nxtcompass')
        self.tw.lc.def_prim(
            'nxtcompass', 1,
            Primitive(self.getCompass, TYPE_INT, [ArgSlot(TYPE_INT)]))
Ejemplo n.º 5
0
    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',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)
        hidden = True
        if self._status:
            hidden = False

        palette.add_block('sound',
                          hidden=hidden,
                          style='box-style',
                          label=_('sound'),
                          help_string=_('raw microphone input signal'),
                          value_block=True,
                          prim_name='sound')
        palette.add_block('volume',
                          hidden=hidden,
                          style='box-style',
                          label=_('loudness'),
                          help_string=_('microphone input volume'),
                          value_block=True,
                          prim_name='volume')

        self._parent.lc.def_prim(
            '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,
            Primitive(self.prim_volume,
                      return_type=TYPE_NUMBER,
                      kwarg_descs={'channel': ConstantArg(0)},
                      call_afterwards=self.after_volume))

        hidden = True
        if PITCH_AVAILABLE and self._status:
            hidden = False

        palette.add_block('pitch',
                          hidden=hidden,
                          style='box-style',
                          label=_('pitch'),
                          help_string=_('microphone input pitch'),
                          value_block=True,
                          prim_name='pitch')
        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))

        hidden = True
        if self.hw in [XO1, XO15, XO175, XO4, XO30] and self._status:
            # Calibration based on http://bugs.sugarlabs.org/ticket/4649
            if self.hw == XO1:
                self.voltage_gain = 0.000022
                self.voltage_bias = 1.14
            elif self.hw == XO15:
                self.voltage_gain = -0.00015
                self.voltage_bias = 1.70
            elif self.hw == XO175:  # Range 0.01V to 3.01V
                self.voltage_gain = 0.0000516
                self.voltage_bias = 1.3598
            elif self.hw == XO4:  # Range 0.17V to 3.08V
                self.voltage_gain = 0.0004073
                self.voltage_bias = 1.6289
            else:  # XO 3.0
                self.voltage_gain = 0.000077
                self.voltage_bias = 0.72
            hidden = False

        palette.add_block('resistance',
                          hidden=hidden,
                          style='box-style',
                          label=_('resistance'),
                          help_string=_('microphone input resistance'),
                          prim_name='resistance')
        palette.add_block('voltage',
                          hidden=hidden,
                          style='box-style',
                          label=_('voltage'),
                          help_string=_('microphone input voltage'),
                          prim_name='voltage')

        hidden = True
        # Only add stereo capture for XO15 (broken on ARM #3675)
        if self.hw in [XO15] and self._status:
            hidden = False

        palette.add_block('resistance2',
                          hidden=hidden,
                          style='box-style',
                          label=_('resistance') + '2',
                          help_string=_('microphone input resistance'),
                          prim_name='resistance2')
        palette.add_block('voltage2',
                          hidden=hidden,
                          style='box-style',
                          label=_('voltage') + '2',
                          help_string=_('microphone input voltage'),
                          prim_name='voltage2')
        self._parent.lc.def_prim(
            '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,
            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,
            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,
            Primitive(self.prim_voltage,
                      return_type=TYPE_NUMBER,
                      kwarg_descs={'channel': ConstantArg(1)},
                      call_afterwards=self.after_voltage))

        if self.hw in [XO15, XO175, XO30, XO4]:
            self.PARAMETERS = {
                SENSOR_AC_BIAS: (False, True, 80, True),
                SENSOR_DC_NO_BIAS: (True, False, 80, False),
                SENSOR_DC_BIAS: (True, True, 90, False)
            }
        elif self.hw == XO1:
            self.PARAMETERS = {
                SENSOR_AC_BIAS: (False, True, 40, True),
                SENSOR_DC_NO_BIAS: (True, False, 0, False),
                SENSOR_DC_BIAS: (True, True, 0, False)
            }
        else:
            self.PARAMETERS = {
                SENSOR_AC_BIAS: (None, True, 40, True),
                SENSOR_DC_NO_BIAS: (True, False, 80, False),
                SENSOR_DC_BIAS: (True, True, 90, False)
            }
Ejemplo n.º 6
0
    def setup(self):
        # set up X11 events specific blocks
        palette = make_palette('xlib-bots',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of X11 event blocks'))

        palette.add_block('setX11mouse',
                          style='basic-style-2arg',
                          label=_('setXY'),
                          value_block=True,
                          default=[0, 0],
                          help_string=_('set the mouse pointer to' +
                                        'x y coordinates'),
                          prim_name='set_x11_mouse')

        palette.add_block('getX11mouseX',
                          style='box-style',
                          label=_('getMouseX'),
                          value_block=True,
                          help_string=_('get the mouse pointer x coordinate'),
                          prim_name='get_x11_mouse_x')

        palette.add_block('getX11mouseY',
                          style='box-style',
                          label=_('getMouseY'),
                          value_block=True,
                          help_string=_('get the mouse pointer y coordinate'),
                          prim_name='get_x11_mouse_y')

        palette.add_block('leftClick',
                          style='box-style',
                          label=_('leftClick'),
                          value_block=True,
                          help_string=_('click left click'),
                          prim_name='left_click')

        palette.add_block('rightClick',
                          style='box-style',
                          label=_('rightClick'),
                          value_block=True,
                          help_string=_('click right click'),
                          prim_name='right_click')

        palette.add_block('true',
                          style='box-style',
                          label=_('true'),
                          value_block=True,
                          help_string=_('true'),
                          prim_name='true')

        palette.add_block('false',
                          style='box-style',
                          label=_('false'),
                          value_block=True,
                          help_string=_('false'),
                          prim_name='false')

        palette.add_block('click',
                          style='basic-style-1arg',
                          label=_('click'),
                          value_block=True,
                          default=[1],
                          help_string=_('simulate a mouse click'),
                          prim_name='click')

        palette.add_block('doubleClick',
                          style='basic-style-1arg',
                          label=_('double click'),
                          value_block=True,
                          default=[1],
                          help_string=_('simulate a mouse double click'),
                          prim_name='double_click')

        palette.add_block('getScreenWidth',
                          style='box-style',
                          label=_('getScreenWidth'),
                          value_block=True,
                          help_string=_('get the screen width'),
                          prim_name='get_screen_width')

        palette.add_block('getScreenHeight',
                          style='box-style',
                          label=_('getScreenHeight'),
                          value_block=True,
                          help_string=_('get the screen height'),
                          prim_name='get_screen_height')

        palette.add_block('pressButton',
                          style='basic-style-1arg',
                          label=_('pressButton'),
                          value_block=True,
                          default=[0],
                          help_string=_('keeps button pressed'),
                          prim_name='press_button')

        palette.add_block('releaseButton',
                          style='basic-style-1arg',
                          label=_('releaseButton'),
                          value_block=True,
                          default=[0],
                          help_string=_('releases button'),
                          prim_name='release_button')

        palette.add_block('freeze',
                          style='basic-style-1arg',
                          label=_('freeze bar'),
                          value_block=True,
                          default=[0],
                          help_string=_('freeze the bar'),
                          prim_name='freeze')

        palette.add_block('setLineColorRGB',
                          hidden=True,
                          style='basic-style-3arg',
                          label=_('setLineColorRGB'),
                          value_block=True,
                          default=[0, 0, 0],
                          help_string=_('set line color from rgb value'),
                          prim_name='set_line_color_rgb')

        palette.add_block('setLineColorRGBmacro',
                          style='basic-style-extended-vertical',
                          label=_('setLineColorRGB'),
                          help_string=_('set line color from rgb value'))

        palette.add_block('setLineColor',
                          style='basic-style-1arg',
                          label=_('setLineColor'),
                          value_block=True,
                          help_string=_('set line color'),
                          prim_name='set_line_color')

        palette.add_block('setLineOpacity',
                          style='basic-style-1arg',
                          label=_('setLineOpacity'),
                          value_block=True,
                          default=[1],
                          help_string=_('set line opacity'),
                          prim_name='set_line_opacity')

        palette.add_block('showLine',
                          style='basic-style-1arg',
                          label=_('showLine'),
                          value_block=True,
                          default=[1],
                          help_string=_('show vertical line over mouse'),
                          prim_name='show_line')

        palette.add_block('setLineWidth',
                          style='basic-style-1arg',
                          label=_('setLineWidth'),
                          value_block=True,
                          default=[0],
                          help_string=_('width of vertical line over mouse'),
                          prim_name='set_line_width')

        palette.add_block('setLineHeight',
                          style='basic-style-1arg',
                          label=_('setLineHeight'),
                          value_block=True,
                          default=[0],
                          help_string=_('height of vertical line over mouse'),
                          prim_name='set_line_height')

        palette.add_block(
            'setLineWidthAndHeigth',
            hidden=True,
            style='basic-style-2arg',
            label=_('setLineWidthAndHeigth'),
            value_block=True,
            default=[0, 0],
            help_string=_('set width and height of line over mouse'),
            prim_name='set_line_width_and_heigth')

        palette.add_block(
            'setLineWidthAndHeigthmacro',
            style='basic-style-extended-vertical',
            label=_('setLineWidthAndHeigth'),
            help_string=_('set width and height of line over mouse'))

        palette.add_block('simulateCopy',
                          style='basic-style',
                          label=_('simulateCopy'),
                          help_string=_('simulate copy event'),
                          prim_name='copy_event')

        palette.add_block('simulatePaste',
                          style='basic-style',
                          label=_('simulatePaste'),
                          help_string=_('simulate paste event'),
                          prim_name='paste_event')

        self._parent.lc.def_prim(
            'set_x11_mouse', 2,
            Primitive(self.set_x11_mouse,
                      arg_descs=[ArgSlot(TYPE_NUMBER),
                                 ArgSlot(TYPE_NUMBER)]))
        self._parent.lc.def_prim('get_x11_mouse_x', 0,
                                 Primitive(self.get_x11_mouse_x, TYPE_INT))
        self._parent.lc.def_prim('copy_event', 0, Primitive(self.copy_event))
        self._parent.lc.def_prim('paste_event', 0, Primitive(self.paste_event))
        self._parent.lc.def_prim('get_x11_mouse_y', 0,
                                 Primitive(self.get_x11_mouse_y, TYPE_INT))

        global CONSTANTS
        CONSTANTS['left_click'] = 1
        self._parent.lc.def_prim(
            'left_click', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('left_click')]))
        CONSTANTS['right_click'] = 2
        self._parent.lc.def_prim(
            'right_click', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('right_click')]))
        CONSTANTS['TRUE'] = True
        self._parent.lc.def_prim(
            'true', 0, Primitive(CONSTANTS.get, TYPE_INT,
                                 [ConstantArg('TRUE')]))
        CONSTANTS['FALSE'] = False
        self._parent.lc.def_prim(
            'false', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('FALSE')]))
        self._parent.lc.def_prim(
            'click', 1, Primitive(self.click,
                                  arg_descs=[ArgSlot(TYPE_NUMBER)]))
        self._parent.lc.def_prim(
            'double_click', 1,
            Primitive(self.double_click, arg_descs=[ArgSlot(TYPE_NUMBER)]))
        self._parent.lc.def_prim('get_screen_width', 0,
                                 Primitive(self.get_screen_width, TYPE_INT))
        self._parent.lc.def_prim('get_screen_height', 0,
                                 Primitive(self.get_screen_height, TYPE_INT))
        self._parent.lc.def_prim(
            'press_button', 1,
            Primitive(self.press_button, arg_descs=[ArgSlot(TYPE_NUMBER)]))
        self._parent.lc.def_prim(
            'release_button', 1,
            Primitive(self.release_button, arg_descs=[ArgSlot(TYPE_NUMBER)]))
        self._parent.lc.def_prim(
            'set_line_color', 1,
            Primitive(self.set_line_color, arg_descs=[ArgSlot(TYPE_COLOR)]))
        self._parent.lc.def_prim(
            'freeze', 1, Primitive(self.setPause,
                                   arg_descs=[ArgSlot(TYPE_INT)]))
        self._parent.lc.def_prim(
            'set_line_color_rgb', 3,
            Primitive(self.set_line_color_rgb,
                      arg_descs=[
                          ArgSlot(TYPE_INT),
                          ArgSlot(TYPE_INT),
                          ArgSlot(TYPE_INT)
                      ]))

        self._parent.lc.def_prim(
            'show_line', 1,
            Primitive(self.show_line, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        self._parent.lc.def_prim(
            'set_line_width', 1,
            Primitive(self.set_line_width, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        self._parent.lc.def_prim(
            'set_line_height', 1,
            Primitive(self.set_line_height, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        self._parent.lc.def_prim(
            'set_line_width_and_heigth', 2,
            Primitive(self.set_line_width_and_heigth,
                      arg_descs=[ArgSlot(TYPE_NUMBER),
                                 ArgSlot(TYPE_NUMBER)]))

        self._parent.lc.def_prim(
            'set_line_opacity', 1,
            Primitive(self.set_line_opacity, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        global MACROS
        MACROS['setLineColorRGBmacro'] = [[
            0, 'setLineColorRGB', 0, 0, [None, 1, 2, 3, None]
        ], [1, ['number', 0], 0, 0, [0, None]],
                                          [2, ['number', 0], 0, 0, [0, None]],
                                          [3, ['number', 0], 0, 0, [0, None]]]

        MACROS['setLineWidthAndHeigthmacro'] = [[
            0, 'setLineWidthAndHeigth', 0, 0, [None, 1, 2, None]
        ], [1, ['number', 0], 0, 0,
            [0, None]], [2, ['number', 0], 0, 0, [0, None]]]
Ejemplo n.º 7
0
    def setup(self):
        """ Setup is called once, when the Turtle Window is created. """

        palette = make_palette('arduino', COLOR_NOTPRESENT,
                             _('Palette of Arduino blocks'),
                             translation=_('arduino'))

        palette.add_block('arduinorefresh',
                     style='basic-style',
                     label=_('refresh Arduino'),
                     prim_name='arduinorefresh',
                     help_string=_('Search for connected Arduinos.'))
        self.tw.lc.def_prim('arduinorefresh', 0,
            Primitive(self.refresh))
        special_block_colors['arduinorefresh'] = COLOR_PRESENT[:]

        palette.add_block('arduinoselect',
                          style='basic-style-1arg',
                          default = 1,
                          label=_('Arduino'),
                          help_string=_('set current Arduino board'),
                          prim_name = 'arduinoselect')
        self.tw.lc.def_prim('arduinoselect', 1,
            Primitive(self.select, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block('arduinocount',
                          style='box-style',
                          label=_('number of Arduinos'),
                          help_string=_('number of Arduino boards'),
                          prim_name = 'arduinocount')
        self.tw.lc.def_prim('arduinocount', 0,
            Primitive(self.count, TYPE_INT))

        palette.add_block('arduinoname',
                  style='number-style-1arg',
                  label=_('Arduino name'),
                  default=[1],
                  help_string=_('Get the name of an Arduino.'),
                  prim_name='arduinoname')
        self.tw.lc.def_prim('arduinoname', 1,
            Primitive(self.getName, TYPE_STRING, [ArgSlot(TYPE_NUMBER)]))
 
        palette.add_block('pinmode',
                  style='basic-style-2arg',
                  label=[_('pin mode'),_('pin'),_('mode')],
                  default=[1],
                  help_string=_('Select the pin function (INPUT, OUTPUT, PWM, SERVO).'),
                  prim_name='pinmode')
        self.tw.lc.def_prim('pinmode', 2,
            Primitive(self.pinMode, arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_STRING)]))

        palette.add_block('analogwrite',
                  style='basic-style-2arg',
                  label=[_('analog write'),_('pin'),_('value')],
                  default=[0, 1],
                  help_string=_('Write analog value in specified port.'),
                  prim_name='analogwrite')
        self.tw.lc.def_prim('analogwrite', 2,
            Primitive(self.analogWrite, arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER)]))

        palette.add_block('analogread',
                  style='number-style-1arg',
                  label=[_('analog read')],
                  default=[0],
                  help_string=_('Read value from analog port. Value may be between 0 and 1.'),
                  prim_name='analogread')
        self.tw.lc.def_prim('analogread', 1,
            Primitive(self.analogRead, TYPE_FLOAT, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block('digitalwrite',
                  style='basic-style-2arg',
                  label=[_('digital write'),_('pin'),_('value')],
                  default=[13, 1],
                  help_string=_('Write digital value to specified port.'),
                  prim_name='digitalwrite')
        self.tw.lc.def_prim('digitalwrite', 2,
            Primitive(self.digitalWrite, arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER)]))

        palette.add_block('digitalread',
                  style='number-style-1arg',
                  label=[_('digital read')],
                  default=[13],
                  help_string=_('Read value from digital port.'),
                  prim_name='digitalread')
        self.tw.lc.def_prim('digitalread', 1,
            Primitive(self.digitalRead, TYPE_INT, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        global CONSTANTS
        CONSTANTS['HIGH'] = 1
        palette.add_block('high',
                  style='box-style',
                  label=_('HIGH'),
                  help_string=_('Set HIGH value for digital port.'),
                  prim_name='high')
        self.tw.lc.def_prim('high', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('HIGH')]))

        CONSTANTS['INPUT'] = _('INPUT')
        palette.add_block('input',
                  style='box-style',
                  label=_('INPUT'),
                  help_string=_('Configure Arduino port for digital input.'),
                  prim_name='input')
        self.tw.lc.def_prim('input', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('INPUT')]))

        CONSTANTS['SERVO'] = _('SERVO')
        palette.add_block('servo',
                  style='box-style',
                  label=_('SERVO'),
                  help_string=_('Configure Arduino port to drive a servo.'),
                  prim_name='servo')
        self.tw.lc.def_prim('servo', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('SERVO')]))

        CONSTANTS['LOW'] = 0
        palette.add_block('low',
                  style='box-style',
                  label=_('LOW'),
                  help_string=_('Set LOW value for digital port.'),
                  prim_name='low')
        self.tw.lc.def_prim('low', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('LOW')]))

        CONSTANTS['OUTPUT'] = _('OUTPUT')
        palette.add_block('output',
                  style='box-style',
                  label=_('OUTPUT'),
                  help_string=_('Configure Arduino port for digital output.'),
                  prim_name='output')
        self.tw.lc.def_prim('output', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('OUTPUT')]))

        CONSTANTS['PWM'] = _('PWM')
        palette.add_block('pwm',
                  style='box-style',
                  label=_('PWM'),
                  help_string=_('Configure Arduino port for PWM (pulse-width modulation).'),
                  prim_name='pwm')
        self.tw.lc.def_prim('pwm', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('PWM')]))
Ejemplo n.º 8
0
    def setup(self):
        # set up X11 events specific blocks
        global CONSTANTS

        CONSTANTS['xe_left_click'] = 1
        CONSTANTS['xe_right_click'] = 3
        CONSTANTS['xe_scroll_up'] = 4
        CONSTANTS['xe_scroll_down'] = 5

        CONSTANTS['TRUE'] = True
        CONSTANTS['FALSE'] = False

        CONSTANTS['xe_buffer_size'] = 30
        CONSTANTS['xe_ctrl'] = "xe_ctrl"
        CONSTANTS['xe_shift'] = "xe_shift"
        CONSTANTS['xe_alt'] = "xe_alt"
        CONSTANTS['xe_alt_gr'] = "xe_alt_gr"
        CONSTANTS['xe_left_arrow'] = "xe_left_arrow"
        CONSTANTS['xe_right_arrow'] = "xe_right_arrow"
        CONSTANTS['xe_up_arrow'] = "xe_up_arrow"
        CONSTANTS['xe_down_arrow'] = "xe_down_arrow"
        CONSTANTS['xe_f4'] = "xe_f4"
        CONSTANTS['xe_f5'] = "xe_f5"
        CONSTANTS['xe_spacebar'] = "xe_spacebar"
        CONSTANTS['xe_tab'] = "xe_tab"
        CONSTANTS['xe_return'] = "xe_return"
        CONSTANTS['xe_escape'] = "xe_escape"
        CONSTANTS['xe_enter'] = "xe_enter"

        global MACROS
        '''MACROS['setLineColorRGBmacro'] = [[0, 'setLineColorRGB', 0, 0, [None, 1, 2, 3, None]],
                                          [1, ['number', 0], 0, 0, [0, None]],
                                          [2, ['number', 0], 0, 0, [0, None]],
                                          [3, ['number', 0], 0, 0, [0, None]]
                                         ]
        '''

        MACROS['setLineWidthAndHeightmacro'] = [[
            0, 'setLineWidthAndHeight', 0, 0, [None, 1, 2, None]
        ], [1, ['number', 0], 0, 0,
            [0, None]], [2, ['number', 0], 0, 0, [0, None]]]

        palette = make_palette('xlib-bots',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of X11 event blocks'))
        # Extra palette
        palette2 = make_palette(
            'xlib-bots-extra',
            colors=["#FF6060", "#A06060"],
            help_string=_('Palette of X11 extra event blocks'))

        palette.add_block(
            'setX11mouse',
            style='basic-style-2arg',
            label=_('setXY'),
            value_block=True,
            default=[0, 0],
            help_string=_('set the mouse pointer to x y coordinates'),
            prim_name='set_x11_mouse')

        self._parent.lc.def_prim(
            'set_x11_mouse', 2,
            Primitive(self.set_x11_mouse,
                      arg_descs=[ArgSlot(TYPE_NUMBER),
                                 ArgSlot(TYPE_NUMBER)]))

        palette.add_block('getX11mouseX',
                          style='box-style',
                          label=_('getMouseX'),
                          value_block=True,
                          help_string=_('get the mouse pointer x coordinate'),
                          prim_name='get_x11_mouse_x')

        self._parent.lc.def_prim('get_x11_mouse_x', 0,
                                 Primitive(self.get_x11_mouse_x, TYPE_INT))

        palette.add_block('getX11mouseY',
                          style='box-style',
                          label=_('getMouseY'),
                          value_block=True,
                          help_string=_('get the mouse pointer y coordinate'),
                          prim_name='get_x11_mouse_y')

        self._parent.lc.def_prim('get_x11_mouse_y', 0,
                                 Primitive(self.get_x11_mouse_y, TYPE_INT))

        palette.add_block('getScreenWidth',
                          style='box-style',
                          label=_('getScreenWidth'),
                          value_block=True,
                          help_string=_('get the screen width'),
                          prim_name='get_screen_width')

        self._parent.lc.def_prim('get_screen_width', 0,
                                 Primitive(self.get_screen_width, TYPE_INT))

        palette.add_block('getScreenHeight',
                          style='box-style',
                          label=_('getScreenHeight'),
                          value_block=True,
                          help_string=_('get the screen height'),
                          prim_name='get_screen_height')

        self._parent.lc.def_prim('get_screen_height', 0,
                                 Primitive(self.get_screen_height, TYPE_INT))

        palette.add_block('click',
                          style='basic-style-1arg',
                          label=_('click'),
                          value_block=True,
                          default=[1],
                          help_string=_('simulate a mouse click'),
                          prim_name='click')

        self._parent.lc.def_prim(
            'click', 1, Primitive(self.click,
                                  arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block('doubleClick',
                          style='basic-style-1arg',
                          label=_('double click'),
                          value_block=True,
                          default=[1],
                          help_string=_('simulate a mouse double click'),
                          prim_name='double_click')

        self._parent.lc.def_prim(
            'double_click', 1,
            Primitive(self.double_click, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block('pressButton',
                          style='basic-style-1arg',
                          label=_('pressButton'),
                          value_block=True,
                          default=[0],
                          help_string=_('keeps button pressed'),
                          prim_name='press_button')

        self._parent.lc.def_prim(
            'press_button', 1,
            Primitive(self.press_button, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block('releaseButton',
                          style='basic-style-1arg',
                          label=_('releaseButton'),
                          value_block=True,
                          default=[0],
                          help_string=_('releases button'),
                          prim_name='release_button')

        self._parent.lc.def_prim(
            'release_button', 1,
            Primitive(self.release_button, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block('leftClick',
                          style='box-style',
                          label=_('leftClick'),
                          value_block=True,
                          help_string=_('click left click'),
                          prim_name='left_click')

        self._parent.lc.def_prim(
            'left_click', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('xe_left_click')]))

        palette.add_block('rightClick',
                          style='box-style',
                          label=_('rightClick'),
                          value_block=True,
                          help_string=_('click right click'),
                          prim_name='right_click')

        self._parent.lc.def_prim(
            'right_click', 0,
            Primitive(CONSTANTS.get, TYPE_INT,
                      [ConstantArg('xe_right_click')]))

        palette.add_block('scrollUp',
                          style='box-style',
                          label=_('scrollUp'),
                          value_block=True,
                          help_string=_('simulate mouse scroll up event'),
                          prim_name='scroll_up')

        self._parent.lc.def_prim(
            'scroll_up', 0,
            Primitive(CONSTANTS.get, TYPE_INT, [ConstantArg('xe_scroll_up')]))

        palette.add_block('scrollDown',
                          style='box-style',
                          label=_('scrollDown'),
                          value_block=True,
                          help_string=_('simulate mouse scroll down event'),
                          prim_name='scroll_down')

        self._parent.lc.def_prim(
            'scroll_down', 0,
            Primitive(CONSTANTS.get, TYPE_INT,
                      [ConstantArg('xe_scroll_down')]))

        palette.add_block('freeze',
                          style='basic-style',
                          label=_('freezeBar'),
                          value_block=True,
                          help_string=_('freeze the bar'),
                          prim_name='freeze')

        self._parent.lc.def_prim('freeze', 0, Primitive(self.setPause))

        palette.add_block('unfreeze',
                          style='basic-style',
                          label=_('unfreezeBar'),
                          value_block=True,
                          help_string=_('unfreeze the bar'),
                          prim_name='unfreeze')

        self._parent.lc.def_prim('unfreeze', 0, Primitive(self.unsetPause))

        palette.add_block('showLine',
                          style='basic-style',
                          label=_('showLine'),
                          value_block=True,
                          help_string=_('show vertical line over mouse'),
                          prim_name='show_line')

        self._parent.lc.def_prim('show_line', 0, Primitive(self.show_line))

        palette.add_block('hideLine',
                          style='basic-style',
                          label=_('hideLine'),
                          value_block=True,
                          help_string=_('hide vertical line over mouse'),
                          prim_name='hide_line')

        self._parent.lc.def_prim('hide_line', 0, Primitive(self.hide_line))
        '''
        palette.add_block('setLineColorRGB',
                          hidden=True,
                          style='basic-style-3arg',
                          label=_('setLineColorRGB'),
                          value_block=True,
                          default=[0, 0, 0],
                          help_string=_('set line color from rgb value'),
                          prim_name='set_line_color_rgb')

        self._parent.lc.def_prim(
            'set_line_color_rgb', 3,
            Primitive(self.set_line_color_rgb,
                      arg_descs=[ArgSlot(TYPE_INT),
                                 ArgSlot(TYPE_INT),
                                 ArgSlot(TYPE_INT)]))


        palette.add_block('setLineColorRGBmacro',
                          style='basic-style-extended-vertical',
                          label=_('setLineColorRGB'),
                          help_string=_('set line color from rgb value'))

        '''

        palette.add_block('setLineColor',
                          style='basic-style-1arg',
                          label=_('setLineColor'),
                          value_block=True,
                          help_string=_('set line color'),
                          prim_name='set_line_color')

        self._parent.lc.def_prim(
            'set_line_color', 1,
            Primitive(self.set_line_color, arg_descs=[ArgSlot(TYPE_COLOR)]))

        palette.add_block('setLineOpacity',
                          style='basic-style-1arg',
                          label=_('setLineOpacity'),
                          value_block=True,
                          default=[1],
                          help_string=_('set line opacity'),
                          prim_name='set_line_opacity')

        self._parent.lc.def_prim(
            'set_line_opacity', 1,
            Primitive(self.set_line_opacity, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block(
            'setLineWidthAndHeight',
            hidden=True,
            style='basic-style-2arg',
            label=_('setLineWidthAndHeight'),
            value_block=True,
            default=[0, 0],
            help_string=_('set width and height of line over mouse'),
            prim_name='set_line_width_and_height')

        self._parent.lc.def_prim(
            'set_line_width_and_height', 2,
            Primitive(self.set_line_width_and_height,
                      arg_descs=[ArgSlot(TYPE_NUMBER),
                                 ArgSlot(TYPE_NUMBER)]))

        palette.add_block(
            'setLineWidthAndHeightmacro',
            style='basic-style-extended-vertical',
            label=_('setLineWidthAndHeight'),
            help_string=_('set width and height of line over mouse'))

        palette2.add_block('simulateKey',
                           style='basic-style-1arg',
                           label=_('simulateKey'),
                           help_string=_('simulates pressing a key'),
                           prim_name='simulate_key')

        self._parent.lc.def_prim(
            'simulate_key', 1,
            Primitive(self.simulate_key, arg_descs=[ArgSlot(TYPE_STRING)]))

        palette2.add_block('spaceBar',
                           style='box-style',
                           label=_('spaceBar'),
                           value_block=True,
                           help_string=_('space bar'),
                           prim_name='spacebar')

        self._parent.lc.def_prim(
            'spacebar', 0,
            Primitive(CONSTANTS.get, TYPE_STRING,
                      [ConstantArg('xe_spacebar')]))

        palette2.add_block('leftArrow',
                           style='box-style',
                           label=_('leftArrow'),
                           value_block=True,
                           help_string=_('left arrow'),
                           prim_name='left_arrow')

        self._parent.lc.def_prim(
            'left_arrow', 0,
            Primitive(CONSTANTS.get, TYPE_STRING,
                      [ConstantArg('xe_left_arrow')]))

        palette2.add_block('rightArrow',
                           style='box-style',
                           label=_('rightArrow'),
                           value_block=True,
                           help_string=_('right arrow'),
                           prim_name='right_arrow')

        self._parent.lc.def_prim(
            'right_arrow', 0,
            Primitive(CONSTANTS.get, TYPE_STRING,
                      [ConstantArg('xe_right_arrow')]))

        palette2.add_block('upArrow',
                           style='box-style',
                           label=_('upArrow'),
                           value_block=True,
                           help_string=_('up arrow'),
                           prim_name='up_arrow')

        self._parent.lc.def_prim(
            'up_arrow', 0,
            Primitive(CONSTANTS.get, TYPE_STRING,
                      [ConstantArg('xe_up_arrow')]))

        palette2.add_block('downArrow',
                           style='box-style',
                           label=_('downArrow'),
                           value_block=True,
                           help_string=_('down arrow'),
                           prim_name='down_arrow')

        self._parent.lc.def_prim(
            'down_arrow', 0,
            Primitive(CONSTANTS.get, TYPE_STRING,
                      [ConstantArg('xe_down_arrow')]))

        palette2.add_block('CtrlKey',
                           style='box-style',
                           label=_('ctrlKey'),
                           value_block=True,
                           help_string=_('ctrl key'),
                           prim_name='ctrl_key')

        self._parent.lc.def_prim(
            'ctrl_key', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('xe_ctrl')]))

        palette2.add_block('ShiftKey',
                           style='box-style',
                           label=_('shiftKey'),
                           value_block=True,
                           help_string=_('shift key'),
                           prim_name='shift_key')

        self._parent.lc.def_prim(
            'shift_key', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('xe_shift')]))

        palette2.add_block('AltKey',
                           style='box-style',
                           label=_('altKey'),
                           value_block=True,
                           help_string=_('alt key'),
                           prim_name='alt_key')

        self._parent.lc.def_prim(
            'alt_key', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('xe_alt')]))
        '''
        palette2.add_block('AltGrKey',
                          style='box-style',
                          label=_('altGrKey'),
                          value_block=True,
                          help_string=_('alt gr key'),
                          prim_name='altgr_key')

        
        self._parent.lc.def_prim(
            'altgr_key', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('xe_alt_gr')]))
        '''

        palette2.add_block('tabKey',
                           style='box-style',
                           label=_('tabKey'),
                           value_block=True,
                           help_string=_('tab key'),
                           prim_name='tab_key')

        self._parent.lc.def_prim(
            'tab_key', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('xe_tab')]))

        palette2.add_block('returnKey',
                           style='box-style',
                           label=_('returnKey'),
                           value_block=True,
                           help_string=_('return key'),
                           prim_name='return_key')

        self._parent.lc.def_prim(
            'return_key', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('xe_return')]))

        palette2.add_block('escapeKey',
                           style='box-style',
                           label=_('escapeKey'),
                           value_block=True,
                           help_string=_('escape key'),
                           prim_name='escape_key')

        self._parent.lc.def_prim(
            'escape_key', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('xe_escape')]))

        palette2.add_block('enterKey',
                           style='box-style',
                           label=_('enterKey'),
                           value_block=True,
                           help_string=_('enter key'),
                           prim_name='enter_key')

        self._parent.lc.def_prim(
            'enter_key', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('xe_enter')]))

        palette2.add_block('f4Key',
                           style='box-style',
                           label=_('f4Key'),
                           value_block=True,
                           help_string=_('f4 key'),
                           prim_name='f4_key')

        self._parent.lc.def_prim(
            'f4_key', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('xe_f4')]))

        palette2.add_block('f5Key',
                           style='box-style',
                           label=_('f5Key'),
                           value_block=True,
                           help_string=_('f5 key'),
                           prim_name='f5_key')

        self._parent.lc.def_prim(
            'f5_key', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('xe_f5')]))

        palette2.add_block('combineKeys',
                           style='number-style-block',
                           label=[_('combine'),
                                  _('key1'),
                                  _('key2')],
                           help_string=_('Combines two keys. e.g : ctrl + c'),
                           prim_name='combine_keys')

        self._parent.lc.def_prim(
            'combine_keys', 2,
            Primitive(self.combine_keys,
                      TYPE_STRING,
                      arg_descs=[ArgSlot(TYPE_STRING),
                                 ArgSlot(TYPE_STRING)]))

        palette2.add_block(
            'debounce',
            style='number-style-block',
            label=[_('debounce'), _('name'),
                   _('button')],
            default=["name"],
            help_string=_('Debouncing - The name must be unique'),
            prim_name='debounce')

        self._parent.lc.def_prim(
            'debounce', 2,
            Primitive(self.debounce,
                      arg_descs=[ArgSlot(TYPE_STRING),
                                 ArgSlot(TYPE_NUMBER)]))

        palette2.add_block('openBrowser',
                           style='basic-style-1arg',
                           label=_('openBrowser'),
                           default=[_("http://www.example.com")],
                           help_string=_('Simulates opening a web browser'),
                           prim_name='browser')

        self._parent.lc.def_prim(
            'browser', 1,
            Primitive(self.browser, arg_descs=[ArgSlot(TYPE_STRING)]))

        palette2.add_block('openProgram',
                           style='basic-style-1arg',
                           label=_("openProgram"),
                           default=[_("name")],
                           help_string=_('Opens a program'),
                           prim_name='open_program')

        self._parent.lc.def_prim(
            'open_program', 1,
            Primitive(self.open_program, arg_descs=[ArgSlot(TYPE_STRING)]))

        palette2.add_block('closeProgram',
                           style='basic-style-1arg',
                           label=_("closeProgram"),
                           default=[_("name")],
                           help_string=_('close a program'),
                           prim_name='close_program')

        self._parent.lc.def_prim(
            'close_program', 1,
            Primitive(self.close_program, arg_descs=[ArgSlot(TYPE_STRING)]))

        palette2.add_block(
            'saveValue',
            style='basic-style-2arg',
            label=[_('saveValue'), _('key'),
                   _('value')],
            default=["key"],
            help_string=_('save value - The key must be unique'),
            prim_name='save_value')

        self._parent.lc.def_prim(
            'save_value', 2,
            Primitive(self.save_value,
                      arg_descs=[ArgSlot(TYPE_STRING),
                                 ArgSlot(TYPE_NUMBER)]))

        palette2.add_block(
            'getValue',
            style='number-style-1arg',
            label=_("getValue"),
            default=[_("key")],
            help_string=_('get a value saved with save value block'),
            prim_name='get_value')

        self._parent.lc.def_prim(
            'get_value', 1,
            Primitive(self.get_value, arg_descs=[ArgSlot(TYPE_STRING)]))

        palette2.add_block(
            'defaultValue',
            style='basic-style-2arg',
            label=[_('defaultValue'), _('key'),
                   _('value')],
            default=["key"],
            help_string=_('default value - The key must be unique'),
            prim_name='default_value')

        self._parent.lc.def_prim(
            'default_value',
            2,
            #save a color
            or_(
                Primitive(
                    self.default_value,
                    arg_descs=[ArgSlot(TYPE_STRING),
                               ArgSlot(TYPE_COLOR)]),
                # ... or save a number
                Primitive(
                    self.default_value,
                    arg_descs=[ArgSlot(TYPE_STRING),
                               ArgSlot(TYPE_NUMBER)]),
                # ... or save a string
                Primitive(
                    self.default_value,
                    arg_descs=[ArgSlot(TYPE_STRING),
                               ArgSlot(TYPE_STRING)])))

        palette2.add_block('setProgramName',
                           style='basic-style-1arg',
                           label=_("setProgramName"),
                           default=[_("my program")],
                           help_string=_('name this program'),
                           prim_name='set_program_name')

        self._parent.lc.def_prim(
            'set_program_name', 1,
            Primitive(self.set_program_name, arg_descs=[ArgSlot(TYPE_STRING)]))
Ejemplo n.º 9
0
    def setup(self):

        palette = make_palette('followme',
                               COLOR_NOTPRESENT,
                               _('FollowMe'),
                               translation=_('followme'))

        palette.add_block('followmerefresh',
                          style='basic-style',
                          label=_('refresh FollowMe'),
                          prim_name='followmerefresh',
                          help_string=_('Search for a connected camera.'))
        self.tw.lc.def_prim('followmerefresh', 0, Primitive(self.refresh))
        special_block_colors['followmerefresh'] = COLOR_PRESENT[:]

        palette.add_block('savecalibration',
                          style='basic-style-1arg',
                          label=_('calibration'),
                          prim_name='savecalibration',
                          string_or_number=True,
                          default='1',
                          help_string=_('store a personalized calibration'))
        self.tw.lc.def_prim(
            'savecalibration', 1,
            Primitive(self.savecalibration,
                      arg_descs=or_([ArgSlot(TYPE_NUMBER)],
                                    [ArgSlot(TYPE_STRING)])))

        palette.add_block('calibration',
                          style='number-style-1strarg',
                          label=_('calibration'),
                          prim_name='calibration',
                          string_or_number=True,
                          default='1',
                          help_string=_('return a personalized calibration'))
        self.tw.lc.def_prim(
            'calibration', 1,
            Primitive(self.calibration, TYPE_STRING,
                      or_([ArgSlot(TYPE_NUMBER)], [ArgSlot(TYPE_STRING)])))

        palette.add_block('follow',
                          style='basic-style-1arg',
                          label=_('follow'),
                          help_string=_('follow a color or calibration'),
                          prim_name='follow')
        self.tw.lc.def_prim(
            'follow', 1,
            Primitive(self.follow,
                      arg_descs=or_([ArgSlot(TYPE_NUMBER)],
                                    [ArgSlot(TYPE_STRING)])))

        palette.add_block(
            'brightness_f',
            style='basic-style-1arg',
            label=_('brightness'),
            default=128,
            help_string=_(
                'set the camera brightness as a value between 0 to 255.'),
            prim_name='brightness_f')
        self.tw.lc.def_prim(
            'brightness_f', 1,
            Primitive(self.brightness, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block('thresholdFollowMe',
                          style='basic-style-3arg',
                          hidden=True,
                          label=[(_('threshold') + '  ' + 'G'), 'R', 'B'],
                          default=[25, 25, 25],
                          help_string=_('set a threshold for a RGB color'),
                          prim_name='threshold')
        self.tw.lc.def_prim(
            'threshold', 3,
            Primitive(self.set_threshold,
                      arg_descs=[
                          ArgSlot(TYPE_NUMBER),
                          ArgSlot(TYPE_NUMBER),
                          ArgSlot(TYPE_NUMBER)
                      ]))

        palette.add_block('thresholdMacro',
                          style='basic-style-extended-vertical',
                          label=_('threshold'),
                          help_string=_('set a threshold for a RGB color'))

        global MACROS
        MACROS['thresholdMacro'] = [[
            0, 'thresholdFollowMe', 0, 0, [None, 1, 2, 3, None]
        ], [1, ['number', 25], 0, 0, [0, None]],
                                    [2, ['number', 25], 0, 0, [0, None]],
                                    [3, ['number', 25], 0, 0, [0, None]]]

        palette.add_block(
            'camera_mode',
            style='basic-style-1arg',
            label=_('camera mode'),
            default='RGB',
            help_string=_('set the color mode of the camera: RGB; YUV or HSV'),
            prim_name='camera_mode')
        self.tw.lc.def_prim(
            'camera_mode', 1,
            Primitive(self.camera_mode, arg_descs=[ArgSlot(TYPE_STRING)]))

        palette.add_block(
            'brightness_w',
            style='box-style',
            label=_('get brightness'),
            help_string=_('get the brightness of the ambient light'),
            prim_name='brightness_w')
        self.tw.lc.def_prim('brightness_w', 0,
                            Primitive(self.luminance, TYPE_INT))

        palette.add_block(
            'average_color',
            style='basic-style-1arg',
            label=_('average color'),
            default=1,
            help_string=
            _('if set to 0 then color averaging is off during calibration; for other values it is on'
              ),
            prim_name='average_color')
        self.tw.lc.def_prim(
            'average_color', 1,
            Primitive(self.average_color, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block('xposition',
                          style='box-style',
                          label=_('x position'),
                          help_string=_('return x position'),
                          value_block=True,
                          prim_name='xposition')
        self.tw.lc.def_prim('xposition', 0, Primitive(self.xpos, TYPE_INT))

        palette.add_block('yposition',
                          style='box-style',
                          label=_('y position'),
                          help_string=_('return y position'),
                          value_block=True,
                          prim_name='yposition')
        self.tw.lc.def_prim('yposition', 0, Primitive(self.ypos, TYPE_INT))

        palette.add_block(
            'pixels',
            style='box-style',
            label=_('pixels'),
            help_string=_('return the number of pixels of the biggest blob'),
            value_block=True,
            prim_name='pixels')
        self.tw.lc.def_prim('pixels', 0, Primitive(self.getPixels, TYPE_INT))

        global CONSTANTS
        CONSTANTS['RGB'] = _('RGB')
        palette.add_block(
            'mode_rgb',
            style='box-style',
            label=_('RGB'),
            help_string=_('set the color mode of the camera to RGB'),
            value_block=True,
            prim_name='mode_rgb')
        self.tw.lc.def_prim(
            'mode_rgb', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('RGB')]))

        CONSTANTS['YUV'] = _('YUV')
        palette.add_block(
            'mode_yuv',
            style='box-style',
            label=_('YUV'),
            help_string=_('set the color mode of the camera to YUV'),
            value_block=True,
            prim_name='mode_yuv')
        self.tw.lc.def_prim(
            'mode_yuv', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('YUV')]))

        CONSTANTS['HSV'] = _('HSV')
        palette.add_block(
            'mode_hsv',
            style='box-style',
            label=_('HSV'),
            help_string=_('set the color mode of the camera to HSV'),
            value_block=True,
            prim_name='mode_hsv')
        self.tw.lc.def_prim(
            'mode_hsv', 0,
            Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg('HSV')]))

        palette.add_block('get_color',
                          style='box-style',
                          label=_('get color'),
                          help_string=_('get the color of an object'),
                          value_block=True,
                          prim_name='get_color')
        self.tw.lc.def_prim('get_color', 0,
                            Primitive(self.get_color, TYPE_STRING))

        palette.add_block(
            'color_dist',
            style='basic-style-1arg',
            label=_('color distance'),
            default=9000,
            help_string=_('set the distance to identify a color'),
            prim_name='color_dist')
        self.tw.lc.def_prim(
            'color_dist', 1,
            Primitive(self.get_color_dist, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block(
            'pixels_min',
            style='basic-style-1arg',
            label=_('minimum pixels'),
            default=10,
            help_string=_('set the minimal number of pixels to follow'),
            prim_name='pixels_min')
        self.tw.lc.def_prim(
            'pixels_min', 1,
            Primitive(self.pixels_min, arg_descs=[ArgSlot(TYPE_NUMBER)]))
Ejemplo n.º 10
0
    def setup(self):
        palette = make_palette('atyarandu',
                               colors=COLOR_PRESENT,
                               help_string=_('Palette of Renewable Energy'))

        palette.add_block('engrefreshagh',
                style='basic-style',
                label=_('refresh Energy'),
                value_block=True,
                help_string=\
                    _('updates the status of the palette and the Energy blocks'),
                prim_name='engrefreshagh')
        self._parent.lc.def_prim(
            'engrefreshagh', 0,
            Primitive(self.prim_refresh, return_type=TYPE_STRING))

        palette.add_block('enggenagh',
                style='box-style',
                label=_('energy generated'),
                value_block=True,
                help_string=\
                    _('Estimated value of renewable energy (MW) to generate in the next hour in Uruguay'),
                prim_name='enggenagh')
        self._parent.lc.def_prim(
            'enggenagh', 0, Primitive(self.prim_enggen,
                                      return_type=TYPE_FLOAT))

        palette.add_block('engmaxagh',
                style='box-style',
                label=_('max energy'),
                value_block=True,
                help_string=\
                    _('Nominal value of renewable energy (MW) that can be generated in Uruguay'),
                prim_name='engmaxagh')
        self._parent.lc.def_prim(
            'engmaxagh', 0, Primitive(self.prim_engmax,
                                      return_type=TYPE_FLOAT))

        palette.add_block('engrecagh',
                style='box-style',
                label=_('recommended energy'),
                value_block=True,
                help_string=\
                    _('The preferred value of renewable energy (MW) for use'),
                prim_name='engrecagh')
        self._parent.lc.def_prim(
            'engrecagh', 0, Primitive(self.prim_engrec,
                                      return_type=TYPE_FLOAT))

        palette.add_block('engoncagh',
                          style='box-style',
                          label=_('ON'),
                          value_block='On',
                          help_string=_('Power on'),
                          colors=COLOR_PRESENT,
                          prim_name='engonagh')
        self._parent.lc.def_prim(
            'engonagh', 0, Primitive(self.prim_on, return_type=TYPE_NUMBER))

        palette.add_block('engoffcagh',
                          style='box-style',
                          label=_('OFF'),
                          value_block='Off',
                          colors=COLOR_RED,
                          help_string=_('Power off'),
                          prim_name='engoffagh')
        self._parent.lc.def_prim(
            'engoffagh', 0, Primitive(self.prim_off, return_type=TYPE_NUMBER))
        global RELAY_PORT
        for m in range(MAX_SENSOR_PER_TYPE):
            if m == 0:
                ocultar = False
            else:
                ocultar = True
                n = m
            x = str(m + 1)
            nombloque = 'relay' + x + 'agh'
            RELAY_PORT[nombloque] = 0
            palette.add_block(nombloque,
                              style='basic-style-1arg',
                              label=_('relay'),
                              prim_name=nombloque,
                              default=1,
                              hidden=ocultar,
                              colors=COLOR_PRESENT,
                              help_string=_('power on/off the relay'))
            self._parent.lc.def_prim(
                nombloque, 1,
                Primitive(
                    self.prim_control,
                    arg_descs=[ArgSlot(TYPE_NUMBER),
                               ConstantArg(nombloque)]))
            special_block_colors[nombloque] = COLOR_NOTPRESENT