def setup(self):
        # set up RFID-specific blocks
        palette = make_palette('sensor',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)

        if self._status:
            palette.add_block('rfid',
                              style='box-style',
                              label=_('RFID'),
                              help_string=_('read value from RFID device'),
                              value_block=True,
                              prim_name='rfid')
        else:
            palette.add_block('rfid',
                              hidden=True,
                              style='box-style',
                              label=_('RFID'),
                              help_string=_('read value from RFID device'),
                              value_block=True,
                              prim_name='rfid')

        self._parent.lc.def_prim(
            'rfid', 0,
            Primitive(self.prim_read_rfid,
                      return_type=TYPE_STRING,
                      call_afterwards=self.after_rfid))
    def setup(self):
        # set up accelerometer specific blocks
        palette = make_palette('sensor',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)

        primitive_dictionary['xyz'] = self.prim_xyz
        if self._status:
            palette.add_block('xyz',
                              style='basic-style-extended-vertical',
                              label=_('acceleration'),
                              help_string=\
                                  _('push acceleration in x, y, z to heap'),
                              prim_name='xyz')
        else:
            palette.add_block('xyz',
                              style='basic-style-extended-vertical',
                              label=_('acceleration'),
                              help_string=\
                                  _('push acceleration in x, y, z to heap'),
                              hidden=True,
                              prim_name='xyz')

        self._parent.lc.def_prim('xyz', 0,
                                 lambda self: primitive_dictionary['xyz']())
Exemple #3
0
    def setup(self):
        # set up RFID-specific blocks
        primitive_dictionary['rfid'] = self.prim_read_rfid
        palette = make_palette('sensor',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)

        if self._status:
            palette.add_block('rfid',
                              style='box-style',
                              label=_('RFID'),
                              help_string=_('read value from RFID device'),
                              value_block=True,
                              prim_name='rfid')
        else:
            palette.add_block('rfid',
                              hidden=True,
                              style='box-style',
                              label=_('RFID'),
                              help_string=_('read value from RFID device'),
                              value_block=True,
                              prim_name='rfid')

        self._parent.lc.def_prim('rfid', 0,
                                 lambda self: primitive_dictionary['rfid']())
    def setup(self):
        # set up light-sensor specific blocks
        palette = make_palette('sensor',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)

        primitive_dictionary['lightsensor'] = self.prim_lightsensor
        if self._status:
            palette.add_block('lightsensor',
                              style='box-style',
                              label=_('brightness'),
                              help_string=\
                                  _('light level detected by light sensor'),
                              prim_name='lightsensor')
        else:
            palette.add_block('lightsensor',
                              style='box-style',
                              label=_('brightness'),
                              help_string=\
                                  _('light level detected by light sensor'),
                              hidden=True,
                              prim_name='lightsensor')

        self._parent.lc.def_prim(
            'lightsensor', 0,
            lambda self: primitive_dictionary['lightsensor']())
    def setup(self):
        # set up light-sensor specific blocks
        palette = make_palette('sensor',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)

        primitive_dictionary['lightsensor'] = self.prim_lightsensor
        if self._status:
            palette.add_block('lightsensor',
                              style='box-style',
                              label=_('brightness'),
                              help_string=\
                                  _('light level detected by light sensor'),
                              prim_name='lightsensor')
        else:
            palette.add_block('lightsensor',
                              style='box-style',
                              label=_('brightness'),
                              help_string=\
                                  _('light level detected by light sensor'),
                              hidden=True,
                              prim_name='lightsensor')

        self._parent.lc.def_prim(
            'lightsensor', 0, lambda self: primitive_dictionary['lightsensor']
            ())
    def setup(self):
        # set up RFID-specific blocks
        primitive_dictionary['rfid'] = self.prim_read_rfid
        palette = make_palette('sensor',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)

        if self._status:
            palette.add_block('rfid',
                              style='box-style',
                              label=_('RFID'),
                              help_string=_('read value from RFID device'),
                              value_block=True,
                              prim_name='rfid')
        else:
            palette.add_block('rfid',
                              hidden=True,
                              style='box-style',
                              label=_('RFID'),
                              help_string=_('read value from RFID device'),
                              value_block=True,
                              prim_name='rfid')

        self._parent.lc.def_prim(
            'rfid', 0, lambda self: primitive_dictionary['rfid']())
Exemple #7
0
def myblock(tw, arg):
    ''' Add a uturn block to the 'turtle' palette '''

    from TurtleArt.tapalette import make_palette, palette_name_to_index
    from TurtleArt.talogo import primitive_dictionary
    from gettext import gettext as _

    # Choose a palette for the new block.
    palette = make_palette('turtle')

    # Create a new block prototype.
    palette.add_block('uturn',
                      style='basic-style-extended-vertical',
                      label=_('uturn'),
                      prim_name='uturn',
                      help_string=_('make a uturn'))

    # Add its primitive to the LogoCode dictionary.
    tw.lc.def_prim('uturn', 0,
                   lambda self: primitive_dictionary['set']
                   ('heading', tw.canvas.seth, tw.canvas.heading + 180))

    # Regenerate the palette, which will now include the new block.
    tw.show_toolbar_palette(palette_name_to_index('turtle'),
                            regenerate=True)
def myblock(tw, arg):
    ''' Add a uturn block to the 'turtle' palette '''

    # def_prim takes 3 arguments: the primitive name, the number of
    # arguments -- 0 in this case -- and the function to call -- in this
    # case, we define the _prim_uturn function to set heading += 180.
    def _prim_uturn(tw):
        value = tw.turtles.get_active_turtle().get_heading() + 180
        tw.turtles.get_active_turtle().set_heading(value)
        # We also update the label on the heading block to indicate
        # the current heading value
        if tw.lc.update_values:
            tw.lc.update_label_value('heading', value)

    from TurtleArt.tapalette import make_palette, palette_name_to_index
    from TurtleArt.talogo import primitive_dictionary
    from gettext import gettext as _

    # Choose a palette for the new block.
    palette = make_palette('turtle')

    # Create a new block prototype.
    palette.add_block('uturn',
                      style='basic-style-extended-vertical',
                      label=_('uturn'),
                      prim_name='uturn',
                      help_string=_('turns the turtle 180 degrees'))

    # Add its primitive to the LogoCode dictionary.
    tw.lc.def_prim('uturn', 0, lambda self: _prim_uturn(tw))

    # Regenerate the palette, which will now include the new block.
    tw.show_toolbar_palette(palette_name_to_index('turtle'), regenerate=True)
    def setup(self):
        # set up accelerometer specific blocks
        palette = make_palette('sensor',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)

        if self._status:
            palette.add_block('xyz',
                              style='basic-style-extended-vertical',
                              label=_('acceleration'),
                              help_string=\
                                  _('push acceleration in x, y, z to heap'),
                              prim_name='xyz')
        else:
            palette.add_block('xyz',
                              style='basic-style-extended-vertical',
                              label=_('acceleration'),
                              help_string=\
                                  _('push acceleration in x, y, z to heap'),
                              hidden=True,
                              prim_name='xyz')

        self._parent.lc.def_prim(
            'xyz', 0,
            Primitive(self.prim_xyz))
Exemple #10
0
    def setup(self):
        # set up accelerometer specific blocks
        palette = make_palette('extras',
                               colors=["#FF0000", "#A00000"],
                               help_string=_('Palette of extra options'),
                               position=8,
                               translation=_('extras'))
        '''
        palette = make_palette('sensor',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)
        '''

        if self._status:
            palette.add_block('xyz',
                              hidden=True,
                              style='basic-style-extended-vertical',
                              label=_('acceleration'),
                              help_string=\
                                  _('push acceleration in x, y, z to heap'),
                              prim_name='xyz')
        else:
            palette.add_block('xyz',
                              hidden=True,
                              style='basic-style-extended-vertical',
                              label=_('acceleration'),
                              help_string=\
                                  _('push acceleration in x, y, z to heap'),
                              prim_name='xyz')

        self._parent.lc.def_prim('xyz', 0, Primitive(self.prim_xyz))
def myblock(tw, arg):
    ''' Add a uturn block to the 'turtle' palette '''

    # def_prim takes 3 arguments: the primitive name, the number of
    # arguments -- 0 in this case -- and the function to call -- in this
    # case, we define the _prim_uturn function to set heading += 180.
    def _prim_uturn(tw):
        value = tw.turtles.get_active_turtle().get_heading() + 180
        tw.turtles.get_active_turtle().set_heading(value)
        # We also update the label on the heading block to indicate
        # the current heading value
        if tw.lc.update_values:
            tw.lc.update_label_value('heading', value)

    from TurtleArt.tapalette import make_palette, palette_name_to_index
    from TurtleArt.talogo import primitive_dictionary
    from gettext import gettext as _

    # Choose a palette for the new block.
    palette = make_palette('turtle')

    # Create a new block prototype.
    palette.add_block('uturn',
                      style='basic-style-extended-vertical',
                      label=_('uturn'),
                      prim_name='uturn',
                      help_string=_('turns the turtle 180 degrees'))

    # Add its primitive to the LogoCode dictionary.
    tw.lc.def_prim('uturn', 0, lambda self: _prim_uturn(tw))

    # Regenerate the palette, which will now include the new block.
    tw.show_toolbar_palette(palette_name_to_index('turtle'),
                            regenerate=True)
Exemple #12
0
    def setup(self):
        # set up RFID-specific blocks
        palette = make_palette('sensor',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)

        if self._status:
            palette.add_block('rfid',
                              style='box-style',
                              label=_('RFID'),
                              help_string=_('read value from RFID device'),
                              value_block=True,
                              prim_name='rfid')
        else:
            palette.add_block('rfid',
                              hidden=True,
                              style='box-style',
                              label=_('RFID'),
                              help_string=_('read value from RFID device'),
                              value_block=True,
                              prim_name='rfid')

        self._parent.lc.def_prim(
            'rfid', 0,
            Primitive(self.prim_read_rfid,
                      return_type=TYPE_STRING,
                      call_afterwards=self.after_rfid))
Exemple #13
0
    def setup(self):
        # set up light-sensor specific blocks
        palette = make_palette('sensor',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)

        if self._status:
            palette.add_block('lightsensor',
                              style='box-style',
                              label=_('brightness'),
                              value_block=True,
                              help_string=\
                                  _('light level detected by light sensor'),
                              prim_name='lightsensor')
        else:
            palette.add_block('lightsensor',
                              style='box-style',
                              label=_('brightness'),
                              value_block=True,
                              help_string=\
                                  _('light level detected by light sensor'),
                              hidden=True,
                              prim_name='lightsensor')

        self._parent.lc.def_prim(
            'lightsensor', 0,
            Primitive(self.prim_lightsensor,
                      return_type=TYPE_NUMBER,
                      call_afterwards=self.after_light))
Exemple #14
0
    def setup(self):
        # set up light-sensor specific blocks
        palette = make_palette('sensor',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of sensor blocks'),
                               position=6)

        if self._status:
            palette.add_block('lightsensor',
                              style='box-style',
                              label=_('brightness'),
                              value_block=True,
                              help_string=\
                                  _('light level detected by light sensor'),
                              prim_name='lightsensor')
        else:
            palette.add_block('lightsensor',
                              style='box-style',
                              label=_('brightness'),
                              value_block=True,
                              help_string=\
                                  _('light level detected by light sensor'),
                              hidden=True,
                              prim_name='lightsensor')

        self._parent.lc.def_prim(
            'lightsensor', 0,
            Primitive(self.prim_lightsensor,
                      return_type=TYPE_NUMBER,
                      call_afterwards=self.after_light))
Exemple #15
0
    def setup(self):

        palette = make_palette('pattern_detection', ["#00FF00","#008000"], _('Pattern detection'),
                                translation=_('pattern_detection'))

        palette.add_block('isPresent',
                    style='boolean-1arg-block-style',
                    label=_('Seeing signal'),
                    prim_name='isPresent',
                    help_string= _('Returns True if the signal is in front of the camera'))
        self.tw.lc.def_prim('isPresent', 1,
            Primitive(self.isPresent, TYPE_BOOL, arg_descs=[ArgSlot(TYPE_STRING)]))

        palette.add_block('getDist',
                    style='number-style-1arg',
                    label=_('Distance to signal'),
                    prim_name='getDist',
                    help_string= _('Returns the distance of the siganl to the camera in milimeters'))
        self.tw.lc.def_prim('getDist', 1,
            Primitive(self.getDist, TYPE_INT, [ArgSlot(TYPE_STRING)]))

        #TODO: Faltaria ver si levanta el objet_data segun el idioma
        #obtener identificadores del api y cargar botones con imagenes.
        out = self.detection.arMultiGetIdsMarker()

        for section_name in out.split(";"):
            self._add_signal_botton(palette, section_name, section_name)
Exemple #16
0
    def setup(self):

        # Palette of Motors
        palette = make_palette('fischer', COLOR_NOTPRESENT,
                            _('Palette of Fischertechnik robot'),
                            translation=_('fischer'))

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

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

        palette.add_block('ftcount',
                    style='box-style',
                    label=_('number of Fischers'),
                    help_string=_('number of Fischer devices'),
                    prim_name = 'ftcount')
        self.tw.lc.def_prim('ftcount', 0,
            Primitive(self.count, TYPE_INT))

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

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

        palette.add_block('ftturnactuator',
                    style='basic-style-2arg',
                    label=[_('turn actuator'), _('port'), _('power')],
                    default=[1, 100],
                    help_string=_('turn an actuator'),
                    prim_name='ftturnactuator')
        self.tw.lc.def_prim('ftturnactuator', 2,
            Primitive(self.turnactuator, arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER)]))
Exemple #17
0
    def setup(self):

        # Palette of Motors
        palette = make_palette('fischer', COLOR_NOTPRESENT,
                            _('Palette of Fischertechnik robot'),
                            translation=_('fischer'))

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

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

        palette.add_block('ftcount',
                    style='box-style',
                    label=_('number of Fischers'),
                    help_string=_('number of Fischer devices'),
                    prim_name = 'ftcount')
        self.tw.lc.def_prim('ftcount', 0,
            Primitive(self.count, TYPE_INT))

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

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

        palette.add_block('ftturnactuator',
                    style='basic-style-2arg',
                    label=[_('actuator'), _('port'), _('power')],
                    default=[1, 100],
                    help_string=_('turn an actuator'),
                    prim_name='ftturnactuator')
        self.tw.lc.def_prim('ftturnactuator', 2,
            Primitive(self.turnactuator, arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER)]))
Exemple #18
0
    def setup(self):
        # set up mashape specific blocks
        palette = make_palette('mashape',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Mashape plugins'))

        palette.add_block(
            'setlang',
            style='basic-style-2arg',
            label=[
                _('set lang'),
                _('from'),
                _('to')],
            prim_name='setlang',
            default=[
                'en',
                'es'],
            help_string=_('set translation settings for translate block'),
        )

        palette.add_block(
            'translate',
            style='number-style-1arg',
            label=_('translate'),
            prim_name='translate',
            default=_('hello world'),
            help_string=_('translate strings'),
        )

        palette.add_block(
            'detectlang',
            style='number-style-1arg',
            label=_('detect lang'),
            prim_name='detectlang',
            default=_('hello world'),
            help_string=_('detect lang of string'),
        )

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

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

        self._parent.lc.def_prim(
            'detectlang',
            1,
            Primitive(self.prim_detectlang, return_type=TYPE_STRING,
                      arg_descs=[ArgSlot(TYPE_STRING)]))
   def setup(self): 
      SKIN_PATHS.append('plugins/'+plugin_folder+'/images')
      palette = make_palette(plugin_name,
                     colors=["#00FF00","#008000"],
                     help_string=_('Deteccion de marcas'))      

      
      primitive_dictionary['isPresent'] = self._isPresent
      palette.add_block('isPresent',
                          style='number-style-1arg',
                          label=_('Viendo Señal'),
                          prim_name='isPresent',
                          help_string= _('Devuelve True si la señal esta en el campo visual de la camara'))
      self._parent.lc.def_prim('isPresent', 1,
                             lambda self, x: primitive_dictionary['isPresent'](x))
      
      primitive_dictionary['stopCam'] = self._stop_cam
      palette.add_block('stopCam',
                          style='basic-style',
                          label=_('Parar Camara'),
                          prim_name='stopCam',
                          help_string= _('Apaga la camara'))
      self._parent.lc.def_prim('stopCam', 0, lambda self :
            primitive_dictionary['stopCam']())
  
      
      primitive_dictionary['getMarkerTrigDist'] = self._getMarkerTrigDist
      palette.add_block('getMarkerTrigDist',
                          style='number-style-1arg',
                          label=_('Distancia Señal'),
                          prim_name='getMarkerTrigDist',
                          help_string= _('Devuelve la distancia a la camara en mm'))
      self._parent.lc.def_prim('getMarkerTrigDist', 1,
                             lambda self, x: primitive_dictionary['getMarkerTrigDist'](x))
	  
      #Se agregan los IDs de botones para luego chequear que esten para activar la camara
      self.block_list.append('isPresent')
      self.block_list.append('stopCam')
      self.block_list.append('getMarkerTrigDist')     
      #TODO: Faltaria ver si levnta el objet_data segun el idioma   
      #obtener identificadores del api y cargar botones con imagenes.	
      out = self.detection.arMultiGetIdsMarker()
      
      for section_name in out.split(";"):
        print 'Signal found:', section_name
        self._add_signal_botton(palette,section_name,section_name)
        self.block_list.append(section_name)
      print '  fin setup'
    def setup(self):
        palette = make_palette('listens',
                               colors=["#FFC000", "#A08000"],
                               help_string=_('Palette for speech recognition'))


        palette.add_block('turtle-listen-to',
                          style='boolean-1arg-block-style',
                          label=_('listen to'),
                          prim_name='listen_to',
                          value_block=True,
                          help_string=_('Listen to'))
        self.tw.lc.def_prim('listen_to', 1,
                            Primitive(self.listen_to,
                                      return_type=TYPE_BOOL,
                                      arg_descs=[ArgSlot(TYPE_STRING)]))
Exemple #21
0
def myblock(tw, args):
    """ """

    def _prim_forward_push(tw, line_length):
        try:  # make sure line_length is a number
            line_length = float(line_length)
        except ValueError:
            return
        penstatus = tw.turtles.get_active_turtle().get_pen_status()
        tw.turtles.get_active_turtle().set_pen_state(False)
        tw.turtles.get_active_turtle().forward(line_length)
        r, g, b, a = tw.turtles.get_active_turtle().get_pixel()
        tw.lc.heap.append(b)
        tw.lc.heap.append(g)
        tw.lc.heap.append(r)
        tw.turtles.get_active_turtle().forward(-line_length)
        tw.turtles.get_active_turtle().set_pen_state(penstatus)
        tw.turtles.get_active_turtle().forward(line_length)
        return

    from TurtleArt.tapalette import make_palette, palette_name_to_index
    from TurtleArt.talogo import primitive_dictionary
    from gettext import gettext as _

    # Choose a palette for the new block.
    palette = make_palette("turtle")

    primitive_dictionary["forwardpush"] = _prim_forward_push

    # Create a new block prototype.
    palette.add_block(
        "forwardpush",
        style="basic-style-1arg",
        label=args[0],
        default=100,
        prim_name="forwardpush",
        help_string=_("push destination rgb value to heap"),
    )

    # Add its primitive to the LogoCode dictionary.
    tw.lc.def_prim("forwardpush", 1, lambda self, x: primitive_dictionary["forwardpush"](tw, x))

    # Regenerate the palette, which will now include the new block.
    tw.show_toolbar_palette(palette_name_to_index("turtle"), regenerate=True)
Exemple #22
0
def myblock(tw, name):
    ''' '''

    def _prim_forward_push(tw, line_length):
        try:  # make sure line_length is a number
            line_length = float(line_length)
        except ValueError:
            return
        penstatus = tw.canvas.pendown
        tw.canvas.setpen(False)
        tw.canvas.forward(line_length)
        r, g, b, a = tw.canvas.get_pixel()
        tw.lc.heap.append(b)
        tw.lc.heap.append(g)
        tw.lc.heap.append(r)
        tw.canvas.forward(-line_length)
        tw.canvas.setpen(penstatus)
        tw.canvas.forward(line_length)
        return

    from TurtleArt.tapalette import make_palette, palette_name_to_index
    from TurtleArt.talogo import primitive_dictionary
    from gettext import gettext as _

    # Choose a palette for the new block.
    palette = make_palette('turtle')

    primitive_dictionary['forwardpush'] = _prim_forward_push

    # Create a new block prototype.
    palette.add_block('forwardpush',
                      style='basic-style-1arg',
                      label=name,
                      default=100,
                      prim_name='forwardpush',
                      help_string=_('push destination rgb value to heap'))

    # Add its primitive to the LogoCode dictionary.
    tw.lc.def_prim('forwardpush', 1,
                   lambda self, x: primitive_dictionary['forwardpush'](tw, x))

    # Regenerate the palette, which will now include the new block.
    tw.show_toolbar_palette(palette_name_to_index('turtle'),
                            regenerate=True)
Exemple #23
0
    def setup(self):
        palette = make_palette('external',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of blocks using external requests'),
                               position=10)

        palette.add_block('dictquery',
                              style='number-style-1arg',
                              label=_('define'),
                              default="mouse",
                              help_string=\
                                  _('word\'s definition from web dictionary'),
                              prim_name='dictquery')

        self._parent.lc.def_prim(
            'dictquery', 1,
            Primitive(self.prim_dictquery,
                      return_type=TYPE_STRING,
                      arg_descs=[ArgSlot(TYPE_STRING)]))
Exemple #24
0
  def setup(self):
    palette = make_palette('kinect',  # the name of your palette
                           colors=["#00FF00", "#00A000"],
                           help_string=_('Palette of kinect sensor'))

    primitive_dictionary['xKinect'] = self._prim_xPos
    palette.add_block('xKinect',
                      style='box-style',
                      label=_('hand x-axis'),
                      value_block=True,
                      prim_name='xKinect',
                      help_string=_('returns the hand x-axis position as a number between -540 and 540'))
    self.parent.lc.def_prim('xKinect', 0, lambda self:
                         primitive_dictionary['xKinect']())
    special_block_colors['xKinect'] = COLOR_NOTPRESENT[:]

    primitive_dictionary['yKinect'] = self._prim_yPos
    palette.add_block('yKinect',
                      style='box-style',
                      label=_('hand y-axis'), 
                      value_block=True,
                      prim_name='yKinect', 
                      help_string=_('returns the hand y-axis position as a number between -400 and 400'))
    self.parent.lc.def_prim('yKinect', 0, lambda self:
                         primitive_dictionary['yKinect']())
    special_block_colors['yKinect'] = COLOR_NOTPRESENT[:]

    primitive_dictionary['zKinect'] = self._prim_zPos
    palette.add_block('zKinect',
                      style='box-style',
                      label=_('hand z-axis'),
                      value_block=True,
                      prim_name='zKinect',
                      help_string=_('returns the hand z-axis position as a number between 420 and 1200'))
    self.parent.lc.def_prim('zKinect', 0, lambda self:
                         primitive_dictionary['zKinect']())
    special_block_colors['zKinect'] = COLOR_NOTPRESENT[:]

    self.kinectThread=threading.Timer(0, self.startTracking)
    self.kinectThread.start()
    self.paletteThread=threading.Timer(0, self.paletteCheck)
    self.paletteThread.start()
Exemple #25
0
    def setup(self):

        palette = make_palette('colorview', COLOR_NOTPRESENT, _('colorview'), translation=_('color detector'))

        palette.add_block('color_compare',
                style='boolean-1arg-block-style',
                label=_('color compare'),
                prim_name='color_compare',
                help_string=_('compares a color with the palette'))
        self.tw.lc.def_prim('color_compare', 1, 
            Primitive(self.color_compare, TYPE_BOOL, arg_descs=[ArgSlot(TYPE_COLOR)]))

        palette.add_block('set_tolerance',
                style='basic-style-1arg',
                label=_('set tolerance'),
                default='8',
                prim_name='set_tolerance',
                help_string=_('sets the tolerance between colors'))
        self.tw.lc.def_prim('set_tolerance', 1,
             Primitive(self.set_tolerance, arg_descs=[ArgSlot(TYPE_STRING)]))

        palette.add_block('set_brightness',
                style='basic-style-1arg',
                label=_('set brightness'),
                default='128',
                prim_name='set_brightness',
                help_string=_('sets the brightness of the camera'))
        self.tw.lc.def_prim('set_brightness', 1,
             Primitive(self.set_brightness, arg_descs=[ArgSlot(TYPE_STRING)]))

        palette.add_block('view_camera',
                style='basic-style',
                label=_('view camera'), 
                prim_name='view_camera',
                help_string=_('shows the camera'))
        self.tw.lc.def_prim('view_camera', 0, Primitive(self.view_camera))
    def setup(self):
        """ Setup is called once, when the Turtle Window is created. """
        palette = make_palette('rodi', COLOR_NOTPRESENT,
                               _('Palette for Rodi bots using Arduino'))

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

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

        palette.add_block('count_Rodi',
                          style='box-style',
                          label=_('number of Rodis'),
                          help_string=_('number of Rodi robots'),
                          prim_name='count_Rodi')
        self.tw.lc.def_prim('count_Rodi', 0,
                            Primitive(self.count_Rodi, TYPE_INT))

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

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

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

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

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

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

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

        palette.add_block(
            'distanced_Rodi',
            style='box-style',
            label=_('distance Rodi'),
            prim_name='distance_Rodi',
            help_string=_('returns the distance as a value between 0 and 1'))
        self.tw.lc.def_prim('distance_Rodi', 0,
                            Primitive(self.distance_Rodi, TYPE_FLOAT))
        special_block_colors['distance_Rodi'] = COLOR_NOTPRESENT[:]

        palette.add_block(
            'left_sensor_Rodi',
            style='box-style',
            label=_('left sensor Rodi'),
            prim_name='left_sensor_Rodi',
            help_string=_(
                'returns the left line sensor as a value between 0 and 1'))
        self.tw.lc.def_prim('left_sensor_Rodi', 0,
                            Primitive(self.left_sensor_Rodi, TYPE_FLOAT))
        special_block_colors['left_sensor_Rodi'] = COLOR_NOTPRESENT[:]

        palette.add_block(
            'right_sensor_Rodi',
            style='box-style',
            label=_('right sensor Rodi'),
            prim_name='right_sensor_Rodi',
            help_string=_(
                'returns the right line sensor as a value between 0 and 1'))
        self.tw.lc.def_prim('right_sensor_Rodi', 0,
                            Primitive(self.right_sensor_Rodi, TYPE_FLOAT))
        special_block_colors['right_sensor_Rodi'] = COLOR_NOTPRESENT[:]
Exemple #27
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)]))

        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)]))

        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('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)]))

        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)]))
Exemple #28
0
	def setup(self):

		palette = make_palette('i2c',
								colors=["#FF6060", "#A06060"],
								help_string=_('Palette of i2c'))

		palette.add_block('openI2C',
					style='basic-style',
					label=_('openI2C'),
					value_block=True,
					help_string=_('opens an i2c connection'),
					prim_name='openI2C')

		self.tw.lc.def_prim('openI2C', 0,
			Primitive(self.openI2C))


		palette.add_block('startI2C',
					style='basic-style',
					label=_('startI2C'),
					value_block=True,
					help_string=_('starts an i2c connection'),
					prim_name='startI2C')

		self.tw.lc.def_prim('startI2C', 0,
			Primitive(self.startI2C))


		palette.add_block('stop',
					style='basic-style',
					label=_('stopI2C'),
					value_block=True,
					help_string=_('stops an i2c connection'),
					prim_name='stopI2C')

		self.tw.lc.def_prim('stopI2C', 0,
			Primitive(self.stopI2C))


		palette.add_block('closeI2C',
					style='basic-style',
					label=_('closeI2C'),
					value_block=True,
					help_string=_('closes an i2c connection'),
					prim_name='closeI2C')

		self.tw.lc.def_prim('closeI2C', 0,
			Primitive(self.closeI2C))


		palette.add_block('writeI2C',
					style='basic-style-1arg',
					label=[_('writeI2C')],
					default=1,
					help_string=_('writeI2C'),
					prim_name='writeI2C')

		self.tw.lc.def_prim('writeI2C', 1,
			Primitive(self.writeI2C, arg_descs=[ArgSlot(TYPE_INT)]))


		palette.add_block('readI2C',
					style='box-style',
					label=_('readI2C'),
					help_string=_('readI2C'),
					prim_name='readI2C')

		self.tw.lc.def_prim('readI2C', 0,
			Primitive(self.readI2C, TYPE_NUMBER))


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

		self.tw.lc.def_prim('idleI2C', 0,
			Primitive(self.idleI2C))


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

		self.tw.lc.def_prim('ackI2C', 0,
			Primitive(self.ackI2C))


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

		self.tw.lc.def_prim('notAckI2C', 0,
			Primitive(self.notAckI2C))


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

		self.tw.lc.def_prim('restartI2C', 0,
			Primitive(self.restartI2C))


		palette.add_block('putcI2C',
					style='basic-style-1arg',
					label=[_('putcI2C')],
					default=[""],
					help_string=_('putcI2C'),
					prim_name='putcI2C')

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


		palette.add_block('getcI2C',
					style='box-style',
					label=_('getcI2C'),
					help_string=_('getcI2C'),
					prim_name='getcI2C')

		self.tw.lc.def_prim('getcI2C', 0,
			Primitive(self.getcI2C, TYPE_STRING))


		palette.add_block('putsI2C',
					style='basic-style-1arg',
					label=[_('putsI2C')],
					default=[""],
					help_string=_('putsI2C'),
					prim_name='putsI2C')

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


		palette.add_block('getsI2C',
					style='box-style',
					label=_('getsI2C'),
					help_string=_('getsI2C'),
					prim_name='getsI2C')

		self.tw.lc.def_prim('getsI2C', 0,
			Primitive(self.getsI2C, TYPE_STRING))
Exemple #29
0
    def setup(self):
        """ Setup is called once, when the Turtle Window is created. """
        palette = make_palette('rodi', COLOR_NOTPRESENT,
                             _('Palette for RoDI bots using Arduino'))

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

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

        palette.add_block('count_Rodi',
                          style='box-style',
                          label=_('number of RoDIs'),
                          help_string=_('number of RoDI robots'),
                          prim_name = 'count_Rodi')
        self.tw.lc.def_prim('count_Rodi', 0,
            Primitive(self.count_Rodi, TYPE_INT))

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

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

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

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

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

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

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

        palette.add_block('see_Rodi',
                     style='box-style',
                     label=_('RoDI see'),
                     prim_name='see_Rodi',
                     help_string=_('returns the distance as a value between 0 and 100 cm'))
        self.tw.lc.def_prim('see_Rodi', 0,
            Primitive(self.see_Rodi, TYPE_NUMBER))
        special_block_colors['see_Rodi'] = COLOR_NOTPRESENT[:]

        palette.add_block('sense_left_Rodi',
                     style='box-style',
                     label=_('RoDI sense left'),
                     prim_name='sense_left_Rodi',
                     help_string=_('returns the left line sensor as a value between 0 and 1023'))
        self.tw.lc.def_prim('sense_left_Rodi', 0,
            Primitive(self.sense_left_Rodi, TYPE_NUMBER))
        special_block_colors['sense_left_Rodi'] = COLOR_NOTPRESENT[:]

        palette.add_block('sense_right_Rodi',
                     style='box-style',
                     label=_('RoDI sense right'),
                     prim_name='right_sensor_Rodi',
                     help_string=_('returns the right line sensor as a value between 0 and 1023'))
        self.tw.lc.def_prim('right_sensor_Rodi', 0,
            Primitive(self.sense_right_Rodi, TYPE_NUMBER))
        special_block_colors['right_sensor_Rodi'] = COLOR_NOTPRESENT[:]

        palette.add_block('sense_light_Rodi',
                     style='box-style',
                     label=_('RoDI sense light'),
                     prim_name='sense_light_Rodi',
                     help_string=_('returns the ambient light as a value between 0 and 1023'))
        self.tw.lc.def_prim('sense_light_Rodi', 0,
            Primitive(self.sense_light_Rodi, TYPE_NUMBER))
        special_block_colors['sense_light_Rodi'] = COLOR_NOTPRESENT[:]

        palette.add_block('play_Rodi',
                     style='basic-style-2arg',
                     label=[_('RoDI play'), _('note'), _('duration')],
                     prim_name='play_Rodi',
                     default=[31, 250],
                     help_string=_('make RoDI play a not for a specified duration'))
        self.tw.lc.def_prim('play_Rodi', 2,
            Primitive(self.play_Rodi, arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER)]))
        special_block_colors['play_Rodi'] = COLOR_NOTPRESENT[:]

        palette.add_block('pixel_Rodi',
                     style='basic-style-3arg',
                     label=[_('RoDI pixel'), _('red'), _('green'), _('blue')],
                     prim_name='pixel_Rodi',
                     default=[0, 0, 0],
                     help_string=_('set the color of the pixel'))
        self.tw.lc.def_prim('pixel_Rodi', 3,
            Primitive(self.pixel_Rodi, arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER)]))
        special_block_colors['pixel_Rodi'] = COLOR_NOTPRESENT[:]

        palette.add_block('led_Rodi',
                     style='basic-style-1arg',
                     label=[_('RoDI led'), _('state')],
                     prim_name='led_Rodi',
                     default=[1],
                     help_string=_('set the state of the led (on = 1 | off = 0'))
        self.tw.lc.def_prim('led_Rodi', 1,
            Primitive(self.led_Rodi, arg_descs=[ArgSlot(TYPE_NUMBER)]))
        special_block_colors['led_Rodi'] = COLOR_NOTPRESENT[:]
    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 pallet 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
    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
        primitive_dictionary['read_camera'] = self.prim_read_camera
        media_blocks_dictionary['camera'] = self.prim_take_picture0
        media_blocks_dictionary['camera1'] = self.prim_take_picture1

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

        if self._status:
            sensors_palette.add_block('luminance',
                                      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,
                lambda self: primitive_dictionary['read_camera'](
                    luminance_only=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,
                lambda self: primitive_dictionary['read_camera']())

            media_palette.add_block('camera',
                                    style='box-style-media',
                                    label=' ',
                                    default='CAMERA',
                                    help_string=_('camera output'),
                                    content_block=True)
            if len(self.devices) > 1:
                media_palette.add_block('camera1',
                                        style='box-style-media',
                                        label=' ',
                                        default='CAMERA',
                                        help_string=_('camera output'),
                                        content_block=True)
            else:
                media_palette.add_block('camera1',
                                        hidden=True,
                                        style='box-style-media',
                                        label=' ',
                                        default='CAMERA',
                                        help_string=_('camera output'),
                                        content_block=True)

        else:  # No camera, so blocks should do nothing
            sensors_palette.add_block('luminance',
                                      hidden=True,
                                      style='box-style',
                                      label=_('brightness'),
                                      help_string=\
                                          _('light level detected by camera'),
                                      value_block=True,
                                      prim_name='read_camera')
            self._parent.lc.def_prim('luminance', 0,
                lambda self: primitive_dictionary['read_camera'](
                    luminance_only=True))

            # 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,
                lambda self: primitive_dictionary['read_camera']())

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

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

        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')
Exemple #32
0
    def setup(self):
        ''' Set up Expeyes-specific blocks '''
        primitive_dictionary['eyes-pvsv'] = self._prim_eyes_set_pvs_voltage
        primitive_dictionary['eyes-sqr1v'] = self._prim_eyes_set_sqr1_voltage
        primitive_dictionary['eyes-sqr1f'] = self._prim_eyes_set_sqr1_freq
        primitive_dictionary['eyes-sqr2v'] = self._prim_eyes_set_sqr2_voltage
        primitive_dictionary['eyes-sqr2f'] = self._prim_eyes_set_sqr2_freq
        primitive_dictionary['eyes-set-state'] = self._prim_eyes_set_state
        primitive_dictionary['eyes-get-state'] = self._prim_eyes_get_state
        primitive_dictionary['eyes-voltage'] = self._prim_eyes_get_voltage
        primitive_dictionary['eyes-capture'] = self._prim_eyes_capture

        palette = make_palette('eyes',
                               colors=["#FF6060", "#A06060"],
                               help_string=_('Palette of Expeyes blocks'))

        palette.add_block('pvsv',
                          style='basic-style-1arg',
                          label=_('set PVS'),
                          default=5,
                          help_string=_('set programmable voltage output'),
                          value_block=True,
                          prim_name='eyes-pvsv')
        palette.add_block('sqr1v',
                          style='basic-style-1arg',
                          label=_('set SQR1 voltage'),
                          default=5,
                          help_string=_('set square wave 1 voltage output'),
                          value_block=True,
                          prim_name='eyes-sqr1v')
        palette.add_block('sqr1f',
                          style='basic-style-1arg',
                          label=_('set SQR1 frequency'),
                          default=5,
                          help_string=_('set square wave 1 frequency output'),
                          value_block=True,
                          prim_name='eyes-sqr1f')
        palette.add_block('sqr2v',
                          style='basic-style-1arg',
                          label=_('set SQR2 voltage'),
                          default=5,
                          help_string=_('set square wave 2 voltage output'),
                          value_block=True,
                          prim_name='eyes-sqr2v')
        palette.add_block('sqr2f',
                          style='basic-style-1arg',
                          label=_('set SQR2 frequency'),
                          default=5,
                          help_string=_('set square wave 2 frequency output'),
                          value_block=True,
                          prim_name='eyes-sqr2f')
        palette.add_block('od1s',
                          style='basic-style-1arg',
                          label=_('set OD1'),
                          help_string=_('set digital output level low (0) or \
high (1)'),
                          value_block=True,
                          prim_name='eyes-od1s')
        palette.add_block('in1s',
                          style='boolean-block-style',
                          label=_('IN1 level'),
                          prim_name='eyes-in1s',
                          value_block=True,
                          help_string=_('returns 1 if input 1 voltage level >\
2.5 volts, 0 if in1 voltage level <= 2.5 volts'))
        palette.add_block('in2s',
                          style='boolean-block-style',
                          label=_('IN2 level'),
                          prim_name='eyes-in2s',
                          value_block=True,
                          help_string=_('returns 1 if input 2 voltage level >\
2.5 volts, 0 if in2 voltage level <= 2.5 volts'))
        palette.add_block('sens',
                          style='boolean-block-style',
                          label=_('SEN level'),
                          prim_name='eyes-sens',
                          value_block=True,
                          help_string=_('returns 1 if resistive sensor voltage \
level > 2.5 volts, 0 if sen voltage level <= 2.5 volts'))
        palette.add_block('capture-a1',
                          style='basic-style-2arg',
                          label=[_('capture A1'), _('samples'), _('interval')],
                          default=[300, 100],
                          help_string=_('capture multiple samples from analog \
input 1 at interval (MS); results pushed to FIFO'),
                          prim_name='eyes-capture-a1')
        palette.add_block('a1',
                          style='box-style',
                          label=_('A1'),
                          help_string=_('read analog input 1 voltage'),
                          value_block=True,
                          prim_name='eyes-a1')
        palette.add_block('capture-a2',
                          style='basic-style-2arg',
                          label=[_('capture A2'), _('samples'), _('interval')],
                          default=[300, 100],
                          help_string=_('capture multiple samples from analog \
input 2 at interval (MS); results pushed to FIFO'),
                          prim_name='eyes-capture-a2')
        palette.add_block('a2',
                          style='box-style',
                          label=_('A2'),
                          help_string=_('read analog input 2 voltage'),
                          value_block=True,
                          prim_name='eyes-a2')
        palette.add_block('capture-in1',
                          style='basic-style-2arg',
                          label=[_('capture IN1'), _('samples'), _('interval')],
                          default=[300, 100],
                          help_string=_('capture multiple samples from input 1 \
at interval (MS); results pushed to FIFO'),
                          prim_name='eyes-capture-in1')
        palette.add_block('in1',
                          style='box-style',
                          label=_('IN1'),
                          help_string=_('read input 1 voltage'),
                          value_block=True,
                          prim_name='eyes-in1v')
        palette.add_block('capture-in2',
                          style='basic-style-2arg',
                          label=[_('capture IN2'), _('samples'), _('interval')],
                          default=[300, 100],
                          help_string=_('capture multiple samples from input 2 \
at interval (MS); results pushed to FIFO'),
                          prim_name='eyes-capture-in2')
        palette.add_block('in2',
                          style='box-style',
                          label=_('IN2'),
                          help_string=_('read input 2 voltage'),
                          value_block=True,
                          prim_name='eyes-in2')
        palette.add_block('capture-sen',
                          style='basic-style-2arg',
                          label=[_('capture SEN'), _('samples'), _('interval')],
                          help_string=_('capture multiple samples from sensor \
input at interval (MS); results pushed to FIFO'),
                          default=[300, 100],
                          prim_name='eyes-capture-sen')
        palette.add_block('sen',
                          style='box-style',
                          label=_('SEN'),
                          help_string=_('read analog sensor input voltage'),
                          value_block=True,
                          prim_name='eyes-sen')
        palette.add_block('sqr1',
                          style='box-style',
                          label=_('SQR1'),
                          help_string=_('read square wave 1 voltage'),
                          value_block=True,
                          prim_name='eyes-sqr1')
        palette.add_block('sqr2',
                          style='box-style',
                          label=_('SQR2'),
                          help_string=_('read square wave 2 voltage'),
                          value_block=True,
                          prim_name='eyes-sqr2')
        palette.add_block('pvs',
                          style='box-style',
                          label=_('PVS'),
                          help_string=_('read programmable voltage'),
                          value_block=True,
                          prim_name='eyes-pvs')

        self._parent.lc.def_prim(
            'eyes-pvs', 1,
            lambda self, x: primitive_dictionary['eyes-pvs'](x))
        self._parent.lc.def_prim(
            'eyes-sqr1v', 1,
            lambda self, x: primitive_dictionary['eyes-sqr1'](x))
        self._parent.lc.def_prim(
            'eyes-sqr1f', 1,
            lambda self, x: primitive_dictionary['eyes-sqr1f'](x))
        self._parent.lc.def_prim(
            'eyes-sqr2v', 1,
            lambda self, x: primitive_dictionary['eyes-sqr2'](x))
        self._parent.lc.def_prim(
            'eyes-sqr2f', 1,
            lambda self, x: primitive_dictionary['eyes-sqr2f'](x))
        self._parent.lc.def_prim(
            'eyes-in1', 0,
            lambda self: primitive_dictionary['eyes-get-state'](3))
        self._parent.lc.def_prim(
            'eyes-in2', 0,
            lambda self: primitive_dictionary['eyes-get-state'](4))
        self._parent.lc.def_prim(
            'eyes-sen', 0,
            lambda self: primitive_dictionary['eyes-get-state'](5))
        self._parent.lc.def_prim(
            'eyes-od1', 1,
            lambda self, x: primitive_dictionary['eyes-set-state'](10, x))
        self._parent.lc.def_prim(
            'eyes-a1', 0,
            lambda self: primitive_dictionary['eyes-voltage'](1))
        self._parent.lc.def_prim(
            'eyes-a2', 0,
            lambda self, x: primitive_dictionary['eyes-voltage'](2))
        self._parent.lc.def_prim(
            'eyes-in1', 0,
            lambda self, x: primitive_dictionary['eyes-voltage'](3))
        self._parent.lc.def_prim(
            'eyes-in2', 0,
            lambda self, x: primitive_dictionary['eyes-voltage'](4))
        self._parent.lc.def_prim(
            'eyes-sen', 0,
            lambda self, x: primitive_dictionary['eyes-voltage'](5))
        self._parent.lc.def_prim(
            'eyes-sqr1', 0,
            lambda self, x: primitive_dictionary['eyes-voltage'](6))
        self._parent.lc.def_prim(
            'eyes-sqr2', 0,
            lambda self, x: primitive_dictionary['eyes-voltage'](7))
        self._parent.lc.def_prim(
            'eyes-pvs', 0,
            lambda self, x: primitive_dictionary['eyes-voltage'](12))
        self._parent.lc.def_prim(
            'eyes-capture-a1', 2,
            lambda self, x, y: primitive_dictionary['eyes-capture'](1, x, y))
        self._parent.lc.def_prim(
            'eyes-capture-a2', 2,
            lambda self, x, y: primitive_dictionary['eyes-capture'](2, x, y))
        self._parent.lc.def_prim(
            'eyes-capture-in1', 2,
            lambda self, x, y: primitive_dictionary['eyes-capture'](3, x, y))
        self._parent.lc.def_prim(
            'eyes-capture-in2', 2,
            lambda self, x, y: primitive_dictionary['eyes-capture'](4, x, y))
        self._parent.lc.def_prim(
            'eyes-capture-sen', 2,
            lambda self, x, y: primitive_dictionary['eyes-capture'](5, x, y))
Exemple #33
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[:]
Exemple #34
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)]))

        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)]))

        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('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)]))

        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)]))
Exemple #35
0
    def setup(self):

        paletteardrone = make_palette('ardrone',
                                      COLOR_NOTPRESENT,
                                      _('ArDrone'),
                                      translation=_('ardrone'))

        paletteardrone.add_block(
            'emergenciaDrone',
            style='basic-style',
            label=_('emergencia Drone'),
            prim_name='emergenciaDrone',
            help_string=_('intercambia estado de emergencia del drone'))
        self.tw.lc.def_prim('emergenciaDrone', 0,
                            Primitive(self.emergenciaDrone))
        special_block_colors['emergenciaDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block(
            'calibrarDrone',
            style='basic-style',
            label=_('calibrar Drone'),
            prim_name='calibrarDrone',
            help_string=_('calibra el drone, tiene que estar en tierra'))
        self.tw.lc.def_prim('calibrarDrone', 0, Primitive(self.calibrarDrone))
        special_block_colors['calibrarDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('despegarDrone',
                                 style='basic-style',
                                 label=_('despegar Drone'),
                                 prim_name='despegarDrone',
                                 help_string=_('despega el drone'))
        self.tw.lc.def_prim('despegarDrone', 0, Primitive(self.despegarDrone))
        special_block_colors['despegarDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('aterrizarDrone',
                                 style='basic-style',
                                 label=_('aterrizar Drone'),
                                 prim_name='aterrizarDrone',
                                 help_string=_('aterrizar el drone'))
        self.tw.lc.def_prim('aterrizarDrone', 0,
                            Primitive(self.aterrizarDrone))
        special_block_colors['aterrizarDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('flotarDrone',
                                 style='basic-style',
                                 label=_('flota Drone'),
                                 prim_name='flotarDrone',
                                 help_string=_('flota el drone'))
        self.tw.lc.def_prim('flotarDrone', 0, Primitive(self.flotarDrone))
        special_block_colors['flotarDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('izquierdaDrone',
                                 style='basic-style',
                                 label=_('izquierda Drone'),
                                 prim_name='izquierdaDrone',
                                 help_string=_('izquierda el drone'))
        self.tw.lc.def_prim('izquierdaDrone', 0,
                            Primitive(self.izquierdaDrone))
        special_block_colors['izquierdaDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('derechaDrone',
                                 style='basic-style',
                                 label=_('derecha Drone'),
                                 prim_name='derechaDrone',
                                 help_string=_('derecha el drone'))
        self.tw.lc.def_prim('derechaDrone', 0, Primitive(self.derechaDrone))
        special_block_colors['derechaDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('arribaDrone',
                                 style='basic-style',
                                 label=_('arriba Drone'),
                                 prim_name='arribaDrone',
                                 help_string=_('arriba el drone'))
        self.tw.lc.def_prim('arribaDrone', 0, Primitive(self.arribaDrone))
        special_block_colors['arribaDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('abajoDrone',
                                 style='basic-style',
                                 label=_('abajo Drone'),
                                 prim_name='abajoDrone',
                                 help_string=_('abajo el drone'))
        self.tw.lc.def_prim('abajoDrone', 0, Primitive(self.abajoDrone))
        special_block_colors['abajoDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('adelanteDrone',
                                 style='basic-style',
                                 label=_('adelante Drone'),
                                 prim_name='adelanteDrone',
                                 help_string=_('adelante el drone'))
        self.tw.lc.def_prim('adelanteDrone', 0, Primitive(self.adelanteDrone))
        special_block_colors['adelanteDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('atrasDrone',
                                 style='basic-style',
                                 label=_('atrás Drone'),
                                 prim_name='atrasDrone',
                                 help_string=_('atras el drone'))
        self.tw.lc.def_prim('atrasDrone', 0, Primitive(self.atrasDrone))
        special_block_colors['atrasDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('girarIzquierdaDrone',
                                 style='basic-style',
                                 label=_('girarIzquierda Drone'),
                                 prim_name='girarIzquierdaDrone',
                                 help_string=_('gira a la izquierda el drone'))
        self.tw.lc.def_prim('girarIzquierdaDrone', 0,
                            Primitive(self.girarIzquierdaDrone))
        special_block_colors['girarIzquierdaDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('girarDerechaDrone',
                                 style='basic-style',
                                 label=_('girarDerecha Drone'),
                                 prim_name='girarDerechaDrone',
                                 help_string=_('gira a la derecha el drone'))
        self.tw.lc.def_prim('girarDerechaDrone', 0,
                            Primitive(self.girarDerechaDrone))
        special_block_colors['girarDerechaDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block(
            'bateriaDrone',
            style='box-style',
            label=('batería Drone'),
            prim_name='bateriaDrone',
            help_string=_('retorna porcentaje de bateria del drone'))
        self.tw.lc.def_prim('bateriaDrone', 0, Primitive(self.bateriaDrone))
        special_block_colors['bateriaDrone'] = COLOR_PRESENT[:]

        paletteardrone.add_block('anguloTheta',
                                 style='box-style',
                                 label=('ángulo Theta'),
                                 prim_name='anguloTheta',
                                 help_string=_('angulo theta del drone'))
        self.tw.lc.def_prim('anguloTheta', 0, Primitive(self.anguloTheta))
        special_block_colors['anguloTheta'] = COLOR_PRESENT[:]

        paletteardrone.add_block('anguloPhi',
                                 style='box-style',
                                 label=('ángulo Phi'),
                                 prim_name='anguloPhi',
                                 help_string=_('retorna angulo Phi del drone'))
        self.tw.lc.def_prim('anguloPhi', 0, Primitive(self.anguloPhi))
        special_block_colors['anguloPhi'] = COLOR_PRESENT[:]

        paletteardrone.add_block('anguloPsi',
                                 style='box-style',
                                 label=('ángulo Psi'),
                                 prim_name='anguloPsi',
                                 help_string=_('retorna angulo Psi del drone'))
        self.tw.lc.def_prim('anguloPsi', 0, Primitive(self.anguloPsi))
        special_block_colors['anguloPsi'] = COLOR_PRESENT[:]

        paletteardrone.add_block('alturaDrone',
                                 style='box-style',
                                 label=('altura Drone'),
                                 prim_name='alturaDrone',
                                 help_string=_('altura del drone'))
        self.tw.lc.def_prim('alturaDrone', 0, Primitive(self.alturaDrone))
        special_block_colors['alturaDrone'] = COLOR_PRESENT[:]
    def setup(self):
        ''' set up audio-sensor-specific blocks '''
        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)

        primitive_dictionary['sound'] = self.prim_sound
        primitive_dictionary['volume'] = self.prim_volume
        if self._status:
            palette.add_block('sound',
                              style='box-style',
                              label=_('sound'),
                              help_string=_('raw microphone input signal'),
                              value_block=True,
                              prim_name='sound')

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

        self._parent.lc.def_prim(
            'sound', 0, lambda self: primitive_dictionary['sound'](0))
        self._parent.lc.def_prim(
            'volume', 0, lambda self: primitive_dictionary['volume'](0))

        primitive_dictionary['pitch'] = self.prim_pitch
        if PITCH_AVAILABLE and self._status:
            palette.add_block('pitch',
                              style='box-style',
                              label=_('pitch'),
                              help_string=_('microphone input pitch'),
                              value_block=True,
                              prim_name='pitch')
        else:
            palette.add_block('pitch',
                              hidden=True,
                              style='box-style',
                              label=_('pitch'),
                              help_string=_('microphone input pitch'),
                              value_block=True,
                              prim_name='pitch')
        self._parent.lc.def_prim('pitch', 0,
                                 lambda self: primitive_dictionary['pitch'](0))

        primitive_dictionary['resistance'] = self.prim_resistance
        primitive_dictionary['voltage'] = self.prim_voltage
        if self.hw in [XO1, XO15, XO175, XO4, XO30] and self._status:
            if self.hw == XO1:
                self.voltage_gain = 0.000022
                self.voltage_bias = 1.14
            elif self.hw == XO15:
                self.voltage_gain = -0.00015
                self.voltage_bias = 1.70
            elif self.hw in [XO175, XO4]:  # recalibrate in light of #3675?
                self.voltage_gain = 0.000071
                self.voltage_bias = 0.55
            else:  # XO 3.0
                self.voltage_gain = 0.000077
                self.voltage_bias = 0.72
            palette.add_block('resistance',
                              style='box-style',
                              label=_('resistance'),
                              help_string=_('microphone input resistance'),
                              value_block=True,
                              prim_name='resistance')
            palette.add_block('voltage',
                              style='box-style',
                              label=_('voltage'),
                              help_string=_('microphone input voltage'),
                              value_block=True,
                              prim_name='voltage')
        else:
            palette.add_block('resistance',
                              hidden=True,
                              style='box-style',
                              label=_('resistance'),
                              help_string=_('microphone input resistance'),
                              prim_name='resistance')
            palette.add_block('voltage',
                              hidden=True,
                              style='box-style',
                              label=_('voltage'),
                              help_string=_('microphone input voltage'),
                              prim_name='voltage')

        # FIXME: Only add stereo capture for XO15 (broken on ARM #3675)
        if self.hw in [XO15] and self._status:
            palette.add_block('resistance2',
                              style='box-style',
                              label=_('resistance') + '2',
                              help_string=_('microphone input resistance'),
                              value_block=True,
                              prim_name='resistance2')
            palette.add_block('voltage2',
                              style='box-style',
                              label=_('voltage') + '2',
                              help_string=_('microphone input voltage'),
                              value_block=True,
                              prim_name='voltage2')
        else:
            palette.add_block('resistance2',
                              hidden=True,
                              style='box-style',
                              label=_('resistance') + '2',
                              help_string=_('microphone input resistance'),
                              prim_name='resistance2')
            palette.add_block('voltage2',
                              hidden=True,
                              style='box-style',
                              label=_('voltage') + '2',
                              help_string=_('microphone input voltage'),
                              prim_name='voltage2')
        self._parent.lc.def_prim(
            'resistance', 0,
            lambda self: primitive_dictionary['resistance'](0))
        self._parent.lc.def_prim(
            'voltage', 0, lambda self: primitive_dictionary['voltage'](0))
        self._parent.lc.def_prim(
            'resistance2', 0,
            lambda self: primitive_dictionary['resistance'](1))
        self._parent.lc.def_prim(
            'voltage2', 0, lambda self: primitive_dictionary['voltage'](1))

        self.audio_started = False
        if self.hw in [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 == XO15:
            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)
                }
Exemple #37
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('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',
                          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('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',
                          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')

        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(
            'get_x11_mouse_y', 0,
            Primitive(self.get_x11_mouse_y, TYPE_INT))
        self._parent.lc.def_prim(
            'left_click', 0,
            Primitive(lambda x: 1, TYPE_INT))
        self._parent.lc.def_prim(
            'right_click', 0,
            Primitive(lambda x: 2, TYPE_INT))
        self._parent.lc.def_prim(
            'true', 0,
            Primitive(lambda x: 1, TYPE_INT))
        self._parent.lc.def_prim(
            'false', 0,
            Primitive(lambda x: 0, TYPE_INT))
        self._parent.lc.def_prim(
            'click', 1,
            Primitive(self.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(lambda tt, x: lib_event.show_line(x),
                      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(lambda tt, x: lib_event.set_line_opacity(x),
                      arg_descs=[ArgSlot(TYPE_NUMBER)]))
Exemple #38
0
    def setup(self):

        palette = make_palette('wedo',
                               COLOR_NOTPRESENT,
                               _('Palette of WeDo blocks'),
                               translation=_('wedo'))

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

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

        palette.add_block('wedogetcount',
                          style='box-style',
                          label=_('number of WeDos'),
                          help_string=_('number of WeDo devices'),
                          prim_name='wedocount')
        self.tw.lc.def_prim('wedocount', 0, Primitive(self.count, TYPE_INT))

        palette.add_block('tilt',
                          style='box-style',
                          label=_('tilt'),
                          help_string=_('tilt sensor output: (-1 == no tilt,\
0 == tilt forward, 3 == tilt back, 1 == tilt left, 2 == tilt right)'),
                          value_block=True,
                          prim_name='wedotilt')
        self.tw.lc.def_prim('wedotilt', 0, Primitive(self.getTilt, TYPE_INT))

        palette.add_block('wedodistance',
                          style='box-style',
                          label=_('distance'),
                          help_string=_('distance sensor output'),
                          value_block=True,
                          prim_name='wedodistance')
        self.tw.lc.def_prim('wedodistance', 0,
                            Primitive(self.getDistance, TYPE_INT))

        palette.add_block(
            'wedogetMotorA',
            style='box-style',
            label=_('Motor A'),
            help_string=_('returns the current speed of Motor A'),
            value_block=True,
            prim_name='wedogetMotorA')
        self.tw.lc.def_prim('wedogetMotorA', 0,
                            Primitive(self.getMotorA, TYPE_INT))

        palette.add_block(
            'wedogetMotorB',
            style='box-style',
            label=_('Motor B'),
            help_string=_('returns the current speed of Motor B'),
            value_block=True,
            prim_name='wedogetMotorB')
        self.tw.lc.def_prim('wedogetMotorB', 0,
                            Primitive(self.getMotorB, TYPE_INT))

        palette.add_block('wedosetMotorA',
                          style='basic-style-1arg',
                          label=_('Motor A'),
                          default=30,
                          prim_name='wedosetMotorA',
                          help_string=_('set the speed for Motor A'))
        self.tw.lc.def_prim(
            'wedosetMotorA', 1,
            Primitive(self.setMotorA, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block('wedosetMotorB',
                          style='basic-style-1arg',
                          label=_('Motor B'),
                          default=30,
                          prim_name='wedosetMotorB',
                          help_string=_('set the speed for Motor B'))
        self.tw.lc.def_prim(
            'wedosetMotorB', 1,
            Primitive(self.setMotorB, arg_descs=[ArgSlot(TYPE_NUMBER)]))
Exemple #39
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')]))
Exemple #40
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')
    def setup(self):
        ''' set up audio-sensor-specific blocks '''
        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)

        primitive_dictionary['sound'] = self.prim_sound
        primitive_dictionary['volume'] = self.prim_volume
        if self._status:
            palette.add_block('sound',
                              style='box-style',
                              label=_('sound'),
                              help_string=_('raw microphone input signal'),
                              value_block=True,
                              prim_name='sound')

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

        self._parent.lc.def_prim('sound', 0,
                                 lambda self: primitive_dictionary['sound'](0))
        self._parent.lc.def_prim(
            'volume', 0, lambda self: primitive_dictionary['volume'](0))

        primitive_dictionary['pitch'] = self.prim_pitch
        if PITCH_AVAILABLE and self._status:
            palette.add_block('pitch',
                              style='box-style',
                              label=_('pitch'),
                              help_string=_('microphone input pitch'),
                              value_block=True,
                              prim_name='pitch')
        else:
            palette.add_block('pitch',
                              hidden=True,
                              style='box-style',
                              label=_('pitch'),
                              help_string=_('microphone input pitch'),
                              value_block=True,
                              prim_name='pitch')
        self._parent.lc.def_prim('pitch', 0,
                                 lambda self: primitive_dictionary['pitch'](0))

        primitive_dictionary['resistance'] = self.prim_resistance
        primitive_dictionary['voltage'] = self.prim_voltage
        if self.hw in [XO1, XO15, XO175, XO4, XO30] and self._status:
            if self.hw == XO1:
                self.voltage_gain = 0.000022
                self.voltage_bias = 1.14
            elif self.hw == XO15:
                self.voltage_gain = -0.00015
                self.voltage_bias = 1.70
            elif self.hw in [XO175, XO4]:  # recalibrate in light of #3675?
                self.voltage_gain = 0.000071
                self.voltage_bias = 0.55
            else:  # XO 3.0
                self.voltage_gain = 0.000077
                self.voltage_bias = 0.72
            palette.add_block('resistance',
                              style='box-style',
                              label=_('resistance'),
                              help_string=_('microphone input resistance'),
                              value_block=True,
                              prim_name='resistance')
            palette.add_block('voltage',
                              style='box-style',
                              label=_('voltage'),
                              help_string=_('microphone input voltage'),
                              value_block=True,
                              prim_name='voltage')
        else:
            palette.add_block('resistance',
                              hidden=True,
                              style='box-style',
                              label=_('resistance'),
                              help_string=_('microphone input resistance'),
                              prim_name='resistance')
            palette.add_block('voltage',
                              hidden=True,
                              style='box-style',
                              label=_('voltage'),
                              help_string=_('microphone input voltage'),
                              prim_name='voltage')

        # FIXME: Only add stereo capture for XO15 (broken on ARM #3675)
        if self.hw in [XO15] and self._status:
            palette.add_block('resistance2',
                              style='box-style',
                              label=_('resistance') + '2',
                              help_string=_('microphone input resistance'),
                              value_block=True,
                              prim_name='resistance2')
            palette.add_block('voltage2',
                              style='box-style',
                              label=_('voltage') + '2',
                              help_string=_('microphone input voltage'),
                              value_block=True,
                              prim_name='voltage2')
        else:
            palette.add_block('resistance2',
                              hidden=True,
                              style='box-style',
                              label=_('resistance') + '2',
                              help_string=_('microphone input resistance'),
                              prim_name='resistance2')
            palette.add_block('voltage2',
                              hidden=True,
                              style='box-style',
                              label=_('voltage') + '2',
                              help_string=_('microphone input voltage'),
                              prim_name='voltage2')
        self._parent.lc.def_prim(
            'resistance', 0, lambda self: primitive_dictionary['resistance']
            (0))
        self._parent.lc.def_prim(
            'voltage', 0, lambda self: primitive_dictionary['voltage'](0))
        self._parent.lc.def_prim(
            'resistance2', 0, lambda self: primitive_dictionary['resistance']
            (1))
        self._parent.lc.def_prim(
            'voltage2', 0, lambda self: primitive_dictionary['voltage'](1))

        self.audio_started = False
        if self.hw in [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 == XO15:
            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)
            }
Exemple #42
0
    def setup(self):
        palette = make_palette('icaro',
                               colors=["#006060", "#A00000"],
                               help_string=_('paleta de bloques icaro'))
        primitive_dictionary['motores'] = self._motores
        palette.add_block('motores',  
                     style='basic-style-1arg',  
                     label=_('motores'),  
                     prim_name='motores',
                     default=[1],  
                     help_string=_('activar los motores CC del integrado L293d'))
        self._parent.lc.def_prim('motores', 1, lambda self, valor: primitive_dictionary['motores'](valor))
        primitive_dictionary['activar'] = self._activar

        palette.add_block('activar',  
                     style='basic-style-1arg',  
                     label=_('activar'),  
                     prim_name='activar',
                     default=[1],  
                     help_string=_('activar pines de la placa'))
        self._parent.lc.def_prim('activar', 1, lambda self, valor: primitive_dictionary['activar'](valor))

        primitive_dictionary['abrir'] = self._abrir_puerto
        palette.add_block('abrir',  
                     style='basic-style-1arg',  
                     label=_('abrir puerto'),  
                     prim_name='abrir',
                     default=['/dev/ttyUSB0'],  
                     help_string=_('abre el puerto para comunicacion con la placa'))
        self._parent.lc.def_prim('abrir', 1, lambda self, valor: primitive_dictionary['abrir'](valor))

        primitive_dictionary['retardo'] = self._retardo
        palette.add_block('retardo',  
                     style='basic-style-1arg',  
                     label=_('retardo'),  
                     prim_name='retardo',  
                     default=[1],
                     help_string=_('un retardo en milisegundo'))
        self._parent.lc.def_prim('retardo', 1, lambda self, valor: primitive_dictionary['retardo'](valor))



        primitive_dictionary['servomotores'] = self._servo
        palette.add_block('servomotores',  
                     style='basic-style-2arg',  
                     label=[_('servomotores'),'servo','grados'],  
                     prim_name='servomotores',
                     default=[1,100],  
                     help_string=_('un retardo en milisegundo'))
        self._parent.lc.def_prim('servomotores', 2, lambda self, valor,servo: primitive_dictionary['servomotores'](servo,valor))

        primitive_dictionary['sensoran1'] = self._sensor_analog
        palette.add_block('sensoran1',  
                     style='box-style',  
                     label=_('sensoran1'),  
                     prim_name='sensoran1',  
                     help_string=_('lee el valor del sensor 1 y devuelve 0 o 255'))
        self._parent.lc.def_prim('sensoran1', 0, lambda self: primitive_dictionary['sensoran1'](1))

        primitive_dictionary['sensoran2'] = self._sensor_analog
        palette.add_block('sensoran2',  
                     style='box-style',  
                     label=_('sensoran2'),  
                     prim_name='sensoran2',  
                     help_string=_('lee el valor del sensor 2 y devuelve 0 o 255'))
        self._parent.lc.def_prim('sensoran2', 0, lambda self: primitive_dictionary['sensoran2'](2))
        

        primitive_dictionary['sensoran3'] = self._sensor_analog
        palette.add_block('sensoran3',  
                     style='box-style',  
                     label=_('sensoran3'),  
                     prim_name='sensoran3',  
                     help_string=_('lee el valor del sensor 3 y devuelve 0 o 255'))
        self._parent.lc.def_prim('sensoran3', 0, lambda self: primitive_dictionary['sensoran3'](3))

        primitive_dictionary['sensoran4'] = self._sensor_analog
        palette.add_block('sensoran4',  
                     style='box-style',  
                     label=_('sensoran4'),  
                     prim_name='sensoran4',  
                     help_string=_('lee el valor del sensor 4 y devuelve 0 o 255'))
        self._parent.lc.def_prim('sensoran4', 0, lambda self: primitive_dictionary['sensoran4'](4))

        primitive_dictionary['sensoran5'] = self._sensor_analog
        palette.add_block('sensoran5',  
                     style='box-style',  
                     label=_('sensoran5'),  
                     prim_name='sensoran5',  
                     help_string=_('lee el valor del sensor 5 y devuelve 0 o 255'))
        self._parent.lc.def_prim('sensoran5', 0, lambda self: primitive_dictionary['sensoran5'](5))
        
        primitive_dictionary['sensoran6'] = self._sensor_analog
        palette.add_block('sensoran6',  
                     style='box-style',  
                     label=_('sensoran6'),  
                     prim_name='sensoran6',  
                     help_string=_('lee el valor del sensor 6 y devuelve 0 o 255'))
        self._parent.lc.def_prim('sensoran6', 0, lambda self: primitive_dictionary['sensoran6'](6))

        primitive_dictionary['sensoran7'] = self._sensor_analog
        palette.add_block('sensoran7',  
                     style='box-style',  
                     label=_('sensoran7'),  
                     prim_name='sensoran7',  
                     help_string=_('lee el valor del sensor 7 y devuelve 0 o 255'))
        self._parent.lc.def_prim('sensoran7', 0, lambda self: primitive_dictionary['sensoran7'](7))        
        
        
        primitive_dictionary['sensoran8'] = self._sensor_analog
        palette.add_block('sensoran8',  
                     style='box-style',  
                     label=_('sensoran8'),  
                     prim_name='sensoran8',  
                     help_string=_('lee el valor del sensor 8 y devuelve 0 o 255'))
        self._parent.lc.def_prim('sensoran8', 0, lambda self: primitive_dictionary['sensoran8'](8))
        

        primitive_dictionary['sensor1'] = self._sensor2
        palette.add_block('sensor1',  
                     style='box-style',  
                     label=_('sensor1'),  
                     prim_name='sensor1',  
                     help_string=_('lee el valor del sensor 1 y devuelve 0 o 1'))
        self._parent.lc.def_prim('sensor1', 0, lambda self: primitive_dictionary['sensor1'](1))


        primitive_dictionary['sensor2'] = self._sensor2
        palette.add_block('sensor2',  
                     style='box-style',  
                     label=_('sensor2'),  
                     prim_name='sensor2',  
                     help_string=_('lee el valor del sensor 2 y devuelve 0 o 2'))
        self._parent.lc.def_prim('sensor2', 0, lambda self: primitive_dictionary['sensor2'](2))

        primitive_dictionary['sensor3'] = self._sensor2
        palette.add_block('sensor3',  
                     style='box-style',  
                     label=_('sensor3'),  
                     prim_name='sensor3',  
                     help_string=_('lee el valor del sensor 3 y devuelve 0 o 3'))
        self._parent.lc.def_prim('sensor3', 0, lambda self: primitive_dictionary['sensor3'](3))

        primitive_dictionary['sensor4'] = self._sensor2
        palette.add_block('sensor4',  
                     style='box-style',  
                     label=_('sensor4'),  
                     prim_name='sensor4',  
                     help_string=_('lee el valor del sensor 4 y devuelve 0 o 4'))
        self._parent.lc.def_prim('sensor4', 0, lambda self: primitive_dictionary['sensor4'](4))

        primitive_dictionary['adelante'] = self._adelante
        palette.add_block('adelante',  
                     style='box-style',  
                     label=_('adelante'),  
                     prim_name='adelante',  
                     help_string=_('mueve los dos motores en un sentido'))
        self._parent.lc.def_prim('adelante', 0, lambda self: primitive_dictionary['adelante'](1))

        primitive_dictionary['atras'] = self._atras
        palette.add_block('atras',  
                     style='box-style',  
                     label=_('atras'),  
                     prim_name='atras',  
                     help_string=_('mueve los dos motores en sentido contrario'))
        self._parent.lc.def_prim('atras', 0, lambda self: primitive_dictionary['atras'](1))

        primitive_dictionary['izquierda'] = self._izquierda
        palette.add_block('izquierda',  
                     style='box-style',  
                     label=_('izquierda'),  
                     prim_name='atras',  
                     help_string=_('izquierda'))
        self._parent.lc.def_prim('izquierda', 0, lambda self: primitive_dictionary['izquierda'](1))

        primitive_dictionary['derecha'] = self._derecha
        palette.add_block('derecha',  
                     style='box-style',  
                     label=_('derecha'),  
                     prim_name='derecha',  
                     help_string=_('derecha'))
        self._parent.lc.def_prim('derecha', 0, lambda self: primitive_dictionary['derecha'](1))

        primitive_dictionary['parar'] = self._parar
        palette.add_block('parar',  
                     style='box-style',  
                     label=_('parar'),  
                     prim_name='parar',  
                     help_string=_('parar'))
        self._parent.lc.def_prim('parar', 0, lambda self: primitive_dictionary['parar'](1))
Exemple #43
0
    def setup(self):

        palette = make_palette('wedo', COLOR_NOTPRESENT, _('Palette of WeDo blocks'),
                                translation=_('wedo'))

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

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

        palette.add_block('wedogetcount',
                style='box-style',
                label=_('number of WeDos'),
                help_string=_('number of WeDo devices'),
                prim_name = 'wedocount')
        self.tw.lc.def_prim('wedocount', 0,
            Primitive(self.count, TYPE_INT))

        palette.add_block('tilt',
                style='box-style',
                label=_('tilt'),
                help_string=_('tilt sensor output: (-1 == no tilt,\
0 == tilt forward, 3 == tilt back, 1 == tilt left, 2 == tilt right)'),
                value_block=True,
                prim_name = 'wedotilt')
        self.tw.lc.def_prim('wedotilt', 0,
            Primitive(self.getTilt, TYPE_INT))

        palette.add_block('wedodistance',
                style='box-style',
                label=_('distance'),
                help_string=_('distance sensor output'),
                value_block=True,
                prim_name = 'wedodistance')
        self.tw.lc.def_prim('wedodistance', 0,
            Primitive(self.getDistance, TYPE_INT))
        
        palette.add_block('wedogetMotorA',
                style='box-style',
                label=_('Motor A'),
                help_string=_('returns the current speed of Motor A'),
                value_block=True,
                prim_name = 'wedogetMotorA')
        self.tw.lc.def_prim('wedogetMotorA', 0,
            Primitive(self.getMotorA, TYPE_INT))

        palette.add_block('wedogetMotorB',
                style='box-style',
                label=_('Motor B'),
                help_string=_('returns the current speed of Motor B'),
                value_block=True,
                prim_name = 'wedogetMotorB')
        self.tw.lc.def_prim('wedogetMotorB', 0,
            Primitive(self.getMotorB, TYPE_INT))

        palette.add_block('wedosetMotorA',
                style = 'basic-style-1arg',
                label = _('Motor A'),
                default = 30,
                prim_name = 'wedosetMotorA',
                help_string = _('set the speed for Motor A'))
        self.tw.lc.def_prim('wedosetMotorA', 1,
            Primitive(self.setMotorA, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block('wedosetMotorB',
                style = 'basic-style-1arg',
                label = _('Motor B'),
                default = 30,
                prim_name = 'wedosetMotorB',
                help_string = _('set the speed for Motor B'))
        self.tw.lc.def_prim('wedosetMotorB', 1,
            Primitive(self.setMotorB, arg_descs=[ArgSlot(TYPE_NUMBER)]))
Exemple #44
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)
            }
    def setup(self):
        palette = make_palette('math',
                               colors=["#FF00FF", "#A000A0"],
                               help_string=_('Advanced mathematic functions'))
        palette.add_block('sin',
                          style='number-style-1arg',
                          label='sin',
                          string_or_number=True,
                          prim_name='sin',
                          help_string=_('Sine'))
        self._parent.lc.def_prim(
            'sin', 1, Primitive(lambda self, x: math.sin(math.radians(x)),
                                return_type=TYPE_FLOAT,
                                arg_descs=[ArgSlot(TYPE_FLOAT)]))
        palette.add_block('cos',
                          style='number-style-1arg',
                          label='cos',
                          string_or_number=True,
                          prim_name='cos',
                          help_string=_('Cosine'))
        self._parent.lc.def_prim(
            'cos', 1, Primitive(lambda self, x: math.cos(math.radians(x)),
                                return_type=TYPE_FLOAT,
                                arg_descs=[ArgSlot(TYPE_FLOAT)]))
        palette.add_block('tan',
                          style='number-style-1arg',
                          label='tan',
                          string_or_number=True,
                          prim_name='tan',
                          help_string=_('Tangent'))
        self._parent.lc.def_prim(
            'tan', 1, Primitive(lambda self, x: math.tan(math.radians(x)),
                                return_type=TYPE_FLOAT,
                                arg_descs=[ArgSlot(TYPE_FLOAT)]))
        palette.add_block('asin',
                          style='number-style-1arg',
                          label='asin',
                          string_or_number=True,
                          prim_name='asin',
                          help_string=_('Arcsine'))
        self._parent.lc.def_prim(
            'asin', 1, Primitive(lambda self, x: math.degrees(math.asin(x)),
                                 return_type=TYPE_FLOAT,
                                 arg_descs=[ArgSlot(TYPE_FLOAT)]))
        palette.add_block('acos',
                          style='number-style-1arg',
                          label='acos',
                          string_or_number=True,
                          prim_name='acos',
                          help_string=_('Arccosine'))
        self._parent.lc.def_prim(
            'acos', 1, Primitive(lambda self, x: math.degrees(math.acos(x)),
                                 return_type=TYPE_FLOAT,
                                 arg_descs=[ArgSlot(TYPE_FLOAT)]))
        palette.add_block('atan',
                          style='number-style-1arg',
                          label='atan',
                          string_or_number=True,
                          prim_name='atan',
                          help_string=_('Arctangent'))
        self._parent.lc.def_prim(
            'atan', 1, Primitive(lambda self, x: math.degrees(math.atan(x)),
                                 return_type=TYPE_FLOAT,
                                 arg_descs=[ArgSlot(TYPE_FLOAT)]))

        palette.add_block('degrees',
                          style='number-style-1arg',
                          label='degrees',
                          string_or_number=True,
                          prim_name='degrees',
                          help_string=_('From radians to degrees'))
        self._parent.lc.def_prim(
            'degrees', 1, lambda self, x: math.degrees(x))
        palette.add_block('radians',
                          style='number-style-1arg',
                          label='radians',
                          string_or_number=True,
                          prim_name='radians',
                          help_string=_('From degrees to degrees'))
        self._parent.lc.def_prim(
            'radians', 1, lambda self, x: math.radians(x))

        palette.add_block('pi',
                          style='box-style',
                          label=_('π'),
                          special_name=_('pi'),
                          prim_name='pi',
                          help_string=_('Pi number'))
        self._parent.lc.def_prim(
            'pi', 0, Primitive(lambda arg: math.pi, return_type=TYPE_FLOAT,
                               arg_descs=[]))
        palette.add_block('e',
                          style='box-style',
                          label=_('e'),
                          prim_name='e',
                          help_string=_('e number'))
        self._parent.lc.def_prim(
            'e', 0, Primitive(lambda arg: math.e, return_type=TYPE_FLOAT,
                              arg_descs=[]))

        palette.add_block('exponentiation',
                          style='number-style-block',
                          label=[_('xⁿ'), _('base'), '         ' + _('exp')],
                          special_name=_('exponentiation'),
                          prim_name='exponentiation',
                          help_string=_(
                          'Exponentiation having base and exponent as inputs'))
        self._parent.lc.def_prim('exponentiation', 2,
                                 Primitive(self.exponentiation,
                                 return_type=TYPE_FLOAT,
                                 arg_descs=[ArgSlot(TYPE_FLOAT),
                                            ArgSlot(TYPE_FLOAT)]))
Exemple #46
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('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='box-style',
                          label=_('simulateCopy'),
                          help_string=_('simulate copy event'),
                          prim_name='copy_event')

        palette.add_block('simulatePaste',
                          style='box-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('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(lambda tt, x: lib_event.show_line(x),
                      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(lambda tt, x: lib_event.set_line_opacity(x),
                      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]]]
Exemple #47
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')]))
    def setup(self):

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

        primitive_dictionary['arduinorefresh'] = self._prim_arduinorefresh
        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,
            lambda self :
            primitive_dictionary['arduinorefresh']())
        special_block_colors['arduinorefresh'] = COLOR_PRESENT[:]

        primitive_dictionary['arduinoselect'] = self._prim_arduinoselect
        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,
            lambda self, n: 
            primitive_dictionary['arduinoselect'](n))

        primitive_dictionary['arduinocount'] = self._prim_arduinocount
        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,
            lambda self:
            primitive_dictionary['arduinocount']())

        primitive_dictionary['arduinoname'] = self._prim_arduinoname
        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,
            lambda self, x:
            primitive_dictionary['arduinoname'](x))

        primitive_dictionary['pinmode'] = self._prim_pin_mode
        palette.add_block('pinmode',
                  style='basic-style-2arg',
                  label=[_('pin mode'),_('pin'),_('mode')],
                  help_string=_('Select the pin function (INPUT, OUTPUT, PWM, SERVO).'),
                  prim_name='pinmode')
        self.tw.lc.def_prim('pinmode', 2,
            lambda self, x, y:
            primitive_dictionary['pinmode'](x, y))

        primitive_dictionary['analogwrite'] = self._prim_analog_write
        palette.add_block('analogwrite',
                  style='basic-style-2arg',
                  label=[_('analog write'),_('pin'),_('value')],
                  default=[0, 255],
                  help_string=_('Write analog value in specified port.'),
                  prim_name='analogwrite')
        self.tw.lc.def_prim('analogwrite', 2,
            lambda self, x, y:
            primitive_dictionary['analogwrite'](x, y))

        primitive_dictionary['analogread'] = self._prim_analog_read
        palette.add_block('analogread',
                  style='basic-style-1arg',
                  label=[_('analog read')],
                  default=[0],
                  help_string=_('Read value from analog port. Value may be between 0 and 1023. Use Vref \
to determine voltage. For USB, volt=((read)*5)/1024) approximately.'),
                  prim_name='analogread')
        self.tw.lc.def_prim('analogread', 1,
            lambda self, x:
            primitive_dictionary['analogread'](x))

        primitive_dictionary['digitalwrite'] = self._prim_digital_write
        palette.add_block('digitalwrite',
                  style='basic-style-2arg',
                  label=[_('digital write'),_('pin'),_('value')],
                  default=[13],
                  help_string=_('Write digital value to specified port.'),
                  prim_name='digitalwrite')
        self.tw.lc.def_prim('digitalwrite', 2,
            lambda self, x, y:
            primitive_dictionary['digitalwrite'](x, y))

        primitive_dictionary['digitalread'] = self._prim_digital_read
        palette.add_block('digitalread',
                  style='basic-style-1arg',
                  label=[_('digital read')],
                  default=[13],
                  help_string=_('Read value from digital port.'),
                  prim_name='digitalread')
        self.tw.lc.def_prim('digitalread', 1,
            lambda self, x:
            primitive_dictionary['digitalread'](x))

        primitive_dictionary['high'] = self._prim_high
        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,
            lambda self: primitive_dictionary['high']())

        primitive_dictionary['input'] = self._prim_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,
            lambda self: primitive_dictionary['input']())

        primitive_dictionary['servo'] = self._prim_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,
            lambda self: primitive_dictionary['servo']())

        primitive_dictionary['low'] = self._prim_low
        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,
            lambda self: primitive_dictionary['low']())

        primitive_dictionary['output'] = self._prim_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,
            lambda self: primitive_dictionary['output']())

        primitive_dictionary['pwm'] = self._prim_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,
            lambda self: primitive_dictionary['pwm']())
Exemple #49
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)]))
Exemple #50
0
 def setup(self):
     palette1 = make_palette('gtk-basic-widgets', ["#00FF00","#008000"], _('Gtk plugin'), translation=_('Gtk plugin'))
     palette2 = make_palette('gtk-basic-methods', ["#00FF00","#008000"], _('Gtk plugin2'), translation=_('Gtk plugin2'))
     
     palette1.add_block('MakeWindow',
                 style='basic-style-1arg',
                 label=_('Window'),
                 default=["name"],
                 prim_name='makeWindow',
                 help_string= _('Makes a window with a name'))
                 
     self._parent.lc.def_prim(
         'makeWindow', 1,
         Primitive(self.make_window, arg_descs=[ArgSlot(TYPE_STRING)]))
     
     palette1.add_block('MakeButton',
                 style='basic-style-2arg',
                 label=_('Button'),
                 default=["name", "label"],
                 prim_name='makeButton',
                 help_string= _('Makes a button'))
                 
     self._parent.lc.def_prim(
         'makeButton', 2,
         Primitive(self.make_button, arg_descs=[ArgSlot(TYPE_STRING), ArgSlot(TYPE_STRING)]))
         
     palette1.add_block('MakeVBox',
                 style='basic-style-1arg',
                 label=_('VBox'),
                 default=["name"],
                 prim_name='makeVBox',
                 help_string= _('Makes a vbox'))
                 
     self._parent.lc.def_prim(
         'makeVBox', 1,
         Primitive(self.make_vbox, arg_descs=[ArgSlot(TYPE_STRING)]))
         
     palette1.add_block('MakeHBox',
                 style='basic-style-1arg',
                 label=_('HBox'),
                 default=["name"],
                 prim_name='makeHBox',
                 help_string= _('Makes a hbox'))
                 
     self._parent.lc.def_prim(
         'makeHBox', 1,
         Primitive(self.make_hbox, arg_descs=[ArgSlot(TYPE_STRING)]))
         
     palette2.add_block('hideWidget',
                 style='basic-style-1arg',
                 label=_('Hide Widgets'),
                 default=["name"],
                 prim_name='hideWidget',
                 help_string= _('Hides any gtk widget'))
                 
     self._parent.lc.def_prim(
         'hideWidget', 1,
         Primitive(self.hide_widget, arg_descs=[ArgSlot(TYPE_STRING)]))
         
     palette2.add_block('addWidget',
                 style='basic-style-2arg',
                 label=[_('Add Widgets'), _('dest'), _('src')],
                 default=["dest", "src"],
                 prim_name='addWidget',
                 help_string= _('Adds any gtk widget'))
                 
     #palette2.add_block('connect',
      #           style='basic-style-3arg',
       #          label=[_('Connect'), _('dest'), _('on'), _('to')],
        #         default=["dest", "clicked", "func"],
         #        prim_name='connectWidget',
          #       help_string= _('Connect'))
          
                 
     palette2.add_block('gtkMain',
                 style='basic-style',
                 label=_('Gtk Main'),
                 prim_name='gtkMain',
                 help_string= _('Runs gtk main loop'))
                 
     self._parent.lc.def_prim(
         'addWidget', 2,
         Primitive(self.add_widget, arg_descs=[ArgSlot(TYPE_STRING),
                                               ArgSlot(TYPE_STRING)]))
         
     self._parent.lc.def_prim(
         'gtkMain', 0,
         Primitive(lambda x : gtk.main()))
    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)
                }
    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')
    def setup(self):

        palette = make_palette('sumtia', ["#00FF00", "#008000"],
                               _('SumBot'),
                               translation=_('sumtia'))

        palette.add_block('updateState',
                          style='basic-style',
                          label=_('update information'),
                          prim_name='updateState',
                          help_string=_('update information from the server'))
        self.tw.lc.def_prim('updateState', 0, Primitive(self.updateState))

        palette.add_block('sendVelocities',
                          style='basic-style-2arg',
                          label=_('speed SumBot'),
                          prim_name='sendVelocities',
                          default=[10, 10],
                          help_string=_('submit the speed to the SumBot'))
        self.tw.lc.def_prim(
            'sendVelocities', 2,
            Primitive(self.sendVelocities,
                      arg_descs=[ArgSlot(TYPE_NUMBER),
                                 ArgSlot(TYPE_NUMBER)]))

        palette.add_block(
            'setVel',
            style='basic-style-1arg',
            label=_('speed SumBot'),
            prim_name='setVel',
            default=[10],
            help_string=_('set the default speed for the movement commands'))
        self.tw.lc.def_prim(
            'setVel', 1,
            Primitive(self.setVel, arg_descs=[ArgSlot(TYPE_NUMBER)]))

        palette.add_block('forwardSumtia',
                          style='basic-style',
                          label=_('forward SumBot'),
                          prim_name='forwardSumtia',
                          help_string=_('move SumBot forward'))
        self.tw.lc.def_prim('forwardSumtia', 0, Primitive(self.forward))

        palette.add_block('backwardSumtia',
                          style='basic-style',
                          label=_('backward SumBot'),
                          prim_name='backwardSumtia',
                          help_string=_('move SumBot backward'))
        self.tw.lc.def_prim('backwardSumtia', 0, Primitive(self.backward))

        palette.add_block('stopSumtia',
                          style='basic-style',
                          label=_('stop SumBot'),
                          prim_name='stopSumtia',
                          help_string=_('stop the SumBot'))
        self.tw.lc.def_prim('stopSumtia', 0, Primitive(self.stop))

        palette.add_block('leftSumtia',
                          style='basic-style',
                          label=_('left SumBot'),
                          prim_name='leftSumtia',
                          help_string=_('turn left the SumBot'))
        self.tw.lc.def_prim('leftSumtia', 0, Primitive(self.left))

        palette.add_block('rightSumtia',
                          style='basic-style',
                          label=_('right SumBot'),
                          prim_name='rightSumtia',
                          help_string=_('turn right the SumBot'))
        self.tw.lc.def_prim('rightSumtia', 0, Primitive(self.right))

        palette.add_block(
            'angleToCenter',
            style='box-style',
            label=_('angle to center'),
            prim_name='angleToCenter',
            help_string=_('get the angle to the center of the dohyo'))
        self.tw.lc.def_prim('angleToCenter', 0,
                            Primitive(self.angleToCenter, TYPE_INT))

        palette.add_block('angleToOpponent',
                          style='box-style',
                          label=_('angle to Enemy'),
                          prim_name='angleToOpponent',
                          help_string=_('get the angle to the Enemy'))
        self.tw.lc.def_prim('angleToOpponent', 0,
                            Primitive(self.angleToOpponent, TYPE_INT))

        palette.add_block('getX',
                          style='box-style',
                          label=_('x coor. SumBot'),
                          prim_name='getX',
                          help_string=_('get the x coordinate of the SumBot'))
        self.tw.lc.def_prim('getX', 0, Primitive(self.getX, TYPE_INT))

        palette.add_block('getY',
                          style='box-style',
                          label=_('y coor. SumBot'),
                          prim_name='getY',
                          help_string=_('get the y coordinate of the SumBot'))
        self.tw.lc.def_prim('getY', 0, Primitive(self.getY, TYPE_INT))

        palette.add_block('getOpX',
                          style='box-style',
                          label=_('x coor. Enemy'),
                          prim_name='getOpX',
                          help_string=_('get the x coordinate of the Enemy'))
        self.tw.lc.def_prim('getOpX', 0, Primitive(self.getOpX, TYPE_INT))

        palette.add_block('getOpY',
                          style='box-style',
                          label=_('y coor. Enemy'),
                          prim_name='getOpY',
                          help_string=_('get the y coordinate of the Enemy'))
        self.tw.lc.def_prim('getOpY', 0, Primitive(self.getOpY, TYPE_INT))

        palette.add_block('getRot',
                          style='box-style',
                          label=_('rotation SumBot'),
                          prim_name='getRot',
                          help_string=_('get the rotation of the Sumbot'))
        self.tw.lc.def_prim('getRot', 0, Primitive(self.getRot, TYPE_INT))

        palette.add_block('getOpRot',
                          style='box-style',
                          label=_('rotation Enemy'),
                          prim_name='getOpRot',
                          help_string=_('get the rotation of the Enemy'))
        self.tw.lc.def_prim('getOpRot', 0, Primitive(self.getOpRot, TYPE_INT))

        palette.add_block(
            'getDistCenter',
            style='box-style',
            label=_('distance to center'),
            prim_name='getDistCenter',
            help_string=_('get the distance to the center of the dohyo'))
        self.tw.lc.def_prim('getDistCenter', 0,
                            Primitive(self.getDistCenter, TYPE_INT))

        palette.add_block('getDistOp',
                          style='box-style',
                          label=_('distance to Enemy'),
                          prim_name='getDistOp',
                          help_string=_('get the distance to the Enemy'))
        self.tw.lc.def_prim('getDistOp', 0, Primitive(self.getDistOp,
                                                      TYPE_INT))