Skip to content

Commit

Permalink
updated widget looks (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mese79 authored Jan 20, 2025
1 parent 6a66577 commit e3fa2cb
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 24 deletions.
18 changes: 17 additions & 1 deletion src/careamics_napari/widgets/configuration_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def __init__(
# experiment name text box
experiment_widget = QWidget()
experiment_layout = QFormLayout()
experiment_layout.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
experiment_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)

self.experiment_name = QLineEdit()
self.experiment_name.setToolTip(
Expand All @@ -89,6 +91,8 @@ def __init__(
# validation
validation = QGroupBox("Validation")
validation_layout = QFormLayout()
validation_layout.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
validation_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)

self.validation_perc = create_double_spinbox(
0.01, 1, self.configuration_signal.val_percentage, 0.01, n_decimal=2
Expand All @@ -113,6 +117,8 @@ def __init__(
# augmentations group box, with x_flip, y_flip and rotations
augmentations = QGroupBox("Augmentations")
augmentations_layout = QFormLayout()
augmentations_layout.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
augmentations_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)

self.x_flip = QCheckBox("X Flip")
self.x_flip.setToolTip(
Expand Down Expand Up @@ -146,6 +152,8 @@ def __init__(

ind_channels_widget = QWidget()
ind_channels_layout = QFormLayout()
ind_channels_layout.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
ind_channels_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)

self.independent_channels = QCheckBox("Independent")
self.independent_channels.setToolTip(
Expand All @@ -161,6 +169,8 @@ def __init__(
# n2v
n2v_channels_widget = QWidget()
n2v_channels_widget_layout = QFormLayout()
n2v_channels_widget_layout.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
n2v_channels_widget_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)

self.n_channels = create_int_spinbox(
1, 10, self.configuration_signal.n_channels_n2v, 1
Expand All @@ -173,6 +183,8 @@ def __init__(
# care/n2n
care_channels_widget = QWidget()
care_channels_widget_layout = QFormLayout()
care_channels_widget_layout.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
care_channels_widget_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)

self.n_channels_in = create_int_spinbox(
1, 10, self.configuration_signal.n_channels_in_care, 1
Expand All @@ -199,6 +211,8 @@ def __init__(
# n2v2
self.n2v2_widget = QGroupBox("N2V2")
n2v2_layout = QFormLayout()
n2v2_layout.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
n2v2_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)

self.use_n2v2 = QCheckBox("Use N2V2")
self.use_n2v2.setToolTip("Check to use N2V2 for training.")
Expand All @@ -212,6 +226,8 @@ def __init__(
# model params
model_params = QGroupBox("UNet parameters")
model_params_layout = QFormLayout()
model_params_layout.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
model_params_layout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)

self.model_depth = create_int_spinbox(2, 5, self.configuration_signal.depth, 1)
self.model_depth.setToolTip("Depth of the U-Net model.")
Expand All @@ -232,7 +248,7 @@ def __init__(
button_widget = QWidget()
button_widget.setLayout(QVBoxLayout())
self.save_button = QPushButton("Save")
self.save_button.setMaximumWidth(80)
self.save_button.setMinimumWidth(120)
button_widget.layout().addWidget(self.save_button)
button_widget.layout().setAlignment(Qt.AlignmentFlag.AlignCenter)
self.layout().addWidget(button_widget)
Expand Down
13 changes: 9 additions & 4 deletions src/careamics_napari/widgets/predict_data_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import TYPE_CHECKING, Optional

from qtpy.QtCore import Qt
from qtpy.QtWidgets import (
QFormLayout,
QTabWidget,
Expand Down Expand Up @@ -88,11 +89,15 @@ def _set_layer_tab(
The layer tab.
"""
if _has_napari and napari.current_viewer() is not None:
form = QFormLayout()
form.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
form.setContentsMargins(12, 12, 0, 0)
widget_layers = QWidget()
widget_layers.setLayout(QFormLayout())
widget_layers.setLayout(form)

self.img_pred = layer_choice()
widget_layers.layout().addRow("Predict", self.img_pred.native)
form.addRow("Predict", self.img_pred.native)

layer_tab.layout().addWidget(widget_layers)

Expand All @@ -117,8 +122,8 @@ def _set_disk_tab(self: Self, disk_tab: QWidget) -> None:
# disk tab
buttons = QWidget()
form = QFormLayout()
# form.setContentsMargins(4, 0, 4, 0)
# form.setSpacing(0)
form.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)

self.pred_images_folder = FolderWidget("Choose")
form.addRow("Predict", self.pred_images_folder)
Expand Down
8 changes: 5 additions & 3 deletions src/careamics_napari/widgets/prediction_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import Optional

from qtpy.QtCore import Qt
from qtpy.QtWidgets import (
QCheckBox,
QFormLayout,
Expand Down Expand Up @@ -81,7 +82,6 @@ def __init__(

self.setTitle("Prediction")
self.setLayout(QVBoxLayout())
self.layout().setContentsMargins(20, 20, 20, 0)

# data selection
predict_data_widget = PredictDataWidget(self.pred_signal)
Expand Down Expand Up @@ -111,6 +111,8 @@ def __init__(
self.batch_size_spin.setEnabled(False)

tiling_form = QFormLayout()
tiling_form.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
tiling_form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
tiling_form.addRow("XY tile size", self.tile_size_xy)
tiling_form.addRow("Z tile size", self.tile_size_z)
tiling_form.addRow("Batch size", self.batch_size_spin)
Expand All @@ -128,11 +130,11 @@ def __init__(
predictions = QWidget()
predictions.setLayout(QHBoxLayout())
self.predict_button = QPushButton("Predict", self)
self.predict_button.setMinimumWidth(120)
self.predict_button.setEnabled(False)
self.predict_button.setToolTip("Run the trained model on the images")

predictions.layout().addWidget(QLabel(""))
predictions.layout().addWidget(self.predict_button)
predictions.layout().addWidget(self.predict_button, alignment=Qt.AlignLeft)

# add to the group
self.layout().addWidget(self.pb_prediction)
Expand Down
4 changes: 3 additions & 1 deletion src/careamics_napari/widgets/saving_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
from typing import Optional

from qtpy.QtCore import Qt
from qtpy.QtWidgets import (
QComboBox,
QFileDialog,
Expand Down Expand Up @@ -71,11 +72,12 @@ def __init__(
self.save_choice.setToolTip("Output format")

self.save_button = QPushButton("Save model", self)
self.save_button.setMinimumWidth(120)
self.save_button.setEnabled(False)
self.save_choice.setToolTip("Save the model weights and configuration.")

save_widget.layout().addWidget(self.save_button)
save_widget.layout().addWidget(self.save_choice)
save_widget.layout().addWidget(self.save_button, alignment=Qt.AlignLeft)
self.layout().addWidget(save_widget)

# actions
Expand Down
25 changes: 15 additions & 10 deletions src/careamics_napari/widgets/train_data_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import TYPE_CHECKING, Optional

from qtpy.QtCore import Qt
from qtpy.QtWidgets import (
QFormLayout,
QTabWidget,
Expand Down Expand Up @@ -92,8 +93,10 @@ def _set_layer_tab(
Layer tab widget.
"""
if _has_napari and napari.current_viewer() is not None:
widget_layers = QWidget()
widget_layers.setLayout(QFormLayout())
form = QFormLayout()
form.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
form.setContentsMargins(12, 12, 0, 0)

self.img_train = layer_choice()
self.img_train.native.setToolTip("Select a training layer.")
Expand Down Expand Up @@ -130,16 +133,17 @@ def _set_layer_tab(
if self.target_val.value is not None:
self._update_val_target_layer(self.target_val.value)

widget_layers.layout().addRow("Train", self.img_train.native)
widget_layers.layout().addRow("Val", self.img_val.native)
widget_layers.layout().addRow("Train target", self.target_train.native)
widget_layers.layout().addRow("Val target", self.target_val.native)
form.addRow("Train", self.img_train.native)
form.addRow("Val", self.img_val.native)
form.addRow("Train target", self.target_train.native)
form.addRow("Val target", self.target_val.native)

else:
widget_layers.layout().addRow("Train", self.img_train.native)
widget_layers.layout().addRow("Val", self.img_val.native)
form.addRow("Train", self.img_train.native)
form.addRow("Val", self.img_val.native)

layer_tab.layout().addWidget(widget_layers)
# layer_tab.layout().addWidget(widget_layers)
layer_tab.layout().addLayout(form)

else:
# simply remove the tab
Expand All @@ -156,7 +160,8 @@ def _set_disk_tab(self: Self, disk_tab: QWidget) -> None:
# disk tab
buttons = QWidget()
form = QFormLayout()
# form.setContentsMargins(4, 0, 4, 0)
form.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
# form.setSpacing(0)

self.train_images_folder = FolderWidget("Choose")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self: Self, training_signal: Optional[TrainingSignal] = None) -> No
self.config_window: Optional[AdvancedConfigurationWindow] = None

self.setTitle("Training parameters")
# self.setMinimumWidth(100)
self.setMinimumWidth(200)

# expert settings
icon = QtGui.QIcon(ICON_GEAR)
Expand Down Expand Up @@ -83,6 +83,9 @@ def __init__(self: Self, training_signal: Optional[TrainingSignal] = None) -> No
self.patch_Z_spin.setEnabled(self.configuration_signal.is_3d)

formLayout = QFormLayout()
formLayout.setContentsMargins(0, 0, 0, 0)
formLayout.setFormAlignment(Qt.AlignLeft | Qt.AlignTop)
formLayout.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)
formLayout.addRow("Enable 3D", self.enable_3d)
formLayout.addRow(self.axes_widget.label.text(), self.axes_widget.text_field)
formLayout.addRow("N epochs", self.n_epochs_spin)
Expand Down
10 changes: 6 additions & 4 deletions src/careamics_napari/widgets/training_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import Optional

from qtpy.QtCore import Qt
from qtpy.QtWidgets import (
QGroupBox,
QHBoxLayout,
Expand Down Expand Up @@ -45,15 +46,17 @@ def __init__(self: Self, train_status: Optional[TrainingStatus] = None) -> None:
train_buttons.setLayout(QHBoxLayout())

self.train_button = QPushButton("Train", self)
self.train_button.setMinimumWidth(120)

self.reset_model_button = QPushButton("", self)
self.reset_model_button = QPushButton("Reset", self)
self.reset_model_button.setMinimumWidth(120)
self.reset_model_button.setEnabled(False)
self.reset_model_button.setToolTip(
"Reset the weights of the model (forget the training)"
)

train_buttons.layout().addWidget(self.reset_model_button)
train_buttons.layout().addWidget(self.train_button)
train_buttons.layout().addWidget(self.train_button, alignment=Qt.AlignLeft)
train_buttons.layout().addWidget(self.reset_model_button, alignment=Qt.AlignLeft)
self.layout().addWidget(train_buttons)

# actions
Expand Down Expand Up @@ -94,7 +97,6 @@ def _reset_clicked(self) -> None:
self.train_status.state = TrainingState.IDLE
self.train_button.setText("Train")
self.reset_model_button.setEnabled(False)
self.reset_model_button.setText("")

def _update_button(self, new_state: TrainingState) -> None:
"""Update the button text based on the training state.
Expand Down

0 comments on commit e3fa2cb

Please sign in to comment.