Skip to content

Commit

Permalink
Add tooltips (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamltyson committed Jun 26, 2023
1 parent 83b2bb9 commit b6d0202
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
21 changes: 18 additions & 3 deletions brainreg_segment/layout/gui_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def add_combobox(
label_stack=False,
callback=None,
width=150,
tooltip=None,
):
if label_stack:
combobox_row = row + 1
Expand All @@ -41,6 +42,8 @@ def add_combobox(
else:
combobox_label = None

if tooltip:
combobox.setToolTip(tooltip)
layout.addWidget(combobox, combobox_row, combobox_column)
return combobox, combobox_label

Expand All @@ -55,6 +58,7 @@ def add_button(
visibility=True,
minimum_width=0,
alignment="center",
tooltip=None,
):
button = QPushButton(label)
if alignment == "center":
Expand All @@ -66,6 +70,9 @@ def add_button(

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

if tooltip:
button.setToolTip(tooltip)
layout.addWidget(button, row, column)
button.clicked.connect(connected_function)
return button
Expand Down Expand Up @@ -119,33 +126,41 @@ def add_button(
# return button


def add_checkbox(layout, default, label, row, column=0):
def add_checkbox(layout, default, label, row, column=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, column=0
layout, default, minimum, maximum, label, step, row, column=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, column=0):
def add_int_box(
layout, default, minimum, maximum, label, row, column=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
16 changes: 16 additions & 0 deletions brainreg_segment/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def add_segmentation_methods_panel(self, row, column=1):
column=1,
minimum_width=COLUMN_WIDTH,
alignment=SEGM_METHODS_PANEL_ALIGN,
tooltip="Segment a 1D structure (e.g. an axon "
"or implanted electrode)",
)
self.show_trackseg_button.setEnabled(False)

Expand All @@ -165,6 +167,7 @@ def add_segmentation_methods_panel(self, row, column=1):
column=1,
minimum_width=COLUMN_WIDTH,
alignment=SEGM_METHODS_PANEL_ALIGN,
tooltip="Segment a 2/3D structure (e.g. a brain region)",
)
self.show_regionseg_button.setEnabled(False)

Expand Down Expand Up @@ -196,6 +199,10 @@ def add_loading_panel(self, row, column=0):
visibility=False,
minimum_width=COLUMN_WIDTH,
alignment=LOADING_PANEL_ALIGN,
tooltip="Load a brainreg project in the coordinate "
"space of your raw data (i.e., not warped to the atlas "
"space). N.B. the data will have been reoriented to "
"the orientation of your chosen atlas.",
)

self.load_button_standard = add_button(
Expand All @@ -207,6 +214,8 @@ def add_loading_panel(self, row, column=0):
visibility=False,
minimum_width=COLUMN_WIDTH,
alignment=LOADING_PANEL_ALIGN,
tooltip="Load a brainreg project warped to the coordinate "
"space of the atlas.",
)

self.add_atlas_menu(self.load_data_layout)
Expand Down Expand Up @@ -236,6 +245,9 @@ def add_saving_panel(self, row):
row=0,
column=0,
visibility=False,
tooltip="Export the segmentation to brainrender "
"(only works if the segmentation was "
"performed in atlas space.",
)
self.save_button = add_button(
"Save",
Expand All @@ -244,6 +256,7 @@ def add_saving_panel(self, row):
row=0,
column=1,
visibility=False,
tooltip="Save the segmentation to disk to " "be reloaded later.",
)

self.save_data_layout.setColumnMinimumWidth(1, COLUMN_WIDTH)
Expand All @@ -269,6 +282,9 @@ def add_atlas_menu(self, layout):
label_stack=True,
callback=self.initialise_atlas,
width=COLUMN_WIDTH,
tooltip="Load a BrainGlobe atlas if you don't have "
"a brainreg project to load. Useful for creating "
"illustrations or testing the software.",
)

self.atlas_menu = atlas_menu
Expand Down
13 changes: 13 additions & 0 deletions brainreg_segment/segmentation_panels/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def add_region_panel(self, row):
self.add_new_region,
row=2,
column=0,
tooltip="Create a new empty segmentation layer "
"to manually segment a new region.",
)

add_button(
Expand All @@ -70,27 +72,38 @@ def add_region_panel(self, row):
self.run_region_analysis,
row=2,
column=1,
tooltip="Analyse the spatial distribution of the "
"segmented regions.",
)
add_button(
"Add region from selected layer",
region_layout,
self.add_region_from_existing_layer,
row=3,
column=0,
tooltip="Adds a region from a selected labels layer (e.g. "
"from another plugin). Make sure this region "
"was segmented from the currently loaded "
"brainreg result (i.e. atlas/sample space)!",
)

self.calculate_volumes_checkbox = add_checkbox(
region_layout,
self.calculate_volumes_default,
"Calculate volumes",
0,
tooltip="Calculate and save the volume of each "
"brain region included in the segmented "
"region.",
)

self.summarise_volumes_checkbox = add_checkbox(
region_layout,
self.summarise_volumes_default,
"Summarise volumes",
1,
tooltip="Summarise each segmented region "
"(e.g. center, volume etc.).",
)

region_layout.setColumnMinimumWidth(1, COLUMN_WIDTH)
Expand Down
24 changes: 23 additions & 1 deletion brainreg_segment/segmentation_panels/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def add_track_panel(self, row):
self.add_track,
row=5,
column=0,
tooltip="Create a new empty segmentation layer "
"to manually annotate a new track.",
)

add_button(
Expand All @@ -88,6 +90,9 @@ def add_track_panel(self, row):
self.run_track_analysis,
row=5,
column=1,
tooltip="Join up the points using a spline fit "
"and save the distribution of the track in "
"the brain.",
)

add_button(
Expand All @@ -96,6 +101,10 @@ def add_track_panel(self, row):
self.add_track_from_existing_layer,
row=6,
column=0,
tooltip="Adds a track from a selected points layer (e.g. "
"from another plugin). Make sure this track "
"was segmented from the currently loaded "
"brainreg result (i.e. atlas/sample space)! ",
)

add_button(
Expand All @@ -104,13 +113,20 @@ def add_track_panel(self, row):
self.add_surface_points,
row=6,
column=1,
tooltip="Add an additional first point at the surface of the "
"brain. Selecting this option will add an additional "
"point at the closest part of the brain surface to the "
"first point, so that the track starts there.",
)

self.summarise_track_checkbox = add_checkbox(
track_layout,
self.summarise_track_default,
"Summarise",
0,
row=0,
tooltip="Save a csv file, showing the brain area for "
"each part of the interpolated track "
"(determined by the number of spline points). ",
)

self.fit_degree = add_int_box(
Expand All @@ -120,6 +136,7 @@ def add_track_panel(self, row):
5,
"Fit degree",
1,
tooltip="Degree of polynomial to fit to the track.",
)

self.spline_smoothing = add_float_box(
Expand All @@ -130,6 +147,9 @@ def add_track_panel(self, row):
"Spline smoothing",
0.1,
2,
tooltip="How closely or not to fit the points "
"(lower numbers fit more closely, for "
"a less smooth interpolation).",
)

self.spline_points = add_int_box(
Expand All @@ -139,6 +159,8 @@ def add_track_panel(self, row):
10000,
"Spline points",
3,
tooltip="How many points are sampled from the "
"interpolation (used for the summary).",
)

track_layout.setColumnMinimumWidth(1, COLUMN_WIDTH)
Expand Down

0 comments on commit b6d0202

Please sign in to comment.