def initialize_toolbar(self): from glue.config import viewer_tool self.toolbar = self._toolbar_cls( self, default_mouse_mode_cls=self._default_mouse_mode_cls) # Need to include tools and subtools declared by parent classes unless # specified otherwise tool_ids, subtool_ids = get_viewer_tools(self.__class__) for tool_id in tool_ids: mode_cls = viewer_tool.members[tool_id] if tool_id in subtool_ids: subtools = [] for subtool_id in subtool_ids[tool_id]: subtools.append(viewer_tool.members[subtool_id](self)) mode = mode_cls(self, subtools=subtools) else: mode = mode_cls(self) self.toolbar.add_tool(mode) self.addToolBar(self.toolbar) self.toolbar_added.emit()
def test_get_viewer_tools(): class CustomViewer1(ViewerWithTools): pass tools, subtools = get_viewer_tools(CustomViewer1) assert tools == ['save'] assert subtools == {'save': []} class CustomViewer2(ViewerWithTools): tools = ['banana'] subtools = {'save': ['apple', 'pear']} tools, subtools = get_viewer_tools(CustomViewer2) assert tools == ['save', 'banana'] assert subtools == {'save': ['apple', 'pear']} CustomViewer2.inherit_tools = False tools, subtools = get_viewer_tools(CustomViewer2) assert tools == ['banana'] assert subtools == {'save': ['apple', 'pear']} class Mixin(object): pass class CustomViewer3(CustomViewer2, Mixin): tools = ['orange'] subtools = {'banana': ['one', 'two']} inherit_tools = True tools, subtools = get_viewer_tools(CustomViewer3) assert tools == ['banana', 'orange'] assert subtools == {'save': ['apple', 'pear'], 'banana': ['one', 'two']}
def initialize_toolbar(self): from glue.config import viewer_tool self.toolbar = BasicJupyterToolbar() # Need to include tools and subtools declared by parent classes unless # specified otherwise tool_ids, subtool_ids = get_viewer_tools(self.__class__) if subtool_ids: raise ValueError( 'subtools are not yet supported in Jupyter viewers') for tool_id in tool_ids: mode_cls = viewer_tool.members[tool_id] mode = mode_cls(self) self.toolbar.add_tool(mode)
def initialize_toolbar(self): from glue.config import viewer_tool self.toolbar = self._toolbar_cls(self, default_mouse_mode_cls=self._default_mouse_mode_cls) # Need to include tools and subtools declared by parent classes unless # specified otherwise tool_ids, subtool_ids = get_viewer_tools(self.__class__) for tool_id in tool_ids: mode_cls = viewer_tool.members[tool_id] if tool_id in subtool_ids: subtools = [] for subtool_id in subtool_ids[tool_id]: subtools.append(viewer_tool.members[subtool_id](self)) mode = mode_cls(self, subtools=subtools) else: mode = mode_cls(self) self.toolbar.add_tool(mode) self.addToolBar(self.toolbar) self.toolbar_added.emit()