diff --git a/brainglobe_utils/qtpy/logo.py b/brainglobe_utils/qtpy/logo.py index 78d9d75..3078fde 100644 --- a/brainglobe_utils/qtpy/logo.py +++ b/brainglobe_utils/qtpy/logo.py @@ -1,4 +1,5 @@ from importlib.resources import files +from typing import Optional from qtpy.QtWidgets import QGroupBox, QHBoxLayout, QLabel, QWidget @@ -6,23 +7,56 @@ def _docs_links_widget( package_name: str, package_tagline: str, - tutorial_file_name: str, - parent: QWidget = None, + tutorial_file_name: Optional[str] = None, + documentation_path: Optional[str] = None, + citation_doi: Optional[str] = None, + github_repo_name: Optional[str] = None, + help_text: Optional[str] = None, + parent: Optional[QWidget] = None, ): - _docs_links_html = f""" -

-

{package_tagline}

-

Website

-

Tutorial

-

Source

-

- """ # noqa: E501 - docs_links_widget = QLabel(_docs_links_html, parent=parent) + lines = [ + "

", + f"

{package_tagline}

", + "

" + "Website

", + ] + + if tutorial_file_name: + lines.append( + f"

" + f"Tutorial

" + ) + + if documentation_path: + lines.append( + f"

Documentation

" + ) + + if github_repo_name is None: + github_repo_name = package_name + lines.append( + f"

Source

" + ) + + if citation_doi: + lines.append( + f"

Citation

" + ) + + if help_text: + lines.append(f"

{help_text}

") + + lines.append("

") + docs_links_widget = QLabel("\n".join(lines), parent=parent) docs_links_widget.setOpenExternalLinks(True) return docs_links_widget -def _logo_widget(package_name: str, parent: QWidget = None): +def _logo_widget(package_name: str, parent: Optional[QWidget] = None): brainglobe_logo = files("brainglobe_utils").joinpath("qtpy/brainglobe.png") _logo_html = f""" @@ -38,9 +72,13 @@ def _logo_widget(package_name: str, parent: QWidget = None): def header_widget( package_name: str, package_tagline: str, - tutorial_file_name: str, - parent: QWidget = None, -): + tutorial_file_name: Optional[str] = None, + documentation_path: Optional[str] = None, + citation_doi: Optional[str] = None, + github_repo_name: Optional[str] = None, + help_text: Optional[str] = None, + parent: Optional[QWidget] = None, +) -> QGroupBox: """ Render HTML in a QGroupBox with a BrainGlobe logo and links to the docs and source code. @@ -51,10 +89,23 @@ def header_widget( The name of the package, e.g. "brainrender-napari" package_tagline : str The tagline for the package - tutorial_file_name : str + tutorial_file_name : str, optional The name of the tutorial file (must include .html), - e.g. "brainrender-qtpy.html": str - parent : QWidget + e.g. "brainrender-qtpy.html" + documentation_path : str, optional + Path of documentation file relative to + https://brainglobe.info/documentation/ (must include .html), + e.g. "cellfinder/user-guide/napari-plugin/index.html" + citation_doi : str, optional + Doi of citation e.g. "https://doi.org/10.1371/journal.pcbi.1009074" + github_repo_name : str, optional + Name of github repository inside the BrainGlobe organisation + (https://github.com/brainglobe). Only necessary if the github + repository name isn't the same as the package name. + help_text : str, optional + Help text to display at the bottom or the header e.g. + "For help, hover the cursor over each parameter." + parent : QWidget, optional The parent widget, defaults to None Returns @@ -69,7 +120,14 @@ def header_widget( box.layout().addWidget(_logo_widget(package_name, parent=box)) box.layout().addWidget( _docs_links_widget( - package_name, package_tagline, tutorial_file_name, parent=box + package_name, + package_tagline, + tutorial_file_name, + documentation_path, + citation_doi, + github_repo_name, + help_text, + parent=box, ) ) diff --git a/tests/tests/test_qtpy/test_logo.py b/tests/tests/test_qtpy/test_logo.py index e1134be..0e7eb88 100644 --- a/tests/tests/test_qtpy/test_logo.py +++ b/tests/tests/test_qtpy/test_logo.py @@ -4,16 +4,29 @@ def test_logo(qtbot): package_name = "test" package_tagline = "Tagline" - package_tutorial = "test.html" + tutorial_file_name = "test-tutorial.html" + documentation_path = "test-docs/test.html" + citation_doi = "https://doi.org/test" + help_text = "For help, hover the cursor over each parameter." - header = header_widget(package_name, package_tagline, package_tutorial) + header = header_widget( + package_name, + package_tagline, + tutorial_file_name=tutorial_file_name, + documentation_path=documentation_path, + citation_doi=citation_doi, + help_text=help_text, + ) qtbot.addWidget(header) expected_strings_logo = [package_name, "brainglobe.png"] expected_strings_docs = [ package_tagline, - package_tutorial, + tutorial_file_name, + documentation_path, + citation_doi, + help_text, "https://brainglobe.info", "https://github.com", ]