Source code for spacr.qt.widgets.info_link
"""Compact teal documentation dot used for spaCR API links."""
from __future__ import annotations
from PySide6.QtCore import QUrl
from PySide6.QtGui import QDesktopServices
from .dot_link import DotLink
[docs]
class InfoLink(DotLink):
"""A small teal dot that opens an API-reference URL when pressed.
:param url: the page to open in the browser.
:param tooltip: hover text, also the accessible name.
:param parent: parent widget.
The colours and the accessible description are fixed here rather than
passed: every one of these dots means the same thing, and a caller
choosing its own would make them stop reading as one control.
"""
def __init__(
self,
url: str,
*,
tooltip: str = "Open API reference",
parent=None,
):
"""Build the teal dot that opens a documentation page.
:param url: the page to open.
:param tooltip: hover text.
:param parent: parent widget, or ``None``.
"""
super().__init__(
tooltip=tooltip,
colours=("#20B8B0", "#48D8D0", "#118D88", "#6A8F8D"),
accessible_description=(
"Opens the relevant spaCR API reference in a web browser."
),
parent=parent,
)
self._url = str(url)
self.setObjectName("InfoLink")
self.clicked.connect(self.open_documentation)
[docs]
def url(self) -> str:
"""Return the documentation URL opened by this button."""
return self._url
[docs]
def set_url(self, url: str) -> None:
"""Change the destination without rebuilding the compact link.
:param url: the address opened in the desktop browser on click;
converted with ``str``.
"""
self._url = str(url)
[docs]
def open_documentation(self) -> None:
"""Open the configured documentation page in the system browser."""
QDesktopServices.openUrl(QUrl(self._url))