Skip to content

Commit

Permalink
Version 1 of qtpy logo.py and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Nov 10, 2023
1 parent 5319e04 commit edfc529
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
File renamed without changes.
File renamed without changes
42 changes: 30 additions & 12 deletions brainglobe_utils/napari/logo.py → brainglobe_utils/qtpy/logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@


def _docs_links_widget(
package_name: str, tutorial_file_name: str, parent: QWidget = None
package_name: str,
package_tagline: str,
tutorial_file_name: str,
parent: QWidget = None,
):
_docs_links_html = f"""
<h3>
<p>2D Registration</p>
<p>{package_tagline}</p>
<p><a href="https://brainglobe.info" style="color:gray;">Website</a></p>
<p><a href="https://brainglobe.info/tutorials/{tutorial_file_name}" style="color:gray;">Tutorial</a></p>
<p><a href="https://github.com/brainglobe/{package_name}" style="color:gray;">Source</a></p>
Expand All @@ -20,39 +23,54 @@ def _docs_links_widget(


def _logo_widget(package_name: str, parent: QWidget = None):
brainglobe_logo = files("brainglobe.png")
brainglobe_logo = files("brainglobe_utils").joinpath("qtpy/brainglobe.png")

_logo_html = f"""
<h1>
<img src="{brainglobe_logo}"width="100">
<p>{package_name}</p>
<\h1>
"""
""" # noqa W605

return QLabel(_logo_html, parent=None)


def header_widget(
package_name: str, tutorial_file_name: str, parent: QWidget = None
package_name: str,
package_tagline: str,
tutorial_file_name: str,
parent: QWidget = None,
):
"""
Render HTML in a QGroupBox with a BrainGlobe logo and links to the docs
and source code.
Args:
package_name: The name of the package, e.g. "brainrender-napari"
tutorial_file_name: The name of the tutorial file
(must include .html), e.g. "brainrender-napari.html"
parent: The parent widget
Returns: A QGroupBox with the rendered HTML containing the logo and links
Parameters
----------
package_name : str
The name of the package, e.g. "brainrender-napari"
package_tagline : str
The tagline for the package
tutorial_file_name : str
The name of the tutorial file (must include .html),
e.g. "brainrender-qtpy.html": str
parent : QWidget
The parent widget, defaults to None
Returns
-------
QGroupBox
A QGroupBox with the rendered HTML containing the logo and links
"""

box = QGroupBox(parent)
box.setFlat(True)
box.setLayout(QHBoxLayout())
box.layout().addWidget(_logo_widget(package_name, parent=box))
box.layout().addWidget(
_docs_links_widget(package_name, tutorial_file_name, parent=box)
_docs_links_widget(
package_name, package_tagline, tutorial_file_name, parent=box
)
)

return box
Empty file.
29 changes: 29 additions & 0 deletions tests/tests/test_unit/test_qtpy/test_logo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from brainglobe_utils.qtpy.logo import header_widget


def test_logo(qtbot):
package_name = "test"
package_tagline = "Tagline"
package_tutorial = "test.html"

header = header_widget(package_name, package_tagline, package_tutorial)

qtbot.addWidget(header)

# header.window().show()

expected_strings_logo = [package_name, "brainglobe.png"]
expected_strings_docs = [
package_tagline,
package_tutorial,
"https://brainglobe.info",
"https://github.com",
]

assert header.layout().count() == 2

for logo_string in expected_strings_logo:
assert logo_string in header.layout().itemAt(0).widget().text()

for docs_string in expected_strings_docs:
assert docs_string in header.layout().itemAt(1).widget().text()

0 comments on commit edfc529

Please sign in to comment.