def _add_signal_botton(self,palette,block_name,label): #If icon exists, use it instead of just the label iconPath = os.path.abspath(os.path.join(os.path.dirname(__file__), 'images/'+block_name+'off.svg')) if os.path.exists(iconPath): palette.add_block(block_name , style='box-style-media', label='', default=block_name, prim_name=block_name, help_string= label ) BLOCKS_WITH_SKIN.append(block_name) NO_IMPORT.append(block_name) MEDIA_SHAPES.append(block_name + 'off') MEDIA_SHAPES.append(block_name + 'small') EXPAND_SKIN[block_name] = (0, 10) else: palette.add_block(block_name , style='box-style', label=block_name, default=block_name, prim_name=block_name, help_string= label ) self._parent.lc.def_prim(block_name , 0, lambda self: block_name)
def _make_polynominal(self, palette, block_name, i18n_name, polynominal, expand=(0, 0)): """ Factory for polynominal blocks """ CONSTANTS[block_name] = Vector(i18n_name, polynominal) palette.add_block( block_name, style='box-style-media', label='', default=None, prim_name=block_name, # TRANS: g is grams, e.g., 3g of fat help_string=_('%(blockname)s:' ' (%(no_cal)d %(cal)s,' ' %(no_prot)dg of %(prot)s,' ' %(no_carb)dg of %(carb)s,' ' %(no_fib)dg of %(fib)s,' ' %(no_fat)dg of %(fat)s)') % { 'blockname': i18n_name, 'no_cal': polynominal[0], 'cal': _('calories'), 'no_prot': polynominal[1], 'prot': _('protein'), 'no_carb': polynominal[2], 'carb': _('carbohydrates'), 'no_fib': polynominal[3], 'fib': _('fiber'), 'no_fat': polynominal[4], 'fat': _('fat') }) BLOCKS_WITH_SKIN.append(block_name) NO_IMPORT.append(block_name) MEDIA_SHAPES.append(block_name + 'off') MEDIA_SHAPES.append(block_name + 'small') if expand > 0: EXPAND_SKIN[block_name] = expand self.tw.lc.def_prim( block_name, 0, Primitive(CONSTANTS.get, return_type=TYPE_VECTOR, arg_descs=[ConstantArg(block_name)]))
def _add_signal_botton(self, palette, block, help): global CONSTANTS CONSTANTS[block] = block block_name = block + "Pat" iconPath = os.path.abspath(os.path.join(self._path, 'images', block_name + 'off.svg')) if os.path.exists(iconPath): palette.add_block(block_name, style='box-style-media', prim_name=block_name, help_string= help) BLOCKS_WITH_SKIN.append(block_name) NO_IMPORT.append(block_name) MEDIA_SHAPES.append(block_name) MEDIA_SHAPES.append(block_name + 'off') MEDIA_SHAPES.append(block_name + 'small') EXPAND_SKIN[block_name] = (0, 10) else: palette.add_block(block_name, style='box-style', label=block, help_string=help, prim_name=block_name) self.tw.lc.def_prim(block_name, 0, Primitive(CONSTANTS.get, TYPE_STRING, [ConstantArg(block)]))
def setup(self): ''' Set up the palettes ''' sensors_palette = make_palette('sensor', colors=["#FF6060", "#A06060"], help_string=_( 'Palette of sensor blocks'), position=6) media_palette = make_palette('media', colors=["#A0FF00", "#80A000"], help_string=_('Palette of media objects'), position=7) # set up camera-specific blocks media_blocks_dictionary['camera'] = self.prim_take_picture0 media_blocks_dictionary['camera1'] = self.prim_take_picture1 SKIN_PATHS.append('plugins/camera_sensor/images') hidden = True second_cam = False if self._status: hidden = False if len(self.devices) > 1: second_cam = True sensors_palette.add_block('luminance', hidden=hidden, style='box-style', label=_('brightness'), help_string=_( 'light level detected by camera'), value_block=True, prim_name='luminance') self._parent.lc.def_prim( 'luminance', 0, Primitive(self.prim_read_camera, return_type=TYPE_NUMBER, kwarg_descs={'luminance_only': ConstantArg(True)}, call_afterwards=self.after_luminance)) media_palette.add_block('camera', hidden=hidden, style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) media_palette.add_block('camera1', hidden=not(second_cam), style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) # Depreciated block sensors_palette.add_block( 'read_camera', hidden=True, style='box-style', label=_('brightness'), help_string=_('Average RGB color from camera is pushed to the stack'), value_block=True, prim_name='read_camera') self._parent.lc.def_prim( 'read_camera', 0, Primitive(self.prim_read_camera, return_type=TYPE_NUMBER, kwarg_descs={'luminance_only': ConstantArg(False)})) NO_IMPORT.append('camera') BLOCKS_WITH_SKIN.append('camera') NO_IMPORT.append('camera1') BLOCKS_WITH_SKIN.append('camera1') MEDIA_SHAPES.append('camerasmall') MEDIA_SHAPES.append('cameraoff') MEDIA_SHAPES.append('camera1small') MEDIA_SHAPES.append('camera1off')
def setup(self): ''' Set up the palettes ''' sensors_palette = make_palette('sensor', colors=["#FF6060", "#A06060"], help_string=_( 'Palette of sensor blocks'), position=6) media_palette = make_palette('media', colors=["#A0FF00", "#80A000"], help_string=_('Palette of media objects'), position=7) # set up camera-specific blocks primitive_dictionary['read_camera'] = self.prim_read_camera media_blocks_dictionary['camera'] = self.prim_take_picture0 media_blocks_dictionary['camera1'] = self.prim_take_picture1 SKIN_PATHS.append('plugins/camera_sensor/images') if self._status: sensors_palette.add_block('luminance', style='box-style', label=_('brightness'), help_string=_( 'light level detected by camera'), value_block=True, prim_name='luminance') self._parent.lc.def_prim('luminance', 0, lambda self: primitive_dictionary['read_camera']( luminance_only=True)) # Depreciated block sensors_palette.add_block('read_camera', hidden=True, style='box-style', label=_('brightness'), help_string=_( 'Average RGB color from camera \ is pushed to the stack'), value_block=True, prim_name='read_camera') self._parent.lc.def_prim('read_camera', 0, lambda self: primitive_dictionary['read_camera']()) media_palette.add_block('camera', style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) if len(self.devices) > 1: media_palette.add_block('camera1', style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) else: media_palette.add_block('camera1', hidden=True, style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) else: # No camera, so blocks should do nothing sensors_palette.add_block('luminance', hidden=True, style='box-style', label=_('brightness'), help_string=\ _('light level detected by camera'), value_block=True, prim_name='read_camera') self._parent.lc.def_prim('luminance', 0, lambda self: primitive_dictionary['read_camera']( luminance_only=True)) # Depreciated block sensors_palette.add_block('read_camera', hidden=True, style='box-style', label=_('brightness'), help_string=_( 'Average RGB color from camera \ is pushed to the stack'), value_block=True, prim_name='read_camera') self._parent.lc.def_prim('read_camera', 0, lambda self: primitive_dictionary['read_camera']()) media_palette.add_block('camera', hidden=True, style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) media_palette.add_block('camera1', hidden=True, style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) NO_IMPORT.append('camera') BLOCKS_WITH_SKIN.append('camera') NO_IMPORT.append('camera1') BLOCKS_WITH_SKIN.append('camera1') MEDIA_SHAPES.append('camerasmall') MEDIA_SHAPES.append('cameraoff') MEDIA_SHAPES.append('camera1small') MEDIA_SHAPES.append('camera1off')
def setup(self): ''' Set up the palettes ''' sensors_palette = make_palette( 'sensor', colors=["#FF6060", "#A06060"], help_string=_('Palette of sensor blocks'), position=6) media_palette = make_palette('media', colors=["#A0FF00", "#80A000"], help_string=_('Palette of media objects'), position=7) # set up camera-specific blocks media_blocks_dictionary['camera'] = self.prim_take_picture0 media_blocks_dictionary['camera1'] = self.prim_take_picture1 SKIN_PATHS.append('plugins/camera_sensor/images') hidden = True second_cam = False if self._status: hidden = False if len(self.devices) > 1: second_cam = True sensors_palette.add_block( 'luminance', hidden=hidden, style='box-style', label=_('brightness'), help_string=_('light level detected by camera'), value_block=True, prim_name='luminance') self._parent.lc.def_prim( 'luminance', 0, Primitive(self.prim_read_camera, return_type=TYPE_NUMBER, kwarg_descs={'luminance_only': ConstantArg(True)}, call_afterwards=self.after_luminance)) media_palette.add_block('camera', hidden=hidden, style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) media_palette.add_block('camera1', hidden=not (second_cam), style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) # Depreciated block sensors_palette.add_block( 'read_camera', hidden=True, style='box-style', label=_('brightness'), help_string=_( 'Average RGB color from camera is pushed to the stack'), value_block=True, prim_name='read_camera') self._parent.lc.def_prim( 'read_camera', 0, Primitive(self.prim_read_camera, return_type=TYPE_NUMBER, kwarg_descs={'luminance_only': ConstantArg(False)})) NO_IMPORT.append('camera') BLOCKS_WITH_SKIN.append('camera') NO_IMPORT.append('camera1') BLOCKS_WITH_SKIN.append('camera1') MEDIA_SHAPES.append('camerasmall') MEDIA_SHAPES.append('cameraoff') MEDIA_SHAPES.append('camera1small') MEDIA_SHAPES.append('camera1off')
def setup(self): ''' Set up the palettes ''' sensors_palette = make_palette( 'sensor', colors=["#FF6060", "#A06060"], help_string=_('Palette of sensor blocks'), position=6) media_palette = make_palette('media', colors=["#A0FF00", "#80A000"], help_string=_('Palette of media objects'), position=7) # set up camera-specific blocks primitive_dictionary['read_camera'] = self.prim_read_camera media_blocks_dictionary['camera'] = self.prim_take_picture0 media_blocks_dictionary['camera1'] = self.prim_take_picture1 SKIN_PATHS.append('plugins/camera_sensor/images') if self._status: sensors_palette.add_block( 'luminance', style='box-style', label=_('brightness'), help_string=_('light level detected by camera'), value_block=True, prim_name='luminance') self._parent.lc.def_prim( 'luminance', 0, lambda self: primitive_dictionary['read_camera'] (luminance_only=True)) # Depreciated block sensors_palette.add_block( 'read_camera', hidden=True, style='box-style', label=_('brightness'), help_string=_('Average RGB color from camera \ is pushed to the stack'), value_block=True, prim_name='read_camera') self._parent.lc.def_prim( 'read_camera', 0, lambda self: primitive_dictionary['read_camera']()) media_palette.add_block('camera', style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) if len(self.devices) > 1: media_palette.add_block('camera1', style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) else: media_palette.add_block('camera1', hidden=True, style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) else: # No camera, so blocks should do nothing sensors_palette.add_block('luminance', hidden=True, style='box-style', label=_('brightness'), help_string=\ _('light level detected by camera'), value_block=True, prim_name='read_camera') self._parent.lc.def_prim( 'luminance', 0, lambda self: primitive_dictionary['read_camera'] (luminance_only=True)) # Depreciated block sensors_palette.add_block( 'read_camera', hidden=True, style='box-style', label=_('brightness'), help_string=_('Average RGB color from camera \ is pushed to the stack'), value_block=True, prim_name='read_camera') self._parent.lc.def_prim( 'read_camera', 0, lambda self: primitive_dictionary['read_camera']()) media_palette.add_block('camera', hidden=True, style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) media_palette.add_block('camera1', hidden=True, style='box-style-media', label=' ', default='CAMERA', help_string=_('camera output'), content_block=True) NO_IMPORT.append('camera') BLOCKS_WITH_SKIN.append('camera') NO_IMPORT.append('camera1') BLOCKS_WITH_SKIN.append('camera1') MEDIA_SHAPES.append('camerasmall') MEDIA_SHAPES.append('cameraoff') MEDIA_SHAPES.append('camera1small') MEDIA_SHAPES.append('camera1off')