Skip to content

How can I customize plot tools? #61

@alimuldal

Description

@alimuldal

I'm working on an ROI picker using guiqwt as a backend. One of the things I'd like to be able to do is to customize the attributes of the shapes that are generated using guiqwt.tools. Initially I'd just like to be able to (programatically) change their style (color, marker style etc.), but I'm having quite a lot of trouble figuring out how to do this.

For example, suppose I want to change the shape of the markers generated by guidata.tools.PointTool from crosses to circles. The PointTool constructor accepts a shape_style= parameter which looks promising, but I can't find any documentation explaining what this or what it does.

PointTool inherits from RectangularShapeTool, which inherits from RectangularActionTool. RectangularActionTool contains these lines which look quite relevant:

    def __init__(self, manager, func, shape_style=None,
                 toolbar_id=DefaultToolbarID, title=None, icon=None, tip=None,
                 fix_orientation=False, switch_to_default_tool=None):
        # ...
        if shape_style is not None:
            self.shape_style_sect = shape_style[0]
            self.shape_style_key = shape_style[1]
        else:
            self.shape_style_sect = self.SHAPE_STYLE_SECT
            self.shape_style_key = self.SHAPE_STYLE_KEY
        # ...
    def set_shape_style(self, shape):
        shape.set_style(self.shape_style_sect, self.shape_style_key)

PointTool.SHAPE_STYLE_SECT == 'plot' and PointTool.SHAPE_STYLE_KEY == 'shape/point', but it's unclear what these correspond to. Naturally, I tried looking at the set_style method of PointShape (ultimately inherited from PolygonShape):

    def set_style(self, section, option):
        self.shapeparam.read_config(CONF, section, option)
        self.shapeparam.update_shape(self)

shapeparam is a guiqwt.shape.ShapeParam, which inherits its read_config method from guidata.dataset.datatypes.DataSet:

    def read_config(self, conf, section, option):
        from guidata.userconfigio import UserConfigReader 
        reader = UserConfigReader(conf, section, option)
        self.deserialize(reader)

CONF is guiqwt.config.CONF, which is a guidata.userconfig.UserConfig. It seems to be a dict-like object that holds configuration parameters for various GUI objects, but it's still far from obvious what the keys and values mean.

The information I'm looking for (just how to change the shape of a plot marker!) is hidden behind about 5 or 6 layers of abstraction - it seems like I would need to have fairly deep knowledge of the inner workings of guiqwt and guidata in order to achieve something that ought to be fairly simple. It would be very helpful if the relevant class methods had more descriptive docstrings, and ideally if there was a working example in the documentation showing how to customize plot tools.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions