Ejemplo n.º 1
0
    def __init__(self, viewer_state=None, **kwargs):

        super(MatplotlibLayerState, self).__init__(viewer_state=viewer_state, **kwargs)

        self.color = self.layer.style.color
        self.alpha = self.layer.style.alpha

        self._sync_color = keep_in_sync(self, 'color', self.layer.style, 'color')
        self._sync_alpha = keep_in_sync(self, 'alpha', self.layer.style, 'alpha')

        self.add_global_callback(self._notify_layer_update)
Ejemplo n.º 2
0
    def __init__(self, layer=None, **kwargs):

        self._sync_markersize = None

        super(WWTTableLayerState, self).__init__(layer=layer)

        self._sync_color = keep_in_sync(self, 'color', self.layer.style, 'color')
        self._sync_alpha = keep_in_sync(self, 'alpha', self.layer.style, 'alpha')
        self._sync_size = keep_in_sync(self, 'size', self.layer.style, 'markersize')

        self.color = self.layer.style.color
        self.size = self.layer.style.markersize
        self.alpha = self.layer.style.alpha

        self.size_att_helper = ComponentIDComboHelper(self, 'size_att',
                                                      numeric=True,
                                                      categorical=False)
        self.cmap_att_helper = ComponentIDComboHelper(self, 'cmap_att',
                                                      numeric=True,
                                                      categorical=False)
        self.img_data_att_helper = ComponentIDComboHelper(self, 'img_data_att',
                                                          numeric=True,
                                                          categorical=False)

        self.size_lim_helper = StateAttributeLimitsHelper(self, attribute='size_att',
                                                          lower='size_vmin', upper='size_vmax',
                                                          cache=self.size_limits_cache)

        self.cmap_lim_helper = StateAttributeLimitsHelper(self, attribute='cmap_att',
                                                          lower='cmap_vmin', upper='cmap_vmax',
                                                          cache=self.cmap_limits_cache)

        self.add_callback('layer', self._on_layer_change)
        if layer is not None:
            self._on_layer_change()

        self.cmap = colormaps.members[0][1]

        # Color and size encoding depending on attributes is only available
        # in PyWWT 0.6 or later.
        if PYWWT_LT_06:
            modes = ['Fixed']
        else:
            modes = ['Fixed', 'Linear']

        WWTTableLayerState.color_mode.set_choices(self, modes)
        WWTTableLayerState.size_mode.set_choices(self, modes)

        self.update_from_dict(kwargs)
Ejemplo n.º 3
0
    def _layer_changed(self):

        if self._sync_color is not None:
            self._sync_color.stop_syncing()

        if self._sync_alpha is not None:
            self._sync_alpha.stop_syncing()

        if self.layer is not None:

            self.color = self.layer.style.color
            self.alpha = self.layer.style.alpha

            self._sync_color = keep_in_sync(self, 'color', self.layer.style, 'color')
            self._sync_alpha = keep_in_sync(self, 'alpha', self.layer.style, 'alpha')
Ejemplo n.º 4
0
def test_keep_in_sync():
    class State1(object):
        a = CallbackProperty()
        b = CallbackProperty()

    class State2(object):
        c = CallbackProperty()

    state1 = State1()
    state2 = State2()

    state1_control = State1()
    state2_control = State2()

    s1 = keep_in_sync(state1, 'a', state1, 'b')
    s2 = keep_in_sync(state1, 'a', state2, 'c')

    state1.a = 1
    assert state1.b == 1
    assert state1_control.b is None
    assert state2.c == 1
    assert state2_control.c is None

    state1.b = 3
    assert state1.a == 3
    assert state1_control.a is None
    assert state2.c == 3
    assert state2_control.c is None

    state2.c = 5
    assert state1.a == 5
    assert state1_control.a is None
    assert state1.b == 5
    assert state1_control.b is None

    s1.disable_syncing()

    state1.a = 7
    assert state1.b == 5
    assert state1_control.b is None
    assert state2.c == 7
    assert state2_control.c is None

    s2.disable_syncing()
Ejemplo n.º 5
0
def test_keep_in_sync():

    class State1(object):
        a = CallbackProperty()
        b = CallbackProperty()

    class State2(object):
        c = CallbackProperty()

    state1 = State1()
    state2 = State2()

    state1_control = State1()
    state2_control = State2()

    s1 = keep_in_sync(state1, 'a', state1, 'b')
    s2 = keep_in_sync(state1, 'a', state2, 'c')

    state1.a = 1
    assert state1.b == 1
    assert state1_control.b is None
    assert state2.c == 1
    assert state2_control.c is None

    state1.b = 3
    assert state1.a == 3
    assert state1_control.a is None
    assert state2.c == 3
    assert state2_control.c is None

    state2.c = 5
    assert state1.a == 5
    assert state1_control.a is None
    assert state1.b == 5
    assert state1_control.b is None

    s1.disable_syncing()

    state1.a = 7
    assert state1.b == 5
    assert state1_control.b is None
    assert state2.c == 7
    assert state2_control.c is None
Ejemplo n.º 6
0
    def _layer_changed(self):

        super(WWTTableLayerState, self)._layer_changed()

        if self._sync_markersize is not None:
            self._sync_markersize.stop_syncing()

        if self.layer is not None:
            self.size = self.layer.style.markersize
            self._sync_markersize = keep_in_sync(self, 'size', self.layer.style, 'markersize')
Ejemplo n.º 7
0
    def __init__(self, layer=None, **kwargs):
        super(WWTImageLayerState, self).__init__(layer=layer)

        self._sync_color = keep_in_sync(self, 'color', self.layer.style,
                                        'color')
        self._sync_alpha = keep_in_sync(self, 'alpha', self.layer.style,
                                        'alpha')

        self.color = self.layer.style.color

        self.img_data_att_helper = ComponentIDComboHelper(self,
                                                          'img_data_att',
                                                          numeric=True,
                                                          categorical=False)

        self.add_callback('layer', self._on_layer_change)
        if layer is not None:
            self._on_layer_change()

        self.update_from_dict(kwargs)
Ejemplo n.º 8
0
    def __init__(self, viewer_state, layer_state=None, layer=None):

        super(LayerArtist, self).__init__(layer)

        self._viewer_state = viewer_state

        self.layer = layer or layer_state.layer
        self.state = layer_state or self._layer_state_cls(
            viewer_state=viewer_state, layer=self.layer)

        if self.state not in self._viewer_state.layers:
            self._viewer_state.layers.append(self.state)

        self.zorder = self.state.zorder
        self.visible = self.state.visible

        self._sync_zorder = keep_in_sync(self, 'zorder', self.state, 'zorder')
        self._sync_visible = keep_in_sync(self, 'visible', self.state,
                                          'visible')

        self.state.add_callback('visible', self._on_visibility_change)

        self._reset_cache()
Ejemplo n.º 9
0
    def __init__(self, viewer_state=None, layer=None, **kwargs):

        super(ScatterLayerState, self).__init__(viewer_state=viewer_state,
                                                layer=layer)

        self.limits_cache = {}

        self.cmap_lim_helper = StateAttributeLimitsHelper(
            self,
            attribute='cmap_att',
            lower='cmap_vmin',
            upper='cmap_vmax',
            limits_cache=self.limits_cache)

        self.size_lim_helper = StateAttributeLimitsHelper(
            self,
            attribute='size_att',
            lower='size_vmin',
            upper='size_vmax',
            limits_cache=self.limits_cache)

        self.cmap_att_helper = ComponentIDComboHelper(self,
                                                      'cmap_att',
                                                      numeric=True,
                                                      datetime=False,
                                                      categorical=False)

        self.size_att_helper = ComponentIDComboHelper(self,
                                                      'size_att',
                                                      numeric=True,
                                                      datetime=False,
                                                      categorical=False)

        self.xerr_att_helper = ComponentIDComboHelper(self,
                                                      'xerr_att',
                                                      numeric=True,
                                                      datetime=False,
                                                      categorical=False)

        self.yerr_att_helper = ComponentIDComboHelper(self,
                                                      'yerr_att',
                                                      numeric=True,
                                                      datetime=False,
                                                      categorical=False)

        self.vx_att_helper = ComponentIDComboHelper(self,
                                                    'vx_att',
                                                    numeric=True,
                                                    datetime=False,
                                                    categorical=False)

        self.vy_att_helper = ComponentIDComboHelper(self,
                                                    'vy_att',
                                                    numeric=True,
                                                    datetime=False,
                                                    categorical=False)

        self.points_mode_helper = ComboHelper(self, 'points_mode')

        points_mode_display = {
            'auto': 'Density map or markers (auto)',
            'markers': 'Markers',
            'density': 'Density map'
        }

        ScatterLayerState.points_mode.set_choices(
            self, ['auto', 'markers', 'density'])
        ScatterLayerState.points_mode.set_display_func(self,
                                                       points_mode_display.get)

        self.add_callback('points_mode', self._update_density_map_mode)
        self.add_callback('density_map',
                          self._on_density_map_change,
                          priority=10000)

        ScatterLayerState.cmap_mode.set_choices(self, ['Fixed', 'Linear'])
        ScatterLayerState.size_mode.set_choices(self, ['Fixed', 'Linear'])

        linestyle_display = {
            'solid': '–––––––',
            'dashed': '– – – – –',
            'dotted': '· · · · · · · ·',
            'dashdot': '– · – · – ·'
        }

        ScatterLayerState.linestyle.set_choices(
            self, ['solid', 'dashed', 'dotted', 'dashdot'])
        ScatterLayerState.linestyle.set_display_func(self,
                                                     linestyle_display.get)

        ScatterLayerState.vector_mode.set_choices(self, ['Cartesian', 'Polar'])

        vector_origin_display = {
            'tail': 'Tail of vector',
            'middle': 'Middle of vector',
            'tip': 'Tip of vector'
        }

        ScatterLayerState.vector_origin.set_choices(self,
                                                    ['tail', 'middle', 'tip'])
        ScatterLayerState.vector_origin.set_display_func(
            self, vector_origin_display.get)

        stretch_display = {
            'linear': 'Linear',
            'sqrt': 'Square Root',
            'arcsinh': 'Arcsinh',
            'log': 'Logarithmic'
        }

        ScatterLayerState.stretch.set_choices(
            self, ['linear', 'sqrt', 'arcsinh', 'log'])
        ScatterLayerState.stretch.set_display_func(self, stretch_display.get)

        if self.viewer_state is not None:
            self.viewer_state.add_callback('x_att',
                                           self._on_xy_change,
                                           priority=10000)
            self.viewer_state.add_callback('y_att',
                                           self._on_xy_change,
                                           priority=10000)
            if hasattr(self.viewer_state, 'plot_mode'):
                self.viewer_state.add_callback('plot_mode',
                                               self._update_points_mode,
                                               priority=10000)
            self._on_xy_change()
            self._update_points_mode()

        self.add_callback('layer', self._on_layer_change)
        if layer is not None:
            self._on_layer_change()

        self.cmap = colormaps.members[0][1]

        self.size = self.layer.style.markersize

        self._sync_size = keep_in_sync(self, 'size', self.layer.style,
                                       'markersize')

        self.update_from_dict(kwargs)
Ejemplo n.º 10
0
 def __init__(self, viewer_state=None, **kwargs):
     super(DendrogramLayerState, self).__init__(viewer_state=viewer_state,
                                                **kwargs)
     self.linewidth = self.layer.style.linewidth
     self._sync_linewidth = keep_in_sync(self, 'linewidth',
                                         self.layer.style, 'linewidth')