def create_toolbutton(parent, text=None, shortcut=None, icon=None, tip=None, toggled=None, triggered=None, autoraise=True, text_beside_icon=False, section=None, option=None, id_=None, plugin=None, context_name=None, register_toolbutton=False): """Create a QToolButton""" button = QToolButton(parent) if text is not None: button.setText(text) if icon is not None: if is_text_string(icon): icon = ima.get_icon(icon) button.setIcon(icon) if text is not None or tip is not None: button.setToolTip(text if tip is None else tip) if text_beside_icon: button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) button.setAutoRaise(autoraise) if triggered is not None: button.clicked.connect(triggered) if toggled is not None: setup_toggled_action(button, toggled, section, option) if shortcut is not None: button.setShortcut(shortcut) if id_ is not None: button.ID = id_ if register_toolbutton: TOOLBUTTON_REGISTRY.register_reference( button, id_, plugin, context_name) return button
def get_toolbutton(self, name: str, context: Optional[str] = None, plugin: Optional[str] = None) -> QToolButton: """ Return toolbutton by name, plugin and context. Parameters ---------- name: str Name of the toolbutton to retrieve. context: Optional[str] Widget or context identifier under which the toolbutton was stored. If None, then `CONTEXT_NAME` is used instead plugin: Optional[str] Name of the plugin where the toolbutton was defined. If None, then `PLUGIN_NAME` is used. Returns ------- toolbutton: QToolButton The corresponding toolbutton stored under the given `name`, `context` and `plugin`. Raises ------ KeyError If either of `name`, `context` or `plugin` keys do not exist in the toolbutton registry. """ plugin = self.PLUGIN_NAME if plugin is None else plugin context = self.CONTEXT_NAME if context is None else context return TOOLBUTTON_REGISTRY.get_reference(name, plugin, context)
def get_toolbuttons( self, context: Optional[str] = None, plugin: Optional[str] = None) -> Dict[str, QToolButton]: """ Return all toolbuttons defined by a context on a given plugin. Parameters ---------- context: Optional[str] Widget or context identifier under which the toolbuttons were stored. If None, then `CONTEXT_NAME` is used instead plugin: Optional[str] Name of the plugin where the toolbuttons were defined. If None, then `PLUGIN_NAME` is used. Returns ------- toolbuttons: Dict[str, QToolButton] A dictionary that maps string keys to their corresponding toolbuttons. """ plugin = self.PLUGIN_NAME if plugin is None else plugin context = self.CONTEXT_NAME if context is None else context return TOOLBUTTON_REGISTRY.get_references(plugin, context)