Skip to content

Commit

Permalink
Import from brainglobe-utils (#2)
Browse files Browse the repository at this point in the history
* Version 1 of qtpy logo.py and tests

* wip: chest and drawers classes draft

* CollapsibleWidget using superqt with tests

* Fixed ubuntu tests failing

* Fixed linting

* Address review comments

* Removed overloaded methods

* Delete unused code & add tests (#18)

* Simplify slurmio dependency

* Remove unused functions

* Add slurmio to dev dependencies

* Remove more unused code

* Add tests

* lint

* update dependencies

* Skip test on windows

* Add tests

* Collapsible Widget API v1.1 (#23)

* WIP collapsible widget API v.1.1

* Updated tests for new functionality

* Update brainglobe_utils/qtpy/collapsible_widget.py

Co-authored-by: Alessandro Felder <[email protected]>

* Made collapsible=True explicit

* Added test for removing widget not found in container

* Remove TODOs

---------

Co-authored-by: Alessandro Felder <[email protected]>

* Collapsible Widget API v1.1 (#23)

* WIP collapsible widget API v.1.1

* Updated tests for new functionality

* Update brainglobe_utils/qtpy/collapsible_widget.py

Co-authored-by: Alessandro Felder <[email protected]>

* Made collapsible=True explicit

* Added test for removing widget not found in container

* Remove TODOs

---------

Co-authored-by: Alessandro Felder <[email protected]>

* Move qtpy functionality from brainglobe-segmentation

* Move qtpy functionality from cellfinder

* Move qtpy functionality from cellfinder

* Merge imio in as `image_io` submodule (#33)

* Initial commit

* bump

* bump

* bump

* add bump2version

* Bump version: 0.0.2 → 0.0.3

* add pre commit hooks

* update testing

* reorder ci

* fix non-istropic loading error

* Bump version: 0.0.3 → 0.0.4

* Gh actions (#3)

* add gh actions

* Update testing

* update testing

* add lint

* coveralls

* coveralls

* deploy

* Bump version: 0.0.4 → 0.0.5

* update readme

* transfer to brainglobe

* run tests on PR

* update coverage

* support python 3.9

* Bump version: 0.0.5 → 0.0.6

* update bump2version

* Bump version: 0.0.6 → 0.1.0-rc0

* Bump version: 0.1.0-rc0 → 0.1.0

* Update setup.py

* add missing import

* Update README.md

* fix linting

* Exclude tests from packaged distributions (#6)

* Update pre commit

* reformat

* Python 3.10 compatibility

* Bump version: 0.1.0 → 0.2.0-rc0

* update GH actions

* Bump version: 0.2.0-rc0 → 0.2.0-rc1

* Bump version: 0.2.0-rc1 → 0.2.0

* Revert older changes

* Fix deprecation of tifffile.imsave replaced by tifffile.imwrite. (#8)

Co-authored-by: Jules Scholler <[email protected]>

* Bump version: 0.2.1 → 0.2.2-rc0

* Bump version: 0.2.2-rc0 → 0.2.2

* Add link to contributing guide

* Add tox and use brainglobe/actions (#10)

* Add tox and use brainglobe actions for testing

* Update pre-commit

* run pre-commit

* Update tox.ini

* Bump version: 0.2.2 → 0.2.3-rc0

* Bump version: 0.2.3-rc0 → 0.2.3

* Long description (#11)

* Add long description for PyPI

* Bump version: 0.2.3 → 0.2.4-rc0

* Bump version: 0.2.4-rc0 → 0.2.4

* Change coverage badge to codecov.

* Test on recent python versions (#13)

* Test on recent python versions

* Bump pre-commit versions

* Fix dtype issue

* Remove straggling mention of 3.7

* Replace brainglobe > NI actions (#14)

* Use standard pre-commit config  (#15)

* Add standard pre-commit config

* pre-commit fixes

* Use pyproject.toml (#16)

* Filter warnings in pytest (#17)

* Filter warnings in pytest

* Filter nptyping warnings

* Add all-contributors

* Update README.md

Co-authored-by: David Stansby <[email protected]>

* docs: add crousseau as a contributor for code, ideas, and test (#25)

* docs: update README.md [skip ci]

* docs: create .all-contributorsrc [skip ci]

* Remove badge

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Adam Tyson <[email protected]>

* Don't skip CI for all-contrbutors-bot

* Update .all-contributorsrc

* docs: add jaimergp as a contributor for code (#23)

* docs: update README.md [skip ci]

* docs: create .all-contributorsrc [skip ci]

* Update README.md

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Adam Tyson <[email protected]>

* docs: add JulesScholler as a contributor for code (#22)

* docs: update README.md [skip ci]

* docs: create .all-contributorsrc [skip ci]

* Update README.md

* Update .all-contributorsrc

* Update .all-contributorsrc

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Adam Tyson <[email protected]>

* docs: add dstansby as a contributor for test, code, and 3 more (#21)

* docs: update README.md [skip ci]

* docs: create .all-contributorsrc [skip ci]

* Update README.md

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Adam Tyson <[email protected]>

* docs: add adamltyson as a contributor for code, infra, and 2 more (#24)

* docs: update README.md [skip ci]

* docs: create .all-contributorsrc [skip ci]

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

* Update README.md

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Adam Tyson <[email protected]>

* Update doc links (#27)

* [pre-commit.ci] pre-commit autoupdate (#28)

updates:
- [github.com/charliermarsh/ruff-pre-commit: v0.0.240 → v0.0.272](astral-sh/ruff-pre-commit@v0.0.240...v0.0.272)
- [github.com/psf/black: 23.1.0 → 23.3.0](psf/black@23.1.0...23.3.0)
- [github.com/pre-commit/mirrors-mypy: v0.991 → v1.3.0](pre-commit/mirrors-mypy@v0.991...v1.3.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Update dependency (imlib -> brainglobe-utils) (#29)

* [pre-commit.ci] pre-commit autoupdate (#31)

updates:
- [github.com/charliermarsh/ruff-pre-commit: v0.0.272 → v0.0.275](astral-sh/ruff-pre-commit@v0.0.272...v0.0.275)
- [github.com/pre-commit/mirrors-mypy: v1.3.0 → v1.4.1](pre-commit/mirrors-mypy@v1.3.0...v1.4.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* remove all contributors (#32)

* [pre-commit.ci] pre-commit autoupdate (#33)

updates:
- https://github.com/charliermarsh/ruff-pre-commithttps://github.com/astral-sh/ruff-pre-commit
- [github.com/astral-sh/ruff-pre-commit: v0.0.275 → v0.0.276](astral-sh/ruff-pre-commit@v0.0.275...v0.0.276)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#34)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.276 → v0.0.277](astral-sh/ruff-pre-commit@v0.0.276...v0.0.277)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Update CI workflow to use NIU actions (#35)

* [pre-commit.ci] pre-commit autoupdate (#36)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.277 → v0.0.278](astral-sh/ruff-pre-commit@v0.0.277...v0.0.278)
- [github.com/psf/black: 23.3.0 → 23.7.0](psf/black@23.3.0...23.7.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#37)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.278 → v0.0.280](astral-sh/ruff-pre-commit@v0.0.278...v0.0.280)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#38)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.280 → v0.0.281](astral-sh/ruff-pre-commit@v0.0.280...v0.0.281)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#39)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.281 → v0.0.282](astral-sh/ruff-pre-commit@v0.0.281...v0.0.282)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#40)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.282 → v0.0.284](astral-sh/ruff-pre-commit@v0.0.282...v0.0.284)
- [github.com/pre-commit/mirrors-mypy: v1.4.1 → v1.5.0](pre-commit/mirrors-mypy@v1.4.1...v1.5.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#41)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.284 → v0.0.285](astral-sh/ruff-pre-commit@v0.0.284...v0.0.285)
- [github.com/pre-commit/mirrors-mypy: v1.5.0 → v1.5.1](pre-commit/mirrors-mypy@v1.5.0...v1.5.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#42)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.285 → v0.0.286](astral-sh/ruff-pre-commit@v0.0.285...v0.0.286)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Set pre-commit autoupdate frequency to monthly (#43)

* [pre-commit.ci] pre-commit autoupdate (#44)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.286 → v0.0.287](astral-sh/ruff-pre-commit@v0.0.286...v0.0.287)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#45)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.287 → v0.0.292](astral-sh/ruff-pre-commit@v0.0.287...v0.0.292)
- [github.com/psf/black: 23.7.0 → 23.9.1](psf/black@23.7.0...23.9.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#48)

updates:
- [github.com/pre-commit/pre-commit-hooks: v4.4.0 → v4.5.0](pre-commit/pre-commit-hooks@v4.4.0...v4.5.0)
- [github.com/astral-sh/ruff-pre-commit: v0.0.292 → v0.1.4](astral-sh/ruff-pre-commit@v0.0.292...v0.1.4)
- [github.com/psf/black: 23.9.1 → 23.10.1](psf/black@23.9.1...23.10.1)
- [github.com/pre-commit/mirrors-mypy: v1.5.1 → v1.6.1](pre-commit/mirrors-mypy@v1.5.1...v1.6.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#49)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.1.4 → v0.1.6](astral-sh/ruff-pre-commit@v0.1.4...v0.1.6)
- [github.com/psf/black: 23.10.1 → 23.11.0](psf/black@23.10.1...23.11.0)
- [github.com/pre-commit/mirrors-mypy: v1.6.1 → v1.7.1](pre-commit/mirrors-mypy@v1.6.1...v1.7.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [pre-commit.ci] pre-commit autoupdate (#50)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.1.6 → v0.1.9](astral-sh/ruff-pre-commit@v0.1.6...v0.1.9)
- [github.com/psf/black: 23.11.0 → 23.12.1](psf/black@23.11.0...23.12.1)
- [github.com/pre-commit/mirrors-mypy: v1.7.1 → v1.8.0](pre-commit/mirrors-mypy@v1.7.1...v1.8.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Update GH actions badge (#51)

* Update test_and_deploy.yml (#52)

See neuroinformatics-unit/movement#108

Co-authored-by: Igor Tatarnikov <[email protected]>

* Add manifest (#54)

* Update CI workflows with manifest

* Allow workflow to be dispatchable

* Add pyarrow dependency to prevent future pandas failures

* [pre-commit.ci] pre-commit autoupdate (#53)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.1.9 → v0.2.0](astral-sh/ruff-pre-commit@v0.1.9...v0.2.0)
- [github.com/psf/black: 23.12.1 → 24.1.1](psf/black@23.12.1...24.1.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* refactor image_io as submodule

* Deprecated alias warning is still present

* Fix an actual circular import because of wildcard import

* Fix buggy html logo - wrong escape backslash

---------

Co-authored-by: crousseau <[email protected]>
Co-authored-by: Adam Tyson <[email protected]>
Co-authored-by: Adam Tyson <[email protected]>
Co-authored-by: Jaime Rodríguez-Guerra <[email protected]>
Co-authored-by: Jules Scholler <[email protected]>
Co-authored-by: Jules Scholler <[email protected]>
Co-authored-by: David Stansby <[email protected]>
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alessandro Felder <[email protected]>
Co-authored-by: Igor Tatarnikov <[email protected]>

* expand interaction.py type hints, docstrings and tests

* expand interaction.py type hints, docstrings and tests

* add further tests for interaction.py

* add further tests for interaction.py

* add test for dialog.py

* add test for dialog.py

* expand docstrings for interaction tests

* Expand header_widget to include doc path, citation and help text (#70)

* expand header_widget to include doc path, citation and help text

* update docstrings for headers

* Expand header_widget to include doc path, citation and help text (#70)

* expand header_widget to include doc path, citation and help text

* update docstrings for headers

* Changed collapsed icon to ▶

* Expose the expanded icon in the constructor as well

* Add transform widget (#88)

* Add transform widget

* Improve testing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update widget name and citation

* Add docstrings and typing

* remove ref to tooltips

* Add napari trove classifier

* Update widget name

* Remove unnecessary 1 line functions

* Remove parameter default

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Add transform widget (#88)

* Add transform widget

* Improve testing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update widget name and citation

* Add docstrings and typing

* remove ref to tooltips

* Add napari trove classifier

* Update widget name

* Remove unnecessary 1 line functions

* Remove parameter default

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Remove BrainGlobe specific code & logo

* Reorganise tests

* Move code

* Update imports

* Remove logo tests

* Typo fix

---------

Co-authored-by: IgorTatarnikov <[email protected]>
Co-authored-by: Igor Tatarnikov <[email protected]>
Co-authored-by: Alessandro Felder <[email protected]>
Co-authored-by: Will Graham <[email protected]>
Co-authored-by: crousseau <[email protected]>
Co-authored-by: Jaime Rodríguez-Guerra <[email protected]>
Co-authored-by: Jules Scholler <[email protected]>
Co-authored-by: Jules Scholler <[email protected]>
Co-authored-by: David Stansby <[email protected]>
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Kimberly Meechan <[email protected]>
Co-authored-by: Kimberly Meechan <[email protected]>
  • Loading branch information
14 people authored Feb 24, 2025
1 parent e162752 commit 8e2b812
Show file tree
Hide file tree
Showing 12 changed files with 1,006 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "qt-niu"
authors = [{name = "Adam Tyson", email= "[email protected]"}]
description = "Reuseable Qt elements"
description = "Reusable Qt elements"
readme = "README.md"
requires-python = ">=3.9.0"
dynamic = ["version"]
Expand Down
173 changes: 173 additions & 0 deletions qt_niu/collapsible_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
from typing import List, Optional

from qtpy.QtCore import Qt, Signal
from qtpy.QtWidgets import QVBoxLayout, QWidget
from superqt.collapsible import QCollapsible


class CollapsibleWidget(QCollapsible):
"""
Custom collapsible widget.
Attributes
----------
toggled_signal_with_self : Signal
Emitted when the CollapsibleWidget is toggled.
Provides the CollapsibleWidget instance and the new state.
Parameters
----------
title : str, optional
The title of the CollapsibleWidget.
parent : QWidget or None, optional
The parent widget.
"""

toggled_signal_with_self = Signal(QCollapsible, bool)

def __init__(
self,
title: str = "",
parent: Optional[QWidget] = None,
expanded_icon: Optional[str] = "▼",
collapsed_icon: Optional[str] = "▶",
):
"""
Initializes a new CollapsibleWidget instance.
Parameters
----------
title : str, optional
The title of the CollapsibleWidget.
parent : QWidget or None, optional
The parent widget.
"""
super().__init__(
title,
parent,
expandedIcon=expanded_icon,
collapsedIcon=collapsed_icon,
)
self.currently_expanded = False

self.toggled.connect(self._on_toggle)

def _on_toggle(self, state):
"""
Handles the toggled signal by emitting the custom signal
with the CollapsibleWidget instance and the new state.
Parameters
----------
state : bool
The new state of the CollapsibleWidget
(True if expanded, False if collapsed).
"""
self.toggled_signal_with_self.emit(self, state)


class CollapsibleWidgetContainer(QWidget):
"""
Container for multiple CollapsibleWidgets with the ability to add,
remove, and synchronize their states. Non-CollapsibleWidgets can also
be added.
Methods
-------
add_widget(QWidget)
Adds a widget to the CollapsibleWidgetContainer.
remove_drawer(QWidget or CollapsibleWidget)
Removes a widget from the CollapsibleWidgetContainer.
_update_drawers(signalling_drawer, state)
Private method to synchronize drawer states.
"""

def __init__(self, parent=None):
"""
Initializes a new CollapsibleWidgetContainer instance.
"""
super().__init__(parent)
self.setLayout(QVBoxLayout())

self.layout().setAlignment(Qt.AlignTop)
self.layout().setSpacing(0)
self.layout().setContentsMargins(0, 0, 0, 0)
self.collapsible_widgets: List[CollapsibleWidget] = []

def add_widget(
self, widget: QWidget, collapsible: bool = True, widget_title: str = ""
):
"""
Adds a QWidget or a CollapsibleWidget to the chest.
Parameters
----------
widget : QWidget
The widget instance to be added.
collapsible : bool, optional
Whether the widget should be collapsible.
widget_title : str, optional
The title of the widget.
"""
if collapsible:
collapsible_widget = CollapsibleWidget(widget_title, parent=self)
collapsible_widget.setContent(widget)
collapsible_widget.toggled_signal_with_self.connect(
self._update_drawers
)
collapsible_widget.collapse(animate=False)
self.collapsible_widgets.append(collapsible_widget)
self.layout().addWidget(collapsible_widget, 0, Qt.AlignTop)
else:
self.layout().addWidget(widget, 0, Qt.AlignTop)

def remove_widget(self, widget: QWidget):
"""
Removes a widget from the chest.
Parameters
----------
widget : QWidget
The widget instance to be removed.
Raises
------
ValueError
If the widget is not found.
"""
for i in range(self.layout().count()):
child_widget = self.layout().itemAt(i).widget()
if (
isinstance(child_widget, CollapsibleWidget)
and child_widget.content() is widget
):
self.layout().removeWidget(child_widget)
self.collapsible_widgets.remove(child_widget)
child_widget.toggled_signal_with_self.disconnect(
self._update_drawers
)
return
elif child_widget is widget:
self.layout().removeWidget(widget)
return

raise ValueError("Widget not found")

def _update_drawers(
self, signalling_widget: CollapsibleWidget, state: bool
):
"""
Synchronizes CollapsibleWidget states to ensure only one
CollapsibleWidget is expanded at a time.
Parameters
----------
signalling_widget : CollapsibleWidget
The CollapsibleWidget emitting the signal.
state : bool
The new state of the signalling_widget.
"""
if state:
for collapsible_widget in self.collapsible_widgets:
if collapsible_widget is not signalling_widget:
collapsible_widget.collapse(False)
29 changes: 29 additions & 0 deletions qt_niu/dialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from qtpy.QtWidgets import QMessageBox, QWidget


def display_warning(widget: QWidget, title: str, message: str) -> bool:
"""
Display a warning in a pop-up that can be accepted or dismissed
"""
message_reply = QMessageBox.question(
widget,
title,
message,
QMessageBox.Yes | QMessageBox.Cancel,
)
if message_reply == QMessageBox.Yes:
return True
else:
return False


def display_info(widget: QWidget, title: str, message: str):
"""
Display information in a pop-up that can only be accepted
"""
QMessageBox.information(
widget,
title,
message,
QMessageBox.Ok,
)
152 changes: 152 additions & 0 deletions qt_niu/interaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
from typing import Callable, List, Optional, Tuple

from qtpy.QtWidgets import (
QCheckBox,
QComboBox,
QDoubleSpinBox,
QLabel,
QLayout,
QPushButton,
QSpinBox,
)


def add_button(
label: str,
layout: QLayout,
connected_function: Callable,
*,
row: int = 0,
column: int = 0,
visibility: bool = True,
minimum_width: int = 0,
alignment: str = "center",
tooltip: Optional[str] = None,
) -> QPushButton:
"""
Add a button to *layout*.
"""
button = QPushButton(label)
if alignment == "center":
pass
elif alignment == "left":
button.setStyleSheet("QPushButton { text-align: left; }")
elif alignment == "right":
button.setStyleSheet("QPushButton { text-align: right; }")

button.setVisible(visibility)
button.setMinimumWidth(minimum_width)

if tooltip:
button.setToolTip(tooltip)

layout.addWidget(button, row, column)
button.clicked.connect(connected_function)
return button


def add_checkbox(
layout: QLayout,
default: bool,
label: str,
row: int = 0,
column: int = 0,
tooltip: Optional[str] = None,
) -> QCheckBox:
"""
Add a checkbox to *layout*.
"""
box = QCheckBox()
box.setChecked(default)
if tooltip:
box.setToolTip(tooltip)
layout.addWidget(QLabel(label), row, column)
layout.addWidget(box, row, column + 1)
return box


def add_float_box(
layout: QLayout,
default: float,
minimum: float,
maximum: float,
label: str,
step: float,
row: int = 0,
column: int = 0,
tooltip: Optional[str] = None,
) -> QDoubleSpinBox:
"""
Add a spin box for float values to *layout*.
"""
box = QDoubleSpinBox()
box.setMinimum(minimum)
box.setMaximum(maximum)
box.setValue(default)
box.setSingleStep(step)
if tooltip:
box.setToolTip(tooltip)
layout.addWidget(QLabel(label), row, column)
layout.addWidget(box, row, column + 1)
return box


def add_int_box(
layout: QLayout,
default: int,
minimum: int,
maximum: int,
label: str,
row: int = 0,
column: int = 0,
tooltip: Optional[str] = None,
) -> QSpinBox:
"""
Add a spin box for integer values to *layout*.
"""
box = QSpinBox()
box.setMinimum(minimum)
box.setMaximum(maximum)
# Not always set if not after min & max
box.setValue(default)
if tooltip:
box.setToolTip(tooltip)
layout.addWidget(QLabel(label), row, column)
layout.addWidget(box, row, column + 1)
return box


def add_combobox(
layout: QLayout,
label: str,
items: List[str],
row: int = 0,
column: int = 0,
label_stack: bool = False,
callback: Optional[Callable] = None,
width: int = 150,
) -> Tuple[QComboBox, Optional[QLabel]]:
"""
Add a selection box to *layout*.
"""
if label_stack:
combobox_row = row + 1
combobox_column = column
else:
combobox_row = row
combobox_column = column + 1
combobox = QComboBox()
combobox.addItems(items)
if callback:
combobox.currentIndexChanged.connect(callback)
combobox.setMaximumWidth = width

if label is not None:
combobox_label = QLabel(label)
combobox_label.setMaximumWidth = width
layout.addWidget(combobox_label, row, column)
else:
combobox_label = None

layout.addWidget(combobox, combobox_row, combobox_column)
return combobox, combobox_label
Loading

0 comments on commit 8e2b812

Please sign in to comment.