diff --git a/visualqc/alignment.py b/visualqc/alignment.py index e043204..1ed6242 100644 --- a/visualqc/alignment.py +++ b/visualqc/alignment.py @@ -26,7 +26,7 @@ from visualqc.interfaces import BaseReviewInterface from visualqc.utils import check_finite_int, check_id_list, check_input_dir_alignment, \ check_out_dir, check_outlier_params, check_views, get_axis, pick_slices, read_image, \ - scale_0to1, check_time + scale_0to1, check_time, set_fig_window_title from visualqc.workflows import BaseWorkflowVisualQC from visualqc.image_utils import overlay_edges, mix_color, diff_image, mix_slices_in_checkers @@ -345,9 +345,9 @@ def open_figure(self): self.fig, self.axes = plt.subplots(self.num_rows, self.num_cols, figsize=self.figsize) self.axes = self.axes.flatten() - - self.fig.canvas.set_window_title('VisualQC Alignment : {} {} {} ' - ''.format(self.in_dir, self.image1_name, self.image2_name)) + set_fig_window_title( + self.fig, 'VisualQC Alignment : {} {} {} ' + ''.format(self.in_dir, self.image1_name, self.image2_name)) # vmin/vmax are controlled, because we rescale all to [0, 1] self.display_params = dict(interpolation='none', aspect='equal', origin='lower', diff --git a/visualqc/defacing.py b/visualqc/defacing.py index e1c41da..6b93cc6 100644 --- a/visualqc/defacing.py +++ b/visualqc/defacing.py @@ -19,9 +19,10 @@ from visualqc import config as cfg from visualqc.image_utils import rescale_without_outliers from visualqc.interfaces import BaseReviewInterface -from visualqc.utils import (check_inputs_defacing, check_out_dir, - compute_cell_extents_grid, pixdim_nifti_header, - read_image, slice_aspect_ratio, check_event_in_axes) +from visualqc.utils import (check_event_in_axes, check_inputs_defacing, + check_out_dir, compute_cell_extents_grid, + pixdim_nifti_header, read_image, set_fig_window_title, + slice_aspect_ratio) from visualqc.workflows import BaseWorkflowVisualQC @@ -355,9 +356,8 @@ def init_layout(self, bounding_rect=cfg.bbox_defacing_MRI_review, figsize=self.figsize) self.fig = self.collage.fig - self.fig.canvas.set_window_title('VisualQC defacing : {} {} ' - ''.format(self.in_dir, - self.defaced_name)) + set_fig_window_title( + self.fig, f'VisualQC defacing : {self.in_dir} {self.defaced_name} ') self.padding = padding diff --git a/visualqc/diffusion.py b/visualqc/diffusion.py index 2b6c904..4d4d96b 100644 --- a/visualqc/diffusion.py +++ b/visualqc/diffusion.py @@ -10,6 +10,7 @@ import time import warnings from abc import ABC +from os.path import basename, join as pjoin from textwrap import wrap import nibabel as nib @@ -17,16 +18,15 @@ from matplotlib import pyplot as plt from matplotlib.widgets import CheckButtons, RadioButtons from mrivis.utils import crop_image -from os.path import basename, join as pjoin + from visualqc import config as cfg from visualqc.image_utils import dwi_overlay_edges from visualqc.readers import diffusion_traverse_bids from visualqc.t1_mri import T1MriInterface from visualqc.utils import (check_bids_dir, check_finite_int, check_image_is_4d, check_out_dir, check_outlier_params, check_time, - check_views, get_axis, - pick_slices, - scale_0to1) + check_views, get_axis, pick_slices, scale_0to1, + set_fig_window_title) from visualqc.workflows import BaseWorkflowVisualQC @@ -420,9 +420,8 @@ def open_figure(self): # 1. main carpet, in the background self.fig, self.ax_carpet = plt.subplots(1, 1, figsize=self.figsize) - self.fig.canvas.set_window_title('VisualQC Diffusion MRI :' - ' {}'.format(self.in_dir)) - + set_fig_window_title( + self.fig, f'VisualQC Diffusion MRI : {self.in_dir} ') self.ax_carpet.set_zorder(self.layer_order_carpet) # vmin/vmax are controlled, because we rescale all to [0, 1] self.imshow_params_carpet = dict(interpolation='none', aspect='auto', diff --git a/visualqc/freesurfer.py b/visualqc/freesurfer.py index 4a8576f..01fa8fd 100644 --- a/visualqc/freesurfer.py +++ b/visualqc/freesurfer.py @@ -32,7 +32,7 @@ check_out_dir, check_outlier_params, check_views, freesurfer_vis_tool_installed, get_axis, get_freesurfer_mri_path, get_label_set, pick_slices, - read_image, scale_0to1, + read_image, scale_0to1, set_fig_window_title, void_subcortical_symmetrize_cortical) from visualqc.workflows import BaseWorkflowVisualQC @@ -407,8 +407,9 @@ def open_figure(self): self.fig, self.axes = plt.subplots(self.num_rows_total, self.num_cols_final, figsize=self.figsize) self.axes = self.axes.flatten() - self.fig.canvas.set_window_title('VisualQC {} {} : {}' - ' '.format(self.vis_type, self.seg_name, self.in_dir)) + set_fig_window_title(self.fig, + 'VisualQC {} {} : {} ' + ''.format(self.vis_type, self.seg_name, self.in_dir)) self.display_params_mri = dict(interpolation='none', aspect='equal', origin='lower', diff --git a/visualqc/functional_mri.py b/visualqc/functional_mri.py index 3dbda66..a5d4429 100644 --- a/visualqc/functional_mri.py +++ b/visualqc/functional_mri.py @@ -22,9 +22,9 @@ from visualqc.readers import func_mri_traverse_bids from visualqc.t1_mri import T1MriInterface from visualqc.utils import (check_bids_dir, check_event_in_axes, check_finite_int, - check_id_list_with_regex, - check_image_is_4d, check_out_dir, check_outlier_params, - check_views, get_axis, pick_slices, scale_0to1) + check_id_list_with_regex, check_image_is_4d, + check_out_dir, check_outlier_params, check_views, + get_axis, pick_slices, scale_0to1, set_fig_window_title) from visualqc.workflows import BaseWorkflowVisualQC @@ -393,8 +393,7 @@ def open_figure(self): # 1. main carpet, in the background self.fig, self.ax_carpet = plt.subplots(1, 1, figsize=self.figsize) - self.fig.canvas.set_window_title('VisualQC Functional MRI :' - ' {}'.format(self.in_dir)) + set_fig_window_title(self.fig, f'VisualQC Functional MRI : {self.in_dir}') self.ax_carpet.set_zorder(self.layer_order_carpet) # vmin/vmax are controlled, because we rescale all to [0, 1] diff --git a/visualqc/t1_mri.py b/visualqc/t1_mri.py index 648f235..ee5e05a 100644 --- a/visualqc/t1_mri.py +++ b/visualqc/t1_mri.py @@ -24,7 +24,7 @@ from visualqc.utils import (check_bids_dir, check_finite_int, check_id_list, check_input_dir_T1, check_out_dir, check_outlier_params, check_views, read_image, saturate_brighter_intensities, - scale_0to1) + scale_0to1, set_fig_window_title) from visualqc.workflows import BaseWorkflowVisualQC @@ -377,8 +377,8 @@ def init_layout(self, views, num_rows_per_view, bounding_rect=cfg.bounding_box_review, figsize=self.figsize) self.fig = self.collage.fig - self.fig.canvas.set_window_title('VisualQC T1 MRI : {} {} ' - ''.format(self.in_dir, self.mri_name)) + set_fig_window_title( + self.fig, f'VisualQC T1w MRI : {self.in_dir} {self.mri_name}') self.padding = padding diff --git a/visualqc/utils.py b/visualqc/utils.py index ee2e612..e9442c2 100644 --- a/visualqc/utils.py +++ b/visualqc/utils.py @@ -67,6 +67,15 @@ def pixdim_nifti_header(header): return header['pixdim'][1:4] +def set_fig_window_title(fig, text): + """Sets the title of the given figure""" + + try: + fig.canvas.manager.set_window_title(text) + except: # not all backends support this, so quietly ignoring it + pass + + def slice_aspect_ratio(pixel_dim, axis): """computes aspect ratio for the cross-sectional slices of a given dimension"""