Skip to content

Setting defaults for glue state classes #3629

@astrofrog

Description

@astrofrog

In glue-viz/glue#2544 I added the ability in glue to define a function that can be used to set initial values for different callback properties on state classes before any callbacks are set up. For example, one can do:

from glue.core import Subset
from glue.core.state_objects import set_state_default_picker
from glue.viewers.profile.state import ProfileLayerState

def default_picker(state):
    if isinstance(state, ProfileLayerState):
        if isinstance(state.layer, Subset):
            state.linewidth = 3
        else:
            state.linewidth = 1
        state.as_steps = False

set_state_default_picker(default_picker)

Most values on the state will be set to their default values at this point except layer which should be populated already, allowing one to know if it is a data or subset layer and acting accordingly. This can also be used e.g. to hide all layers by default before they are ever shown.

The benefit of using this is to avoid triggering lots of callbacks by e.g. changing linewidth after all the callbacks are set since it will lead to unnecessary UI updates. With the approach above, the default values can be set before the layer is ever shown.

I haven't made any changes in jdaviz but I think there are several places that could benefit from this. If people are interested in experimenting with this, feel free to report back any issues here! If it seems it could help, I can trigger a glue-core release.

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