-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move qtpy functionality from brainglobe-segmentation
- Loading branch information
1 parent
4b4f350
commit 8e96563
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from qtpy.QtWidgets import QMessageBox | ||
|
||
|
||
def display_warning(widget, title, message): | ||
""" | ||
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, title, message): | ||
""" | ||
Display information in a pop-up that can only be accepted | ||
""" | ||
QMessageBox.information( | ||
widget, | ||
title, | ||
message, | ||
QMessageBox.Ok, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from qtpy.QtWidgets import ( | ||
QCheckBox, | ||
QDoubleSpinBox, | ||
QLabel, | ||
QPushButton, | ||
QSpinBox, | ||
) | ||
|
||
|
||
def add_button( | ||
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; }") | ||
|
||
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, 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 | ||
|
||
|
||
def add_float_box( | ||
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 | ||
|
||
|
||
def add_int_box( | ||
layout, | ||
default, | ||
minimum, | ||
maximum, | ||
label, | ||
row: int = 0, | ||
column: int = 0, | ||
tooltip=None, | ||
): | ||
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 | ||