Example #1
0
    def __init__(self,
                 label: str,
                 data: Iterable,
                 *,
                 axis: YAxis = Plot.yaxis,
                 **config: Any):
        self.axis = axis
        self._name_id = label + '##' + _generate_id(self)
        self._data = []
        self._config = {}

        ## create data fields from record type
        for index, name in enumerate(self._get_data_keywords()):
            self._data.append([])
            field = DataSeriesCollection(self, index)
            setattr(self, f'_{name}_accessor', field)

        ## non-data config properties
        props = self._get_config_properties()
        for prop_name, value in config.items():
            prop = props.get(prop_name)
            if prop is None:
                raise AttributeError(f"no config property named '{prop_name}'")
            prop.__set__(self, value)

        self.extend(data)
Example #2
0
    def __init__(self, *, name_id: Optional[str] = None, **kwargs: Any):
        if name_id is not None:
            self._name_id = name_id
        else:
            self._name_id = _generate_id(self)

        if dpgcore.does_item_exist(self.id):
            self._setup_preexisting()
        else:
            # at no point should a Widget object exist for an item that hasn't
            # actually been added, so if the item doesn't exist we need to add it now.

            # labels are handled specially because they are very common
            if 'label' in kwargs and kwargs['label'] is None:
                kwargs['label'] = self.id

            # subclasses will pass both config values and keywords to _setup_add_widget()
            # separate them now
            config_props = self._get_config_properties()
            config_args = {}
            for name, value in list(kwargs.items()):
                prop = config_props.get(name)
                if prop is not None and not prop.no_init:
                    config_args[prop] = kwargs.pop(name)

            # just keywords left in kwargs
            self._setup_add_widget(kwargs)

            config_data = {}
            for prop, value in config_args.items():
                config_data.update(prop.fconfig(self, value))

            dpgcore.configure_item(self.id, **config_data)

        _register_item(self.id, self)
Example #3
0
    def __init__(self,
                 plot: Plot,
                 text: str,
                 pos: Tuple[float, float],
                 offset: Tuple[float, float],
                 *,
                 color: ColorRGBA = None,
                 clamped: bool = True):

        self._tag_id = _generate_id(self)
        self._plot = plot
        self._text = text
        self._pos = pos
        self._offset = offset
        self._color = color
        self._clamped = clamped
        self._create_annotation()
Example #4
0
    def __init__(self,
                 canvas: DrawingCanvas,
                 *args,
                 tag_id: str = None,
                 **kwargs: Any):
        self._canvas = canvas
        if tag_id is not None:
            self._tag_id = tag_id
        else:
            self._tag_id = _generate_id(self)

        props = self._get_draw_properties()
        draw_data = {}
        for prop, value in zip(props.values(), args):
            draw_data.update(prop.fconfig(self, value))

        for name, value in kwargs.items():
            prop = props.get(name)
            if prop is not None:
                draw_data.update(prop.fconfig(self, value))

        self._draw_internal(draw_data)