Skip to content

Commit

Permalink
Layout changes and refactoring (#10)
Browse files Browse the repository at this point in the history
* Update .gitignore

* Grouped layout helpers

* Delete gui_elements.py

* Code refactoring

* Moved segment.py for now

* Revert to segment.py

* Implement segmentation methods as separate classes

* Add layout folder

* Update segment.py

* Enable button label alignment

* Region label paint is ndim by default

* Rename segmentation method folder and bugfixes

* Take over Adam's fixes and further bugfixes

* get rid of wildcard import

* Update segment.py

* Adding comments to trigger commit hooks

* Update analysis.py

* Reformatted code

* Reset constants (defaults)

Back to original values

* Re-integrated loading function for atlas layers and brainreg

Otherwise CI breaks.

* bugfix constant naming

* updated GUI tests. Left out add_surface_points() for now

add_surface_points() seems to work when workflow is followed in GUI but fails in CI. Need to investigate a bit.

* Make imio requirement

* Bugfixes, test changes

* Separate methods chooser panel from loader and add button styling
  • Loading branch information
horsto authored Sep 2, 2020
1 parent 2174c87 commit 38cb744
Show file tree
Hide file tree
Showing 21 changed files with 1,894 additions and 1,449 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ target/
# pyenv
.python-version

# vscode
.vscode

# celery beat schedule file
celerybeat-schedule

Expand Down Expand Up @@ -117,3 +120,4 @@ venv.bak/
.idea/

*.~lock.*
*.zip
76 changes: 0 additions & 76 deletions brainreg_segment/gui_elements.py

This file was deleted.

Empty file.
28 changes: 28 additions & 0 deletions brainreg_segment/layout/gui_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Constants used throughout
WINDOW_HEIGHT = 750
WINDOW_WIDTH = 1500
COLUMN_WIDTH = 150

LOADING_PANEL_ALIGN = (
"left" # Alignment of text in pushbuttons in loading panel
)
SEGM_METHODS_PANEL_ALIGN = (
"left" # Alignment of text in pushbuttons in methods chooser panel
)

POINT_SIZE = 100
SPLINE_SIZE = 50
NUM_COLORS = 10
BRUSH_SIZE = 250
SPLINE_POINTS_DEFAULT = 1000
SPLINE_SMOOTHING_DEFAULT = 0.1
FIT_DEGREE_DEFAULT = 3

SUMMARISE_TRACK_DEFAULT = True
ADD_SURFACE_POINT_DEFAULT = False
CALCULATE_VOLUMES_DEFAULT = True
SUMMARIZE_VOLUMES_DEFAULT = True

TRACK_FILE_EXT = ".points"
IMAGE_FILE_EXT = ".tiff"
BOUNDARIES_STRING = "Boundaries"
147 changes: 147 additions & 0 deletions brainreg_segment/layout/gui_elements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# GUI ELEMENTS
# from napari.resources import build_icons # Contains .SVGPATH to all icons for napari

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


def add_combobox(
layout,
label,
items,
row,
column=0,
label_stack=False,
callback=None,
width=150,
):
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


def add_button(
label,
layout,
connected_function,
row,
column,
visibility=True,
minimum_width=0,
alignment="center",
):
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)
layout.addWidget(button, row, column)
button.clicked.connect(connected_function)
return button


# def add_radiobutton(
# label,
# layout,
# connected_function,
# row,
# column,
# visibility=True,
# minimum_width=0,
# alignment="center",
# ):
# button = QRadioButton(label)
# if alignment == "center":
# pass
# elif alignment == "left":
# button.setStyleSheet(
# "QRadioButton { text-align: left; padding: 0; spacing: 30px;}"
# )
# elif alignment == "right":
# button.setStyleSheet(
# "QRadioButton { text-align: right; padding: 0; spacing: 30px;}"
# )

# # Too change indicator button ... needs to dynamically retrieve icon from Napari.
# # Icons are saved as .svg files under napari.resources SVGPATH
# # "QRadioButton::indicator"
# # "{"
# # "width:16px;"
# # "height:16px;"
# # "}"
# # "QRadioButton::indicator::unchecked"
# # "{"
# # "image: url(build_icons.SVGPATH/visibility_off.svg);"
# # "}"
# # "QRadioButton::indicator::checked"
# # "{"
# # "image: url(/opt/miniconda3/envs/analysis/lib/python3.6/site-packages/napari/resources/icons/visibility.svg);"
# # "}"
# # )

# button.setVisible(visibility)
# button.setMinimumWidth(minimum_width)
# layout.addWidget(button, row, column)
# button.clicked.connect(connected_function)
# return button


def add_checkbox(layout, default, label, row, column=0):
box = QCheckBox()
box.setChecked(default)
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, column=0
):
box = QDoubleSpinBox()
box.setMinimum(minimum)
box.setMaximum(maximum)
box.setValue(default)
box.setSingleStep(step)
layout.addWidget(QLabel(label), row, column)
layout.addWidget(box, row, column + 1)
return box


def add_int_box(layout, default, minimum, maximum, label, row, column=0):
box = QSpinBox()
box.setMinimum(minimum)
box.setMaximum(maximum)
# Not always set if not after min & max
box.setValue(default)
layout.addWidget(QLabel(label), row, column)
layout.addWidget(box, row, column + 1)
return box
35 changes: 35 additions & 0 deletions brainreg_segment/layout/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Small layout utils
from napari.viewer import Viewer


def disable_napari_btns(viewer):
"""
Disable some Napari functions to hide them from user interation
- Transpose TODO: Understand how to add this properly with space conventions
- Grid view
- Console
- New labels layer
- New points layer
- New shapes layer
"""
viewer.window.qt_viewer.viewerButtons.transposeDimsButton.setVisible(False)
viewer.window.qt_viewer.viewerButtons.gridViewButton.setVisible(False)
viewer.window.qt_viewer.viewerButtons.consoleButton.setVisible(False)
viewer.window.qt_viewer.layerButtons.newLabelsButton.setVisible(False)
viewer.window.qt_viewer.layerButtons.newPointsButton.setVisible(False)
viewer.window.qt_viewer.layerButtons.newShapesButton.setVisible(False)


def disable_napari_key_bindings():
"""
Disable some default key bingings that are unused
"""

@Viewer.bind_key("Control-G", overwrite=True)
def no_grid_mode_warning(self):
print("Grid mode is not supported")

@Viewer.bind_key("Control-T", overwrite=True)
def no_tranpose_warning(self):
print("Transposing is not supported")
4 changes: 2 additions & 2 deletions brainreg_segment/regions/IO.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tifffile
import imio
import numpy as np

from pathlib import Path
Expand Down Expand Up @@ -120,7 +120,7 @@ def save_regions_to_file(
name = label_layer.name

filename = destination_directory / (name + image_extension)
tifffile.imsave(filename, data.astype(np.int16))
imio.to_tiff(data.astype(np.int16), filename)


def export_regions_to_file(image, filename, voxel_size, ignore_empty=True):
Expand Down
1 change: 1 addition & 0 deletions brainreg_segment/regions/analysis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pandas as pd


from napari.qt.threading import thread_worker
from skimage.measure import regionprops_table

Expand Down
2 changes: 1 addition & 1 deletion brainreg_segment/regions/layers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import tifffile

import numpy as np

from glob import glob
Expand Down Expand Up @@ -28,6 +27,7 @@ def add_new_label_layer(
"""
labels = np.empty_like(base_image)
label_layer = viewer.add_labels(labels, num_colors=num_colors, name=name)
label_layer.n_dimensional = True
label_layer.selected_label = selected_label
label_layer.brush_size = brush_size
return label_layer
Expand Down
Loading

0 comments on commit 38cb744

Please sign in to comment.