pythonenthoughtchaco

Chaco: 2 tools write the same metadata key


I have this problem with chaco.

In the plot, I need select some points (are points that I generate). This points, I can select with two tools: RangenSelection and ScatterInspector. If I work with only one tool, the code work well and I can detect with points I select, but when I work with both tools, both tools write the same metadata name: selections. This is the most important part of the code:

#this are all the tools.append
my_plot.tools.append(ScatterInspector(my_plot, selection_mode="toggle", persistent_hover=False))
my_plot.overlays.append(
        ScatterInspectorOverlay(my_plot,
            hover_color = "transparent",
            hover_marker_size = 10,
            hover_outline_color = "purple",
            hover_line_width = 2,
            selection_marker_size = 8,
            selection_color = "red")
        )

my_plot.tools.append(RangeSelection(my_plot, left_button_selects = False, rigth_button_selects = True, auto_handle_event = False))
my_plot.overlays.append(RangeSelectionOverlay(component=my_plot)) 

my_plot.tools.append(PanTool(my_plot))
my_plot.overlays.append(ZoomTool(my_plot, drag_button="right"))

return plot

#the rest of the code

def _metadata_handler(self):
    sel_indices = self.index_datasource.metadata.get('selections', [])
    su = self.index_datasource.metadata.get('annotations', [])
    print su
    print "Selection indices:", sel_indices

def _plot_default(self):
    plot = _create_plot_component()

    # Retrieve the plot hooked to the tool.
    my_plot = plot.plots["my_plot"][0]

    # Set up the trait handler for the selection
    self.index_datasource = my_plot.index
    self.index_datasource.on_trait_change(self._metadata_handler,
                                          "metadata_changed")

    return plot

When I run the code, and see what are in annotations, is always empty. But in selections the code write with both tools and this give an error. How can I tell to some tool in where metadata key write??

Thanks for your help.


Solution

  • The solution is put metadata_name="annotations" in RangeSelection and in RangeSelectionOverlay