Source code for glue.viewers.common.tool

# The classes in this file define toolbar tools. Mouse modes specifically
# are defined in mouse_modes.py

from __future__ import absolute_import, division, print_function

from glue.core.callback_property import CallbackProperty

__all__ = ['Tool', 'CheckableTool', 'DropdownTool', 'SimpleToolMenu']


[docs]class Tool(object): """ The base class for all toolbar tools. All tools have the following attributes: * icon : QIcon object * tool_id : a short name for the tool * action_text : the action title (used if the tool is made available in a menu) * tool_tip : a tip that is shown when the user hovers over the icon * status_tip : a tip that is shown in the status bar when the tool is active * shortcut : keyboard shortcut to toggle the tool """ enabled = CallbackProperty(True) icon = None tool_id = None action_text = None tool_tip = None status_tip = None shortcut = None def __init__(self, viewer=None): self.viewer = viewer if hasattr(self.viewer, 'window_closed'): self.viewer.window_closed.connect(self._do_close)
[docs] def activate(self): """ Fired when the toolbar button is activated """ pass
[docs] def menu_actions(self): """ List of QtWidgets.QActions to be attached to this tool as a context menu. """ return []
def _do_close(self, *args): # We do this so that tools can override close self.close()
[docs] def close(self): if hasattr(self.viewer, 'window_closed'): self.viewer.window_closed.disconnect(self._do_close) self.viewer = None
[docs]class CheckableTool(Tool): """ A tool that is checkable. When checked, the ``activate`` method is executed, and when unchecked, the ``deactivate`` method is executed. """
[docs] def activate(self): """ Fired when the toolbar button is activated """ pass
[docs] def deactivate(self): """ Fired when the toolbar button is deactivated """ pass
[docs]class SimpleToolMenu(DropdownTool): """ A base class for tools that have no action it themselves but show a dropdown of other tools. """ pass