コード例 #1
0
ファイル: pattern_detection.py プロジェクト: AlanJAS/Butia
    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)
コード例 #2
0
ファイル: fischer.py プロジェクト: AlanJAS/Butia
    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)]))
コード例 #3
0
ファイル: colorview.py プロジェクト: AlanJAS/Butia
    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))
コード例 #4
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)]))
コード例 #5
0
ファイル: arduino.py プロジェクト: AlanJAS/arduino
    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')]))
コード例 #6
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[:]
コード例 #7
0
ファイル: xevents.py プロジェクト: nvazquez/Turtlebots
    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]]]
コード例 #8
0
    def change_butia_palette_colors(self, force_refresh, change_statics_blocks,
                                    change_extras_blocks):

        self.make_match_dict()

        self.getCastButia()

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

                            label = label_name_from_device_id[blk_name]

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

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

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

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

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

        try:
            index = palette_name_to_index('butia-cast')
            self.tw.regenerate_palette(index)
        except:
            pass
コード例 #9
0
    def setup(self):
        palette = make_palette('atyarandu',
                    colors=COLOR_PRESENT,
                    help_string=_('Palette of Renewable Energy'))

        palette.add_block('engrefreshagh',
                style='basic-style',
                label=_('refresh Energy'),
                value_block=True,
                help_string=\
                    _('updates the status of the 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
コード例 #10
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)]))
コード例 #11
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[:]
コード例 #12
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))
コード例 #13
0
    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))
コード例 #14
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)]))
コード例 #15
0
    def setup(self):

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        palette.add_block(
            'pixels_min',
            style='basic-style-1arg',
            label=_('minimum pixels'),
            default=10,
            help_string=_('set the minimal number of pixels to follow'),
            prim_name='pixels_min')
        self.tw.lc.def_prim(
            'pixels_min', 1,
            Primitive(self.pixels_min, arg_descs=[ArgSlot(TYPE_NUMBER)]))
コード例 #16
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=[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[:]
コード例 #17
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)]))
コード例 #18
0
    def setup(self):
       
        palette = make_palette('ax12',COLOR_NOTPRESENT,_('AX-12 Motors functions'), translation=_('ax12'))

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

        palette.add_block('getID',
                     style='box-style',
                     label=_('getID'),
                     prim_name='getID',
                     help_string=_('return a random ID of the conected AX-motors'))
        self.tw.lc.def_prim('getID', 0,
            Primitive(self.getID))
        special_block_colors['getID'] = COLOR_NOTPRESENT[:]

        palette.add_block('stopAx',
            style='basic-style-1arg',
            label=[_('stop')],
            prim_name='stopAx',
            default=[1],
            help_string=_('stop the AX-12 motors '))
        self.tw.lc.def_prim('stopAx', 1,
            Primitive(self.stpSpeed, arg_descs=[ArgSlot(TYPE_NUMBER)]))
        special_block_colors['stopAx'] = COLOR_NOTPRESENT[:]

        palette.add_block('setAxPosition',
            style='basic-style-2arg',
            label=[_('set position'), _('idMotor'), _('degrees')],
            prim_name='setAxPosition',
            default=[1,0],
            help_string=_('set the position of the AX-12 motors'))
        self.tw.lc.def_prim('setAxPosition', 2,
            Primitive(self.sPosition, arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER)]))
        special_block_colors['setAxPosition'] = COLOR_NOTPRESENT[:]

        palette.add_block('getAxPosition',
                style='number-style-1arg',
                label=[_('get position')],
                prim_name='getAxPosition',
                default=1,
                help_string=_('get the position of the AX-12 motors'))
        self.tw.lc.def_prim('getAxPosition', 1,
                Primitive(self.gPosition, TYPE_INT, [ArgSlot(TYPE_NUMBER)]))
        special_block_colors['getAxPosition'] = COLOR_NOTPRESENT[:]

        palette.add_block('setAxSpeed',
            style='basic-style-2arg',
            label=[_('set speed'), _('idMotor'), _('speed')],
            prim_name='setAxSpeed',
            default=[1,0],
            help_string=_('set the speed of the AX-12 motors'))
        self.tw.lc.def_prim('setAxSpeed', 2,
            Primitive(self.sSpeed, arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER)]))
        special_block_colors['setAxSpeed'] = COLOR_NOTPRESENT[:]

        palette.add_block('getAxTemperature',
                style='number-style-1arg',
                label=[_('get temperature')],
                prim_name='getAxTemperature',
                default=1,
                help_string=_('get the temperature of the AX-12 motors'))
        self.tw.lc.def_prim('getAxTemperature', 1,
                Primitive(self.gTemp, TYPE_INT, [ArgSlot(TYPE_NUMBER)]))
        special_block_colors['getAxTemperature'] = COLOR_NOTPRESENT[:]

        palette.add_block('setAxLed',
            style='basic-style-2arg',
            label=[_('set led'), _('idMotor'), _('action')],
            prim_name='setAxLed',
            default=[1,0],
            help_string=_('turns the AX led motor with id idMotor when action = 1, turn off if action = 0'))
        self.tw.lc.def_prim('setAxLed', 2,
            Primitive(self.axLed,arg_descs=[ArgSlot(TYPE_NUMBER), ArgSlot(TYPE_NUMBER)]))
        special_block_colors['setAxLed'] = COLOR_NOTPRESENT[:]

        palette.add_block('getAxVoltage',
                style='number-style-1arg',
                label=[_('get voltage')],
                prim_name='getAxVoltage',
                default=1,
                help_string=_('get the voltage of the AX-12 motors'))
        self.tw.lc.def_prim('getAxVoltage', 1,
                Primitive(self.gVolt, TYPE_INT, [ArgSlot(TYPE_NUMBER)]))
        special_block_colors['getAxVoltage'] = COLOR_NOTPRESENT[:]
コード例 #19
0
    def _eat_palette(self):
        palette = make_palette('eatme',
                               colors=["#FFFFFF", "#A0A0A0"],
                               help_string=_('Palette of nutrition'))

        palette.add_block('get_calories',
                          style='number-style-1arg',
                          label=_('get calories'),
                          prim_name='get_calories',
                          help_string=_('extract caloric content of food'))
        self.tw.lc.def_prim(
            'get_calories', 1,
            Primitive(self._prim_nutriant,
                      arg_descs=[ArgSlot(TYPE_OBJECT)],
                      kwarg_descs={'nutriant': CALORIES},
                      return_type=TYPE_NUMBER))

        palette.add_block('get_protein',
                          style='number-style-1arg',
                          label=_('get protein'),
                          prim_name='get_protein',
                          help_string=_('extract protein content of food'))
        self.tw.lc.def_prim(
            'get_protein', 1,
            Primitive(self._prim_nutriant,
                      arg_descs=[ArgSlot(TYPE_OBJECT)],
                      kwarg_descs={'nutriant': PROTEIN},
                      return_type=TYPE_NUMBER))

        palette.add_block('get_carbohydrate',
                          style='number-style-1arg',
                          label=_('get carbohydrates'),
                          prim_name='get_carbohydrate',
                          help_string=_('extract carbohydrate content of'
                                        ' food'))
        self.tw.lc.def_prim(
            'get_carbohydrate', 1,
            Primitive(self._prim_nutriant,
                      arg_descs=[ArgSlot(TYPE_OBJECT)],
                      kwarg_descs={'nutriant': CARBOHYDRATE},
                      return_type=TYPE_NUMBER))

        palette.add_block('calories',
                          style='box-style',
                          label=_('calories eaten'),
                          help_string=_('stored caloric content of food'
                                        ' eaten'),
                          prim_name='calories',
                          value_block=True)
        self.tw.lc.def_prim(
            'calories', 0,
            Primitive(self._prim_get_calories, return_type=TYPE_NUMBER))
        palette.add_block('protein',
                          style='box-style',
                          label=_('protein eaten'),
                          help_string=_('stored protein content of food'
                                        ' eaten'),
                          prim_name='protein',
                          value_block=True)
        self.tw.lc.def_prim(
            'protein', 0,
            Primitive(self._prim_get_protein, return_type=TYPE_NUMBER))

        palette.add_block('carbohydrate',
                          style='box-style',
                          label=_('carbohydrates eaten'),
                          help_string=_('stored carbohydrate content of'
                                        ' food eaten'),
                          prim_name='carbohydrate',
                          value_block=True)
        self.tw.lc.def_prim(
            'carbohydrate', 0,
            Primitive(self._prim_get_carbohydrate, return_type=TYPE_NUMBER))

        palette.add_block('get_fiber',
                          style='number-style-1arg',
                          label=_('get fiber'),
                          prim_name='get_fiber',
                          help_string=_('extract fiber content of food'))
        self.tw.lc.def_prim(
            'get_fiber', 1,
            Primitive(self._prim_nutriant,
                      arg_descs=[ArgSlot(TYPE_OBJECT)],
                      kwarg_descs={'nutriant': FIBER},
                      return_type=TYPE_NUMBER))

        palette.add_block('get_fat',
                          style='number-style-1arg',
                          label=_('get fat'),
                          prim_name='get_fat',
                          help_string=_('extract fat content of food'))
        self.tw.lc.def_prim(
            'get_fat', 1,
            Primitive(self._prim_nutriant,
                      arg_descs=[ArgSlot(TYPE_OBJECT)],
                      kwarg_descs={'nutriant': FAT},
                      return_type=TYPE_NUMBER))

        palette.add_block('eat',
                          style='basic-style-1arg',
                          label=_('eat'),
                          prim_name='eat',
                          help_string=_('eat food and store its nutritional'
                                        ' value'))
        self.tw.lc.def_prim(
            'eat', 1,
            Primitive(self._prim_eat, arg_descs=[ArgSlot(TYPE_VECTOR)]))

        palette.add_block('fiber',
                          style='box-style',
                          label=_('fiber eaten'),
                          help_string=_('stored fiber content of food eaten'),
                          prim_name='fiber',
                          value_block=True)
        self.tw.lc.def_prim(
            'fiber', 0, Primitive(self._prim_get_fiber,
                                  return_type=TYPE_NUMBER))

        palette.add_block('fat',
                          style='box-style',
                          label=_('fat eaten'),
                          help_string=_('stored fat content of food eaten'),
                          prim_name='fat',
                          value_block=True)
        self.tw.lc.def_prim(
            'fat', 0, Primitive(self._prim_get_fat, return_type=TYPE_NUMBER))

        palette.add_block('digest',
                          style='basic-style-extended-vertical',
                          label=_('digest meal'),
                          prim_name='digest',
                          help_string=_('digest food eaten and zero out'
                                        ' stored nutritional values'))
        self.tw.lc.def_prim('digest', 0, Primitive(self._prim_digest))

        palette.add_block('get_name',
                          style='number-style-1arg',
                          label=_('get name'),
                          prim_name='get_name',
                          help_string=_('get name of food'))
        self.tw.lc.def_prim(
            'get_name', 1,
            Primitive(self._prim_name,
                      arg_descs=[ArgSlot(TYPE_OBJECT)],
                      return_type=TYPE_STRING))

        palette.add_block('add_food',
                          hidden=True,
                          string_or_number=True,
                          style='basic-style-7arg',
                          label=[
                              _('add food') + '\n\n',
                              _('name'),
                              _('image'),
                              _('calories'),
                              _('protein'),
                              _('carbohydrates'),
                              _('fiber'),
                              _('fat')
                          ],
                          prim_name='add_food',
                          default=['banana', None, 105, 1, 27, 3, 0],
                          help_string=_('add a new food block'))
        self.tw.lc.def_prim(
            'add_food', 7,
            Primitive(self._prim_add_food,
                      return_type=TYPE_NUMBER,
                      arg_descs=[
                          ArgSlot(TYPE_STRING),
                          ArgSlot(TYPE_OBJECT),
                          ArgSlot(TYPE_NUMBER),
                          ArgSlot(TYPE_NUMBER),
                          ArgSlot(TYPE_NUMBER),
                          ArgSlot(TYPE_NUMBER),
                          ArgSlot(TYPE_NUMBER)
                      ]))

        # macro
        palette.add_block('newfood',
                          style='basic-style-1arg',
                          label=_('add food'),
                          help_string=_('add a new food block'))
コード例 #20
0
ファイル: Xevents.py プロジェクト: rafaelcor/turtleclick
    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)]))