2013-07-28 28 views
0

我有chaco這個問題。Chaco:2個工具編寫相同的元數據密鑰

在圖中,我需要選擇一些點(我生成的點)。這一點,我可以選擇兩個工具:RangenSelection和ScatterInspector。如果我僅使用一種工具工作,則代碼運行良好,並且可以使用我選擇的點進行檢測,但是當我使用這兩種工具時,這兩種工具都會寫入相同的元數據名稱:selections。這是代碼的最重要的部分:

#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 

當我運行代碼,看看有什麼是annotations,始終是空的。但在selections代碼與這兩種工具編寫,這給了一個錯誤。 我如何告訴一些工具在哪裏元數據鍵寫?

感謝您的幫助。

回答

0

的溶液放入metadata_name="annotations"RangeSelectionRangeSelectionOverlay

相關問題