Skip to content

Commit

Permalink
Move qtpy functionality from brainglobe-segmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
adamltyson committed Jan 16, 2024
1 parent 4b4f350 commit 8e96563
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
29 changes: 29 additions & 0 deletions brainglobe_utils/qtpy/dialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from qtpy.QtWidgets import QMessageBox

Check warning on line 1 in brainglobe_utils/qtpy/dialog.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/dialog.py#L1

Added line #L1 was not covered by tests


def display_warning(widget, title, message):

Check warning on line 4 in brainglobe_utils/qtpy/dialog.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/dialog.py#L4

Added line #L4 was not covered by tests
"""
Display a warning in a pop-up that can be accepted or dismissed
"""
message_reply = QMessageBox.question(

Check warning on line 8 in brainglobe_utils/qtpy/dialog.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/dialog.py#L8

Added line #L8 was not covered by tests
widget,
title,
message,
QMessageBox.Yes | QMessageBox.Cancel,
)
if message_reply == QMessageBox.Yes:
return True

Check warning on line 15 in brainglobe_utils/qtpy/dialog.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/dialog.py#L14-L15

Added lines #L14 - L15 were not covered by tests
else:
return False

Check warning on line 17 in brainglobe_utils/qtpy/dialog.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/dialog.py#L17

Added line #L17 was not covered by tests


def display_info(widget, title, message):

Check warning on line 20 in brainglobe_utils/qtpy/dialog.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/dialog.py#L20

Added line #L20 was not covered by tests
"""
Display information in a pop-up that can only be accepted
"""
QMessageBox.information(

Check warning on line 24 in brainglobe_utils/qtpy/dialog.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/dialog.py#L24

Added line #L24 was not covered by tests
widget,
title,
message,
QMessageBox.Ok,
)
94 changes: 94 additions & 0 deletions brainglobe_utils/qtpy/interaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from qtpy.QtWidgets import (

Check warning on line 1 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L1

Added line #L1 was not covered by tests
QCheckBox,
QDoubleSpinBox,
QLabel,
QPushButton,
QSpinBox,
)


def add_button(

Check warning on line 10 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L10

Added line #L10 was not covered by tests
label,
layout,
connected_function,
*,
row: int = 0,
column: int = 0,
visibility=True,
minimum_width=0,
alignment="center",
tooltip=None,
):
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; }")

Check warning on line 28 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L22-L28

Added lines #L22 - L28 were not covered by tests

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

Check warning on line 31 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L30-L31

Added lines #L30 - L31 were not covered by tests

if tooltip:
button.setToolTip(tooltip)
layout.addWidget(button, row, column)
button.clicked.connect(connected_function)
return button

Check warning on line 37 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L33-L37

Added lines #L33 - L37 were not covered by tests


def add_checkbox(

Check warning on line 40 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L40

Added line #L40 was not covered by tests
layout, default, label, row: int = 0, column: int = 0, tooltip=None
):
box = QCheckBox()
box.setChecked(default)
if tooltip:
box.setToolTip(tooltip)
layout.addWidget(QLabel(label), row, column)
layout.addWidget(box, row, column + 1)
return box

Check warning on line 49 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L43-L49

Added lines #L43 - L49 were not covered by tests


def add_float_box(

Check warning on line 52 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L52

Added line #L52 was not covered by tests
layout,
default,
minimum,
maximum,
label,
step,
row: int = 0,
column: int = 0,
tooltip=None,
):
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

Check warning on line 72 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L63-L72

Added lines #L63 - L72 were not covered by tests


def add_int_box(

Check warning on line 75 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L75

Added line #L75 was not covered by tests
layout,
default,
minimum,
maximum,
label,
row: int = 0,
column: int = 0,
tooltip=None,
):
box = QSpinBox()
box.setMinimum(minimum)
box.setMaximum(maximum)

Check warning on line 87 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L85-L87

Added lines #L85 - L87 were not covered by tests
# 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

Check warning on line 94 in brainglobe_utils/qtpy/interaction.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_utils/qtpy/interaction.py#L89-L94

Added lines #L89 - L94 were not covered by tests

0 comments on commit 8e96563

Please sign in to comment.