From 82be8627bf49122179937c640eb40b330969d181 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Mon, 13 Aug 2018 15:39:38 -0300 Subject: [PATCH] Using kwargs protocol from pypubsub (args1 deprecated) closes #141 (#143) --- app.py | 36 +++++++++++++++++++++--------------- invesalius/control.py | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------ invesalius/data/coordinates.py | 4 ++-- invesalius/data/coregistration.py | 16 ++++++++-------- invesalius/data/geometry.py | 2 +- invesalius/data/mask.py | 37 ++++++++++++++++++------------------- invesalius/data/measures.py | 83 +++++++++++++++++++++++++---------------------------------------------------------- invesalius/data/record_coords.py | 6 +++--- invesalius/data/slice_.py | 198 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------- invesalius/data/styles.py | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------- invesalius/data/surface.py | 116 ++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------- invesalius/data/viewer_slice.py | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------- invesalius/data/viewer_volume.py | 301 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------- invesalius/data/volume.py | 97 ++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------- invesalius/data/vtk_utils.py | 3 +-- invesalius/gui/bitmap_preview_panel.py | 14 ++++++-------- invesalius/gui/data_notebook.py | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------- invesalius/gui/default_tasks.py | 18 ++++++++---------- invesalius/gui/default_viewers.py | 71 ++++++++++++++++++++++++++++++++++------------------------------------- invesalius/gui/dialogs.py | 53 ++++++++++++++++++++++++----------------------------- invesalius/gui/dicom_preview_panel.py | 4 ++-- invesalius/gui/frame.py | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------- invesalius/gui/import_bitmap_panel.py | 36 +++++++++++++++--------------------- invesalius/gui/import_network_panel.py | 4 ++-- invesalius/gui/import_panel.py | 41 +++++++++++++++++------------------------ invesalius/gui/preferences.py | 2 +- invesalius/gui/task_exporter.py | 7 ++++--- invesalius/gui/task_importer.py | 6 +++--- invesalius/gui/task_navigator.py | 200 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------- invesalius/gui/task_slice.py | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------- invesalius/gui/task_surface.py | 41 +++++++++++++++++++---------------------- invesalius/gui/task_tools.py | 6 ++---- invesalius/gui/widgets/clut_raycasting.py | 2 +- invesalius/gui/widgets/slice_menu.py | 30 +++++++++++++++--------------- invesalius/presets.py | 19 +++++++++---------- invesalius/reader/bitmap_reader.py | 10 +++++----- invesalius/reader/dicom_reader.py | 6 +++--- 37 files changed, 1134 insertions(+), 1354 deletions(-) diff --git a/app.py b/app.py index f45fd99..28dcbdd 100644 --- a/app.py +++ b/app.py @@ -47,7 +47,7 @@ try: except ImportError: from wx import SplashScreen #from wx.lib.pubsub import setupv1 #new wx -from wx.lib.pubsub import setuparg1# as psv1 +# from wx.lib.pubsub import setuparg1# as psv1 #from wx.lib.pubsub import Publisher #import wx.lib.pubsub as ps from wx.lib.pubsub import pub as Publisher @@ -117,7 +117,7 @@ class InVesalius(wx.App): Open drag & drop files under darwin """ path = os.path.abspath(filename) - Publisher.sendMessage('Open project', path) + Publisher.sendMessage('Open project', filepath=path) def Startup2(self): self.control = self.splash.control @@ -347,10 +347,10 @@ def use_cmd_optargs(options, args): # If import DICOM argument... if options.dicom_dir: import_dir = options.dicom_dir - Publisher.sendMessage('Import directory', {'directory': import_dir, 'gui': not options.no_gui}) + Publisher.sendMessage('Import directory', directory=import_dir, use_gui=not options.no_gui) if options.save: - Publisher.sendMessage('Save project', os.path.abspath(options.save)) + Publisher.sendMessage('Save project', filepath=os.path.abspath(options.save)) exit(0) check_for_export(options) @@ -360,9 +360,11 @@ def use_cmd_optargs(options, args): import invesalius.reader.dicom_reader as dcm for patient in dcm.GetDicomGroups(options.import_all): for group in patient.GetGroups(): - Publisher.sendMessage('Import group', {'group': group, 'gui': not options.no_gui}) + Publisher.sendMessage('Import group', + group=group, + use_gui=not options.no_gui) check_for_export(options, suffix=group.title, remove_surfaces=False) - Publisher.sendMessage('Remove masks', [0]) + Publisher.sendMessage('Remove masks', mask_indexes=(0,)) return True # Check if there is a file path somewhere in what the user wrote @@ -373,14 +375,14 @@ def use_cmd_optargs(options, args): file = utils.decode(arg, FS_ENCODE) if os.path.isfile(file): path = os.path.abspath(file) - Publisher.sendMessage('Open project', path) + Publisher.sendMessage('Open project', filepath=path) check_for_export(options) return True - + file = utils.decode(arg, sys.stdin.encoding) if os.path.isfile(file): path = os.path.abspath(file) - Publisher.sendMessage('Open project', path) + Publisher.sendMessage('Open project', filepath=path) check_for_export(options) return True @@ -428,7 +430,8 @@ def check_for_export(options, suffix='', remove_surfaces=False): def export(path_, threshold_range, remove_surface=False): import invesalius.constants as const - Publisher.sendMessage('Set threshold values', threshold_range) + Publisher.sendMessage('Set threshold values', + threshold_range=threshold_range) surface_options = { 'method': { @@ -443,17 +446,20 @@ def export(path_, threshold_range, remove_surface=False): 'overwrite': False, } } - Publisher.sendMessage('Create surface from index', surface_options) - Publisher.sendMessage('Export surface to file', (path_, const.FILETYPE_STL)) + Publisher.sendMessage('Create surface from index', + surface_parameters=surface_options) + Publisher.sendMessage('Export surface to file', + filename=path_, filetype=const.FILETYPE_STL) if remove_surface: - Publisher.sendMessage('Remove surfaces', [0]) + Publisher.sendMessage('Remove surfaces', + surface_indexes=(0,)) -def print_events(data): +def print_events(topic=Publisher.AUTO_TOPIC, **msg_data): """ Print pubsub messages """ - utils.debug(data.topic) + utils.debug("%s\n\tParameters: %s" % (topic, msg_data)) def main(): """ diff --git a/invesalius/control.py b/invesalius/control.py index 1f24b88..d5b8bfc 100644 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -108,40 +108,38 @@ class Controller(): Publisher.subscribe(self.OnSaveProject, 'Save project') - def SetBitmapSpacing(self, pubsub_evt): + def SetBitmapSpacing(self, spacing): proj = prj.Project() - proj.spacing = pubsub_evt.data + proj.spacing = spacing - def OnCancelImport(self, pubsub_evt): + def OnCancelImport(self): #self.cancel_import = True Publisher.sendMessage('Hide import panel') - def OnCancelImportBitmap(self, pubsub_evt): + def OnCancelImportBitmap(self): #self.cancel_import = True Publisher.sendMessage('Hide import bitmap panel') ########################### ########################### - def OnShowDialogImportDirectory(self, pubsub_evt): + def OnShowDialogImportDirectory(self): self.ShowDialogImportDirectory() - def OnShowDialogImportOtherFiles(self, pubsub_evt): - id_type = pubsub_evt.data + def OnShowDialogImportOtherFiles(self, id_type): self.ShowDialogImportOtherFiles(id_type) - def OnShowDialogOpenProject(self, pubsub_evt): + def OnShowDialogOpenProject(self): self.ShowDialogOpenProject() - def OnShowDialogSaveProject(self, pubsub_evt): - saveas = pubsub_evt.data - self.ShowDialogSaveProject(saveas) + def OnShowDialogSaveProject(self, save_as): + self.ShowDialogSaveProject(save_as) - def OnShowDialogCloseProject(self, pubsub_evt): + def OnShowDialogCloseProject(self): self.ShowDialogCloseProject() - def OnShowBitmapFile(self, pubsub_evt): + def OnShowBitmapFile(self): self.ShowDialogImportBitmapFile() ########################### @@ -155,10 +153,10 @@ class Controller(): if answer: self.ShowDialogSaveProject() self.CloseProject() - #Publisher.sendMessage("Enable state project", False) + #Publisher.sendMessage("Enable state project", state=False) Publisher.sendMessage('Set project name') Publisher.sendMessage("Stop Config Recording") - Publisher.sendMessage("Set slice interaction style", const.STATE_DEFAULT) + Publisher.sendMessage("Set slice interaction style", style=const.STATE_DEFAULT) # Import TIFF, BMP, JPEG or PNG dirpath = dialog.ShowImportBitmapDirDialog(self.frame) @@ -179,10 +177,10 @@ class Controller(): if answer: self.ShowDialogSaveProject() self.CloseProject() - #Publisher.sendMessage("Enable state project", False) + #Publisher.sendMessage("Enable state project", state=False) Publisher.sendMessage('Set project name') Publisher.sendMessage("Stop Config Recording") - Publisher.sendMessage("Set slice interaction style", const.STATE_DEFAULT) + Publisher.sendMessage("Set slice interaction style", style=const.STATE_DEFAULT) # Import project dirpath = dialog.ShowImportDirDialog(self.frame) if dirpath and not os.listdir(dirpath): @@ -200,17 +198,17 @@ class Controller(): if answer: self.ShowDialogSaveProject() self.CloseProject() - # Publisher.sendMessage("Enable state project", False) + # Publisher.sendMessage("Enable state project", state=False) Publisher.sendMessage('Set project name') Publisher.sendMessage("Stop Config Recording") - Publisher.sendMessage("Set slice interaction style", const.STATE_DEFAULT) + Publisher.sendMessage("Set slice interaction style", style=const.STATE_DEFAULT) # Warning for limited support to Analyze format if id_type == const.ID_ANALYZE_IMPORT: dialog.ImportAnalyzeWarning() filepath = dialog.ShowImportOtherFilesDialog(id_type) - Publisher.sendMessage("Open other files", filepath) + Publisher.sendMessage("Open other files", filepath=filepath) def ShowDialogOpenProject(self): # Offer to save current project if necessary @@ -265,21 +263,21 @@ class Controller(): if not answer: utils.debug("Close without changes") self.CloseProject() - Publisher.sendMessage("Enable state project", False) + Publisher.sendMessage("Enable state project", state=False) Publisher.sendMessage('Set project name') Publisher.sendMessage("Stop Config Recording") elif answer == 1: self.ShowDialogSaveProject() utils.debug("Save changes and close") self.CloseProject() - Publisher.sendMessage("Enable state project", False) + Publisher.sendMessage("Enable state project", state=False) Publisher.sendMessage('Set project name') Publisher.sendMessage("Stop Config Recording") elif answer == -1: utils.debug("Cancel") else: self.CloseProject() - Publisher.sendMessage("Enable state project", False) + Publisher.sendMessage("Enable state project", state=False) Publisher.sendMessage('Set project name') Publisher.sendMessage("Stop Config Recording") @@ -288,13 +286,10 @@ class Controller(): ########################### - def OnOpenProject(self, pubsub_evt): - path = pubsub_evt.data - self.OpenProject(path) - - def OnOpenRecentProject(self, pubsub_evt): - filepath = pubsub_evt.data + def OnOpenProject(self, filepath): + self.OpenProject(filepath) + def OnOpenRecentProject(self, filepath): if os.path.exists(filepath): session = ses.Session() st = session.project_status @@ -325,17 +320,16 @@ class Controller(): self.Slice.window_width = proj.window Publisher.sendMessage('Update threshold limits list', - proj.threshold_range) + threshold_range=proj.threshold_range) self.LoadProject() session = ses.Session() session.OpenProject(filepath) - Publisher.sendMessage("Enable state project", True) + Publisher.sendMessage("Enable state project", state=True) - def OnSaveProject(self, pubsub_evt): - path = pubsub_evt.data - self.SaveProject(path) + def OnSaveProject(self, filepath): + self.SaveProject(filepath) def SaveProject(self, path=None, compress=False): Publisher.sendMessage('Begin busy cursor') @@ -356,7 +350,7 @@ class Controller(): Publisher.sendMessage('End busy cursor') def CloseProject(self): - Publisher.sendMessage('Set slice interaction style', const.STATE_DEFAULT) + Publisher.sendMessage('Set slice interaction style', style=const.STATE_DEFAULT) Publisher.sendMessage('Hide content panel') Publisher.sendMessage('Close project data') @@ -390,8 +384,7 @@ class Controller(): reader.SetDirectoryPath(path) Publisher.sendMessage('End busy cursor') - def Progress(self, evt): - data = evt.data + def Progress(self, data): if (data): message = _("Loading file %d of %d ...")%(data[0],data[1]) if not(self.progress_dialog): @@ -408,19 +401,17 @@ class Controller(): self.progress_dialog.Close() self.progress_dialog = None - def OnLoadImportPanel(self, evt): - patient_series = evt.data + def OnLoadImportPanel(self, patient_series): ok = self.LoadImportPanel(patient_series) if ok: Publisher.sendMessage('Show import panel') Publisher.sendMessage("Show import panel in frame") self.img_type = 1 - def OnLoadImportBitmapPanel(self, evt): - data = evt.data + def OnLoadImportBitmapPanel(self, data): ok = self.LoadImportBitmapPanel(data) if ok: - Publisher.sendMessage('Show import bitmap panel in frame') + Publisher.sendMessage('Show import bitmap panel in frame') self.img_type = 2 #Publisher.sendMessage("Show import panel in invesalius.gui.frame") as frame @@ -430,7 +421,7 @@ class Controller(): #first_patient = patient_series[0] #Publisher.sendMessage("Load bitmap preview", first_patient) if data: - Publisher.sendMessage("Load import bitmap panel", data) + Publisher.sendMessage("Load import bitmap panel", data=data) return True else: dialog.ImportInvalidFiles("Bitmap") @@ -439,9 +430,9 @@ class Controller(): def LoadImportPanel(self, patient_series): if patient_series and isinstance(patient_series, list): - Publisher.sendMessage("Load import panel", patient_series) + Publisher.sendMessage("Load import panel", dicom_groups=patient_series) first_patient = patient_series[0] - Publisher.sendMessage("Load dicom preview", first_patient) + Publisher.sendMessage("Load dicom preview", patient=first_patient) return True else: dialog.ImportInvalidFiles("DICOM") @@ -450,10 +441,8 @@ class Controller(): #----------- to import by command line --------------------------------------------------- - def OnImportMedicalImages(self, pubsub_evt): - directory = pubsub_evt.data['directory'] - gui = pubsub_evt.data['gui'] - self.ImportMedicalImages(directory, gui) + def OnImportMedicalImages(self, directory, use_gui): + self.ImportMedicalImages(directory, use_gui) def ImportMedicalImages(self, directory, gui=True): patients_groups = dcm.GetDicomGroups(directory) @@ -484,19 +473,17 @@ class Controller(): # OPTION 4: Nothing... self.LoadProject() - Publisher.sendMessage("Enable state project", True) + Publisher.sendMessage("Enable state project", state=True) - def OnImportGroup(self, pubsub_evt): - group = pubsub_evt.data['group'] - gui = pubsub_evt.data['gui'] - self.ImportGroup(group, gui) + def OnImportGroup(self, group, use_gui): + self.ImportGroup(group, use_gui) def ImportGroup(self, group, gui=True): matrix, matrix_filename, dicom = self.OpenDicomGroup(group, 0, [0, 0], gui=gui) self.CreateDicomProject(dicom, matrix, matrix_filename) self.LoadProject() - Publisher.sendMessage("Enable state project", True) + Publisher.sendMessage("Enable state project", state=True) #------------------------------------------------------------------------------------- @@ -514,21 +501,23 @@ class Controller(): self.Slice.spacing = proj.spacing Publisher.sendMessage('Load slice to viewer', - (proj.mask_dict)) + mask_dict=proj.mask_dict) Publisher.sendMessage('Load slice plane') - Publisher.sendMessage('Bright and contrast adjustment image',\ - (proj.window, proj.level)) - Publisher.sendMessage('Update window level value',\ - (proj.window, proj.level)) + Publisher.sendMessage('Bright and contrast adjustment image', + window=proj.window, + level=proj.level) + Publisher.sendMessage('Update window level value', + window=proj.window, + level=proj.level) - Publisher.sendMessage('Set project name', proj.name) + Publisher.sendMessage('Set project name', proj_name=proj.name) Publisher.sendMessage('Load surface dict', - proj.surface_dict) + surface_dict=proj.surface_dict) Publisher.sendMessage('Hide surface items', - proj.surface_dict) + surface_dict=proj.surface_dict) self.LoadImagedataInfo() # TODO: where do we insert this << 0: - Publisher.sendMessage('Set edition brush size', size) + Publisher.sendMessage('Set edition brush size', size=size) cursor.SetPosition(cursor.position) self.viewer.interactor.Render() else: @@ -1005,23 +1008,23 @@ class WatershedConfig(with_metaclass(utils.Singleton, object)): Publisher.subscribe(self.set_3dcon, "Set watershed 3d con") Publisher.subscribe(self.set_gaussian_size, "Set watershed gaussian size") - def set_operation(self, pubsub_evt): - self.operation = WATERSHED_OPERATIONS[pubsub_evt.data] + def set_operation(self, operation): + self.operation = WATERSHED_OPERATIONS[operation] - def set_use_ww_wl(self, pubsub_evt): - self.use_ww_wl = pubsub_evt.data + def set_use_ww_wl(self, use_ww_wl): + self.use_ww_wl = use_ww_wl - def set_algorithm(self, pubsub_evt): - self.algorithm = pubsub_evt.data + def set_algorithm(self, algorithm): + self.algorithm = algorithm - def set_2dcon(self, pubsub_evt): - self.con_2d = pubsub_evt.data + def set_2dcon(self, con_2d): + self.con_2d = con_2d - def set_3dcon(self, pubsub_evt): - self.con_3d = pubsub_evt.data + def set_3dcon(self, con_3d): + self.con_3d = con_3d - def set_gaussian_size(self, pubsub_evt): - self.mg_size = pubsub_evt.data + def set_gaussian_size(self, size): + self.mg_size = size WALGORITHM = {"Watershed": watershed, "Watershed IFT": watershed_ift} @@ -1124,13 +1127,12 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): cursor.SetSize(self.config.cursor_size) self.viewer.slice_data.SetCursor(cursor) - def set_bsize(self, pubsub_evt): - size = pubsub_evt.data + def set_bsize(self, size): self.config.cursor_size = size self.viewer.slice_data.cursor.SetSize(size) - def set_bformat(self, pubsub_evt): - self.config.cursor_type = pubsub_evt.data + def set_bformat(self, brush_format): + self.config.cursor_type = brush_format self._set_cursor() def OnEnterInteractor(self, obj, evt): @@ -1157,7 +1159,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): size -= 1 if size > 0: - Publisher.sendMessage('Set watershed brush size', size) + Publisher.sendMessage('Set watershed brush size', size=size) cursor.SetPosition(cursor.position) self.viewer.interactor.Render() else: @@ -1175,7 +1177,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): size += 1 if size <= 100: - Publisher.sendMessage('Set watershed brush size', size) + Publisher.sendMessage('Set watershed brush size', size=size) cursor.SetPosition(cursor.position) self.viewer.interactor.Render() else: @@ -1423,7 +1425,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): if roi_m.size: roi_m[index] = operation - def expand_watershed(self, pubsub_evt): + def expand_watershed(self): markers = self.matrix image = self.viewer.slice_.matrix self.viewer.slice_.do_threshold_to_all_slices() @@ -1631,7 +1633,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): self.viewer.slice_.rotations = [0, 0, 0] self.viewer.slice_.q_orientation = np.array((1, 0, 0, 0)) - Publisher.sendMessage('Update reorient angles', (0, 0, 0)) + Publisher.sendMessage('Update reorient angles', angles=(0, 0, 0)) self._discard_buffers() self.viewer.slice_.current_mask.clear_history() @@ -1687,7 +1689,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): self.viewer.slice_.q_orientation = transformations.quaternion_multiply(self.viewer.slice_.q_orientation, transformations.quaternion_about_axis(angle, axis)) az, ay, ax = transformations.euler_from_quaternion(self.viewer.slice_.q_orientation) - Publisher.sendMessage('Update reorient angles', (ax, ay, az)) + Publisher.sendMessage('Update reorient angles', angles=(ax, ay, az)) self._discard_buffers() if self.viewer.slice_.current_mask: @@ -1713,8 +1715,8 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): # print (z, y, x), tcoord return tcoord - def _set_reorientation_angles(self, pubsub_evt): - ax, ay, az = pubsub_evt.data + def _set_reorientation_angles(self, angles): + ax, ay, az = angles q = transformations.quaternion_from_euler(az, ay, ax) self.viewer.slice_.q_orientation = q @@ -1968,9 +1970,8 @@ class CropMaskInteractorStyle(DefaultInteractorStyle): self.viewer.canvas.draw_list.remove(self.draw_retangle) Publisher.sendMessage('Redraw canvas') - def CropMask(self, pubsub_evt): + def CropMask(self): if self.viewer.orientation == "AXIAL": - xi, xf, yi, yf, zi, zf = self.draw_retangle.box.GetLimits() xi += 1 @@ -1978,7 +1979,7 @@ class CropMaskInteractorStyle(DefaultInteractorStyle): yi += 1 yf += 1 - + zi += 1 zf += 1 @@ -1986,13 +1987,13 @@ class CropMaskInteractorStyle(DefaultInteractorStyle): cp_mask = self.viewer.slice_.current_mask.matrix.copy() tmp_mask = self.viewer.slice_.current_mask.matrix[zi-1:zf+1, yi-1:yf+1, xi-1:xf+1].copy() - + self.viewer.slice_.current_mask.matrix[:] = 1 self.viewer.slice_.current_mask.matrix[zi-1:zf+1, yi-1:yf+1, xi-1:xf+1] = tmp_mask self.viewer.slice_.current_mask.save_history(0, 'VOLUME', self.viewer.slice_.current_mask.matrix.copy(), cp_mask) - + self.viewer.slice_.buffer_slices['AXIAL'].discard_mask() self.viewer.slice_.buffer_slices['CORONAL'].discard_mask() self.viewer.slice_.buffer_slices['SAGITAL'].discard_mask() @@ -2002,9 +2003,9 @@ class CropMaskInteractorStyle(DefaultInteractorStyle): self.viewer.slice_.buffer_slices['SAGITAL'].discard_vtk_mask() self.viewer.slice_.current_mask.was_edited = True - Publisher.sendMessage('Reload actual slice') + Publisher.sendMessage('Reload actual slice') + - class SelectPartConfig(with_metaclass(utils.Singleton, object)): def __init__(self): self.mask = None @@ -2066,7 +2067,7 @@ class SelectMaskPartsInteractorStyle(DefaultInteractorStyle): self.config.mask.name = self.config.mask_name self.viewer.slice_._add_mask_into_proj(self.config.mask) self.viewer.slice_.SelectCurrentMask(self.config.mask.index) - Publisher.sendMessage('Change mask selected', self.config.mask.index) + Publisher.sendMessage('Change mask selected', index=self.config.mask.index) del self.viewer.slice_.aux_matrices['SELECT'] self.viewer.slice_.to_show_aux = '' diff --git a/invesalius/data/surface.py b/invesalius/data/surface.py index 0ab79af..fbc41ae 100644 --- a/invesalius/data/surface.py +++ b/invesalius/data/surface.py @@ -171,11 +171,10 @@ class SurfaceManager(): Publisher.subscribe(self.OnImportSurfaceFile, 'Import surface file') - def OnDuplicate(self, pubsub_evt): - selected_items = pubsub_evt.data + def OnDuplicate(self, surface_indexes): proj = prj.Project() surface_dict = proj.surface_dict - for index in selected_items: + for index in surface_indexes: original_surface = surface_dict[index] # compute copy name name = original_surface.name @@ -190,14 +189,13 @@ class SurfaceManager(): volume = original_surface.volume, area = original_surface.area) - def OnRemove(self, pubsub_evt): - selected_items = pubsub_evt.data + def OnRemove(self, surface_indexes): proj = prj.Project() old_dict = self.actors_dict new_dict = {} - if selected_items: - for index in selected_items: + if surface_indexes: + for index in surface_indexes: proj.RemoveSurface(index) if index in old_dict: actor = old_dict[index] @@ -207,21 +205,21 @@ class SurfaceManager(): if i > index: new_dict[i-1] = old_dict[i] old_dict = new_dict - Publisher.sendMessage('Remove surface actor from viewer', actor) + Publisher.sendMessage('Remove surface actor from viewer', actor=actor) self.actors_dict = new_dict - if self.last_surface_index in selected_items: + if self.last_surface_index in surface_indexes: if self.actors_dict: self.last_surface_index = 0 else: self.last_surface_index = None - def OnSeedSurface(self, pubsub_evt): + def OnSeedSurface(self, seeds): """ Create a new surface, based on the last selected surface, using as reference seeds user add to surface of reference. """ - points_id_list = pubsub_evt.data + points_id_list = seeds index = self.last_surface_index proj = prj.Project() surface = proj.surface_dict[index] @@ -229,10 +227,10 @@ class SurfaceManager(): new_polydata = pu.JoinSeedsParts(surface.polydata, points_id_list) index = self.CreateSurfaceFromPolydata(new_polydata) - Publisher.sendMessage('Show single surface', (index, True)) + Publisher.sendMessage('Show single surface', index=index, visibility=True) #self.ShowActor(index, True) - def OnSplitSurface(self, pubsub_evt): + def OnSplitSurface(self): """ Create n new surfaces, based on the last selected surface, according to their connectivity. @@ -248,9 +246,9 @@ class SurfaceManager(): index_list.append(index) #self.ShowActor(index, True) - Publisher.sendMessage('Show multiple surfaces', (index_list, True)) + Publisher.sendMessage('Show multiple surfaces', index_list=index_list, visibility=True) - def OnLargestSurface(self, pubsub_evt): + def OnLargestSurface(self): """ Create a new surface, based on largest part of the last selected surface. @@ -261,13 +259,12 @@ class SurfaceManager(): new_polydata = pu.SelectLargestPart(surface.polydata) new_index = self.CreateSurfaceFromPolydata(new_polydata) - Publisher.sendMessage('Show single surface', (new_index, True)) + Publisher.sendMessage('Show single surface', index=new_index, visibility=True) - def OnImportSurfaceFile(self, pubsub_evt): + def OnImportSurfaceFile(self, filename): """ Creates a new surface from a surface file (STL, PLY, OBJ or VTP) """ - filename = pubsub_evt.data self.CreateSurfaceFromFile(filename) def CreateSurfaceFromFile(self, filename): @@ -368,42 +365,34 @@ class SurfaceManager(): self.last_surface_index = surface.index - Publisher.sendMessage('Load surface actor into viewer', actor) + Publisher.sendMessage('Load surface actor into viewer', actor=actor) - Publisher.sendMessage('Update surface info in GUI', - (surface.index, surface.name, - surface.colour, surface.volume, - surface.area, surface.transparency)) + Publisher.sendMessage('Update surface info in GUI', surface=surface) return surface.index - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): self.CloseProject() def CloseProject(self): for index in self.actors_dict: - Publisher.sendMessage('Remove surface actor from viewer', self.actors_dict[index]) + Publisher.sendMessage('Remove surface actor from viewer', actor=self.actors_dict[index]) del self.actors_dict self.actors_dict = {} # restarting the surface index Surface.general_index = -1 - def OnSelectSurface(self, pubsub_evt): - index = pubsub_evt.data - #self.last_surface_index = index + def OnSelectSurface(self, surface_index): + #self.last_surface_index = surface_index # self.actors_dict. proj = prj.Project() - surface = proj.surface_dict[index] - Publisher.sendMessage('Update surface info in GUI', - (index, surface.name, - surface.colour, surface.volume, - surface.area, surface.transparency)) - self.last_surface_index = index + surface = proj.surface_dict[surface_index] + Publisher.sendMessage('Update surface info in GUI', surface=surface) + self.last_surface_index = surface_index # if surface.is_shown: - self.ShowActor(index, True) + self.ShowActor(surface_index, True) - def OnLoadSurfaceDict(self, pubsub_evt): - surface_dict = pubsub_evt.data + def OnLoadSurfaceDict(self, surface_dict): for key in surface_dict: surface = surface_dict[key] @@ -436,27 +425,23 @@ class SurfaceManager(): self.actors_dict[surface.index] = actor # Send actor by pubsub to viewer's render - Publisher.sendMessage('Load surface actor into viewer', (actor)) + Publisher.sendMessage('Load surface actor into viewer', actor=actor) Publisher.sendMessage('Update status text in GUI', - _("Ready")) + label=_("Ready")) # The following lines have to be here, otherwise all volumes disappear - Publisher.sendMessage('Update surface info in GUI', - (surface.index, surface.name, - surface.colour, surface.volume, - surface.area, surface.transparency)) + Publisher.sendMessage('Update surface info in GUI', surface=surface) if not surface.is_shown: self.ShowActor(key, False) #### #(mask_index, surface_name, quality, fill_holes, keep_largest) - def AddNewActor(self, pubsub_evt): + def AddNewActor(self, slice_, mask, surface_parameters): """ Create surface actor, save into project and send it to viewer. """ - slice_, mask, surface_parameters = pubsub_evt.data matrix = slice_.matrix filename_img = slice_.matrix_filename spacing = slice_.spacing @@ -825,31 +810,27 @@ class SurfaceManager(): del measured_polydata del to_measure - Publisher.sendMessage('Load surface actor into viewer', actor) + Publisher.sendMessage('Load surface actor into viewer', actor=actor) # Send actor by pubsub to viewer's render if overwrite and self.actors_dict.keys(): old_actor = self.actors_dict[self.last_surface_index] - Publisher.sendMessage('Remove surface actor from viewer', old_actor) + Publisher.sendMessage('Remove surface actor from viewer', actor=old_actor) # Save actor for future management tasks self.actors_dict[surface.index] = actor - Publisher.sendMessage('Update surface info in GUI', - (surface.index, surface.name, - surface.colour, surface.volume, - surface.area, - surface.transparency)) + Publisher.sendMessage('Update surface info in GUI', surface=surface) #When you finalize the progress. The bar is cleaned. UpdateProgress = vu.ShowProgress(1) UpdateProgress(0, _("Ready")) - Publisher.sendMessage('Update status text in GUI', _("Ready")) + Publisher.sendMessage('Update status text in GUI', label=_("Ready")) Publisher.sendMessage('End busy cursor') del actor - def UpdateSurfaceInterpolation(self, pub_evt): + def UpdateSurfaceInterpolation(self): interpolation = int(ses.Session().surface_interpolation) key_actors = self.actors_dict.keys() @@ -861,20 +842,18 @@ class SurfaceManager(): """ Remove actor, according to given actor index. """ - Publisher.sendMessage('Remove surface actor from viewer', (index)) + Publisher.sendMessage('Remove surface actor from viewer', actor=index) self.actors_dict.pop(index) # Remove surface from project's surface_dict proj = prj.Project() proj.surface_dict.pop(index) - def OnChangeSurfaceName(self, pubsub_evt): - index, name = pubsub_evt.data + def OnChangeSurfaceName(self, index, name): proj = prj.Project() proj.surface_dict[index].name = name - def OnShowSurface(self, pubsub_evt): - index, value = pubsub_evt.data - self.ShowActor(index, value) + def OnShowSurface(self, index, visibility): + self.ShowActor(index, visibility) def ShowActor(self, index, value): """ @@ -886,30 +865,27 @@ class SurfaceManager(): proj.surface_dict[index].is_shown = value Publisher.sendMessage('Render volume viewer') - def SetActorTransparency(self, pubsub_evt): + def SetActorTransparency(self, surface_index, transparency): """ Set actor transparency (oposite to opacity) according to given actor index and value. """ - index, value = pubsub_evt.data - self.actors_dict[index].GetProperty().SetOpacity(1-value) + self.actors_dict[surface_index].GetProperty().SetOpacity(1-transparency) # Update value in project's surface_dict proj = prj.Project() - proj.surface_dict[index].transparency = value + proj.surface_dict[surface_index].transparency = transparency Publisher.sendMessage('Render volume viewer') - def SetActorColour(self, pubsub_evt): + def SetActorColour(self, surface_index, colour): """ """ - index, colour = pubsub_evt.data - self.actors_dict[index].GetProperty().SetColor(colour[:3]) + self.actors_dict[surface_index].GetProperty().SetColor(colour[:3]) # Update value in project's surface_dict proj = prj.Project() - proj.surface_dict[index].colour = colour + proj.surface_dict[surface_index].colour = colour Publisher.sendMessage('Render volume viewer') - def OnExportSurface(self, pubsub_evt): - filename, filetype = pubsub_evt.data + def OnExportSurface(self, filename, filetype): ftype_prefix = { const.FILETYPE_STL: '.stl', const.FILETYPE_VTP: '.vtp', diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 085034e..0b34ce0 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -132,29 +132,27 @@ class ContourMIPConfig(wx.Panel): Publisher.subscribe(self._set_projection_type, 'Set projection type') - def OnSetMIPSize(self, evt): + def OnSetMIPSize(self, number_slices): val = self.mip_size_spin.GetValue() - Publisher.sendMessage('Set MIP size %s' % self.orientation, val) + Publisher.sendMessage('Set MIP size %s' % self.orientation, number_slices=val) def OnSetMIPBorder(self, evt): val = self.border_spin.GetValue() - Publisher.sendMessage('Set MIP border %s' % self.orientation, val) + Publisher.sendMessage('Set MIP border %s' % self.orientation, border_size=val) def OnCheckInverted(self, evt): val = self.inverted.GetValue() - Publisher.sendMessage('Set MIP Invert %s' % self.orientation, val) + Publisher.sendMessage('Set MIP Invert %s' % self.orientation, invert=val) - def _set_projection_type(self, pubsub_evt): - tprojection = pubsub_evt.data - - if tprojection in (const.PROJECTION_MIDA, - const.PROJECTION_CONTOUR_MIDA): + def _set_projection_type(self, projection_id): + if projection_id in (const.PROJECTION_MIDA, + const.PROJECTION_CONTOUR_MIDA): self.inverted.Enable() else: self.inverted.Disable() - if tprojection in (const.PROJECTION_CONTOUR_MIP, - const.PROJECTION_CONTOUR_MIDA): + if projection_id in (const.PROJECTION_CONTOUR_MIP, + const.PROJECTION_CONTOUR_MIDA): self.border_spin.Enable() self.txt_mip_border.Enable() else: @@ -664,8 +662,7 @@ class Viewer(wx.Panel): self.UpdateCanvas() self.on_text = True - def __set_layout(self, pubsub_evt): - layout = pubsub_evt.data + def __set_layout(self, layout): self.SetLayout(layout) def __config_interactor(self): @@ -693,8 +690,7 @@ class Viewer(wx.Panel): self.state = state - def UpdateWindowLevelValue(self, pubsub_evt): - window, level = pubsub_evt.data + def UpdateWindowLevelValue(self, window, level): self.acum_achange_window, self.acum_achange_level = (window, level) self.SetWLText(window, level) @@ -704,18 +700,18 @@ class Viewer(wx.Panel): Publisher.sendMessage('Update all slice') Publisher.sendMessage('Update clut imagedata widget') - def UpdateWindowLevelText(self, pubsub_evt): - window, level = pubsub_evt.data - self.acum_achange_window, self.acum_achange_level = (window, level) + def UpdateWindowLevelText(self, window, level): + self.acum_achange_window, self.acum_achange_level = window, level self.SetWLText(window, level) self.interactor.Render() def OnClutChange(self, evt): Publisher.sendMessage('Change colour table from background image from widget', - evt.GetNodes()) + nodes=evt.GetNodes()) slc = sl.Slice() Publisher.sendMessage('Update window level value', - (slc.window_width, slc.window_level)) + window=slc.window_width, + level=slc.window_level) def SetWLText(self, window_width, window_level): value = STR_WL%(window_level, window_width) @@ -930,46 +926,45 @@ class Viewer(wx.Panel): ren.GetActiveCamera().Zoom(1.0) self.interactor.Render() - def ChangeBrushColour(self, pubsub_evt): - vtk_colour = pubsub_evt.data[3] + def ChangeBrushColour(self, colour): + vtk_colour = colour self._brush_cursor_colour = vtk_colour if (self.cursor): for slice_data in self.slice_data_list: slice_data.cursor.SetColour(vtk_colour) - def SetBrushColour(self, pubsub_evt): - colour_wx = pubsub_evt.data - colour_vtk = [colour/float(255) for colour in colour_wx] + def SetBrushColour(self, colour): + colour_vtk = [colour/float(255) for colour in colour] self._brush_cursor_colour = colour_vtk if self.slice_data.cursor: self.slice_data.cursor.SetColour(colour_vtk) - def UpdateSlicesNavigation(self, pubsub_evt): + def UpdateSlicesNavigation(self, arg, position): # Get point from base change - ux, uy, uz = pubsub_evt.data[1][:3] + ux, uy, uz = position[:3] px, py = self.get_slice_pixel_coord_by_world_pos(ux, uy, uz) coord = self.calcultate_scroll_position(px, py) self.cross.SetFocalPoint((ux, uy, uz)) self.ScrollSlice(coord) - Publisher.sendMessage('Set ball reference position', (ux, uy, uz)) + Publisher.sendMessage('Set ball reference position', position=(ux, uy, uz)) def ScrollSlice(self, coord): if self.orientation == "AXIAL": Publisher.sendMessage(('Set scroll position', 'SAGITAL'), - coord[0]) + index=coord[0]) Publisher.sendMessage(('Set scroll position', 'CORONAL'), - coord[1]) + index=coord[1]) elif self.orientation == "SAGITAL": Publisher.sendMessage(('Set scroll position', 'AXIAL'), - coord[2]) + index=coord[2]) Publisher.sendMessage(('Set scroll position', 'CORONAL'), - coord[1]) + index=coord[1]) elif self.orientation == "CORONAL": Publisher.sendMessage(('Set scroll position', 'AXIAL'), - coord[2]) + index=coord[2]) Publisher.sendMessage(('Set scroll position', 'SAGITAL'), - coord[0]) + index=coord[0]) def get_slice_data(self, render): #for slice_data in self.slice_data_list: @@ -1251,39 +1246,37 @@ class Viewer(wx.Panel): Publisher.subscribe(self.UpdateInterpolatedSlice, "Update Slice Interpolation") - def RefreshViewer(self, pubsub_evt): + def RefreshViewer(self): self.Refresh() - def SetDefaultCursor(self, pusub_evt): + def SetDefaultCursor(self): self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) - def SetSizeNSCursor(self, pusub_evt): + def SetSizeNSCursor(self): self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) - def SetSizeWECursor(self, pusub_evt): + def SetSizeWECursor(self): self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZEWE)) - def SetSizeNWSECursor(self, pubsub_evt): + def SetSizeNWSECursor(self): if sys.platform.startswith('linux'): self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENWSE)) else: self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) - def OnExportPicture(self, pubsub_evt): - id, filename, filetype = pubsub_evt.data - + def OnExportPicture(self, orientation, filename, filetype): dict = {"AXIAL": const.AXIAL, "CORONAL": const.CORONAL, "SAGITAL": const.SAGITAL} - if id == dict[self.orientation]: + if orientation == dict[self.orientation]: Publisher.sendMessage('Begin busy cursor') if _has_win32api: utils.touch(filename) win_filename = win32api.GetShortPathName(filename) - self._export_picture(id, win_filename, filetype) + self._export_picture(orientation, win_filename, filetype) else: - self._export_picture(id, filename, filetype) + self._export_picture(orientation, filename, filetype) Publisher.sendMessage('End busy cursor') def _export_picture(self, id, filename, filetype): @@ -1340,13 +1333,13 @@ class Viewer(wx.Panel): Publisher.sendMessage('End busy cursor') - def OnShowText(self, pubsub_evt): + def OnShowText(self): self.ShowTextActors() - def OnHideText(self, pubsub_evt): + def OnHideText(self): self.HideTextActors() - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): self.CloseProject() def CloseProject(self): @@ -1371,11 +1364,10 @@ class Viewer(wx.Panel): self.wl_text = None self.pick = vtk.vtkWorldPointPicker() - def OnSetInteractorStyle(self, pubsub_evt): - state = pubsub_evt.data - self.SetInteractorStyle(state) + def OnSetInteractorStyle(self, style): + self.SetInteractorStyle(style) - if (state not in [const.SLICE_STATE_EDITOR, const.SLICE_STATE_WATERSHED]): + if (style not in [const.SLICE_STATE_EDITOR, const.SLICE_STATE_WATERSHED]): Publisher.sendMessage('Set interactor default cursor') def __bind_events_wx(self): @@ -1386,8 +1378,7 @@ class Viewer(wx.Panel): self.interactor.Bind(wx.EVT_RIGHT_UP, self.OnContextMenu) self.interactor.Bind(wx.EVT_SIZE, self.OnSize) - def LoadImagedata(self, pubsub_evt): - mask_dict = pubsub_evt.data + def LoadImagedata(self, mask_dict): self.SetInput(mask_dict) def LoadRenderers(self, imagedata): @@ -1509,9 +1500,8 @@ class Viewer(wx.Panel): renderer.AddActor(cross_actor) - def __update_cross_position(self, pubsub_evt): - pos = pubsub_evt.data - self.cross.SetFocalPoint(pos) + def __update_cross_position(self, position): + self.cross.SetFocalPoint(position) def _set_cross_visibility(self, visibility): self.cross_actor.SetVisibility(visibility) @@ -1569,8 +1559,8 @@ class Viewer(wx.Panel): return slice_data - def UpdateInterpolatedSlice(self, pub_sub): - if self.slice_actor != None: + def UpdateInterpolatedSlice(self): + if self.slice_actor != None: if ses.Session().slice_interpolation: self.slice_actor.InterpolateOff() else: @@ -1578,15 +1568,13 @@ class Viewer(wx.Panel): self.interactor.Render() - def SetInterpolatedSlices(self, pub_sub): - self.interpolation_slice_status = status = pub_sub.data - + def SetInterpolatedSlices(self, flag): + self.interpolation_slice_status = flag if self.slice_actor != None: - if status == True: + if self.interpolation_slice_status == True: self.slice_actor.InterpolateOn() else: self.slice_actor.InterpolateOff() - self.interactor.Render() def __update_camera(self): @@ -1605,7 +1593,7 @@ class Viewer(wx.Panel): self.slice_data.actor.SetDisplayExtent(image.GetExtent()) self.slice_data.renderer.ResetCameraClippingRange() - def UpdateRender(self, evt): + def UpdateRender(self): self.interactor.Render() def UpdateCanvas(self, evt=None): @@ -1655,8 +1643,8 @@ class Viewer(wx.Panel): def UpdateSlice3D(self, pos): original_orientation = project.Project().original_orientation pos = self.scroll.GetThumbPosition() - Publisher.sendMessage('Change slice from slice plane',\ - (self.orientation, pos)) + Publisher.sendMessage('Change slice from slice plane', + orientation=self.orientation, index=pos) def OnScrollBar(self, evt=None, update3D=True): pos = self.scroll.GetThumbPosition() @@ -1667,7 +1655,7 @@ class Viewer(wx.Panel): # Update other slice's cross according to the new focal point from # the actual orientation. focal_point = self.cross.GetFocalPoint() - Publisher.sendMessage('Update cross position', focal_point) + Publisher.sendMessage('Update cross position', position=focal_point) Publisher.sendMessage('Update slice viewer') else: self.interactor.Render() @@ -1722,7 +1710,7 @@ class Viewer(wx.Panel): elif evt.GetKeyCode() in projections: self.slice_.SetTypeProjection(projections[evt.GetKeyCode()]) - Publisher.sendMessage('Set projection type', projections[evt.GetKeyCode()]) + Publisher.sendMessage('Set projection type', projection_id=projections[evt.GetKeyCode()]) Publisher.sendMessage('Reload actual slice') skip = False @@ -1766,28 +1754,24 @@ class Viewer(wx.Panel): self.slice_data.SetSize((w, h)) evt.Skip() - def OnSetMIPSize(self, pubsub_evt): - val = pubsub_evt.data - self.number_slices = val + def OnSetMIPSize(self, number_slices): + self.number_slices = number_slices self.ReloadActualSlice() - def OnSetMIPBorder(self, pubsub_evt): - val = pubsub_evt.data - self.slice_.n_border = val + def OnSetMIPBorder(self, border_size): + self.slice_.n_border = border_size buffer_ = self.slice_.buffer_slices[self.orientation] buffer_.discard_buffer() self.ReloadActualSlice() - def OnSetMIPInvert(self, pubsub_evt): - val = pubsub_evt.data - self._mip_inverted = val + def OnSetMIPInvert(self, invert): + self._mip_inverted = invert buffer_ = self.slice_.buffer_slices[self.orientation] buffer_.discard_buffer() self.ReloadActualSlice() - def OnShowMIPInterface(self, pubsub_evt): - value = pubsub_evt.data - if value: + def OnShowMIPInterface(self, flag): + if flag: if not self.mip_ctrls.Shown: self.mip_ctrls.Show() self.GetSizer().Add(self.mip_ctrls, 0, wx.EXPAND|wx.GROW|wx.ALL, 2) @@ -1797,9 +1781,8 @@ class Viewer(wx.Panel): self.GetSizer().Detach(self.mip_ctrls) self.Layout() - def OnSetOverwriteMask(self, pubsub_evt): - value = pubsub_evt.data - self.overwrite_mask = value + def OnSetOverwriteMask(self, flag): + self.overwrite_mask = flag def set_slice_number(self, index): inverted = self.mip_ctrls.inverted.GetValue() @@ -1831,28 +1814,27 @@ class Viewer(wx.Panel): self.__update_display_extent(image) self.cross.SetModelBounds(self.slice_data.actor.GetBounds()) - def ChangeSliceNumber(self, pubsub_evt): - index = pubsub_evt.data + def ChangeSliceNumber(self, index): #self.set_slice_number(index) self.scroll.SetThumbPosition(index) pos = self.scroll.GetThumbPosition() self.set_slice_number(pos) self.interactor.Render() - def ReloadActualSlice(self, pubsub_evt=None): + def ReloadActualSlice(self): pos = self.scroll.GetThumbPosition() self.set_slice_number(pos) self.interactor.Render() - def OnUpdateScroll(self, pubsub_evt): + def OnUpdateScroll(self): max_slice_number = sl.Slice().GetNumberOfSlices(self.orientation) self.scroll.SetScrollbar(wx.SB_VERTICAL, 1, max_slice_number, max_slice_number) - def OnSwapVolumeAxes(self, pubsub_evt): + def OnSwapVolumeAxes(self, axes): # Adjusting cursor spacing to match the spacing from the actual slice # orientation - axis0, axis1 = pubsub_evt.data + axis0, axis1 = axes cursor = self.slice_data.cursor spacing = cursor.spacing if (axis0, axis1) == (2, 1): @@ -1864,34 +1846,32 @@ class Viewer(wx.Panel): self.slice_data.renderer.ResetCamera() - def AddActors(self, pubsub_evt): + def AddActors(self, actors, slice_number): "Inserting actors" - actors, n = pubsub_evt.data pos = self.scroll.GetThumbPosition() #try: - #renderer = self.renderers_by_slice_number[n] + #renderer = self.renderers_by_slice_number[slice_number] #for actor in actors: #renderer.AddActor(actor) #except KeyError: #pass - if pos == n: + if pos == slice_number: for actor in actors: self.slice_data.renderer.AddActor(actor) - self.actors_by_slice_number[n].extend(actors) + self.actors_by_slice_number[slice_number].extend(actors) - def RemoveActors(self, pubsub_evt): + def RemoveActors(self, actors, slice_number): "Remove a list of actors" - actors, n = pubsub_evt.data try: - renderer = self.renderers_by_slice_number[n] + renderer = self.renderers_by_slice_number[slice_number] except KeyError: for actor in actors: - self.actors_by_slice_number[n].remove(actor) + self.actors_by_slice_number[slice_number].remove(actor) self.slice_data.renderer.RemoveActor(actor) else: for actor in actors: # Remove the actor from the renderer renderer.RemoveActor(actor) # and remove the actor from the actor's list - self.actors_by_slice_number[n].remove(actor) + self.actors_by_slice_number[slice_number].remove(actor) diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index d238341..3de5335 100755 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -264,8 +264,7 @@ class Viewer(wx.Panel): Publisher.subscribe(self.OnUpdateAngleThreshold, 'Update angle threshold') Publisher.subscribe(self.OnUpdateDistThreshold, 'Update dist threshold') - def SetStereoMode(self, pubsub_evt): - mode = pubsub_evt.data + def SetStereoMode(self, mode): ren_win = self.interactor.GetRenderWindow() if mode == const.STEREO_OFF: @@ -293,23 +292,19 @@ class Viewer(wx.Panel): self.interactor.Render() - def _check_ball_reference(self, pubsub_evt): - st = pubsub_evt.data - if st == const.SLICE_STATE_CROSS: + def _check_ball_reference(self, style): + if style == const.SLICE_STATE_CROSS: self._mode_cross = True self._check_and_set_ball_visibility() self.interactor.Render() - def _uncheck_ball_reference(self, pubsub_evt): - st = pubsub_evt.data - if st == const.SLICE_STATE_CROSS: + def _uncheck_ball_reference(self, style): + if style == const.SLICE_STATE_CROSS: self._mode_cross = False self.RemoveBallReference() self.interactor.Render() - def OnSensors(self, pubsub_evt): - probe_id = pubsub_evt.data[0] - ref_id = pubsub_evt.data[1] + def OnSensors(self, probe_id, ref_id): if not self.sen1: self.CreateSensorID() @@ -345,39 +340,36 @@ class Viewer(wx.Panel): self.interactor.Render() - def OnRemoveSensorsID(self, pubsub_evt): + def OnRemoveSensorsID(self): if self.sen1: self.ren.RemoveActor(self.sen1.actor) self.ren.RemoveActor(self.sen2.actor) self.sen1 = self.sen2 = False self.interactor.Render() - def OnShowSurface(self, pubsub_evt): - index, value = pubsub_evt.data - if value: + def OnShowSurface(self, index, visibility): + if visibility: self._to_show_ball += 1 else: self._to_show_ball -= 1 self._check_and_set_ball_visibility() - def OnStartSeed(self, pubsub_evt): - index = pubsub_evt.data + def OnStartSeed(self): self.seed_points = [] - def OnEndSeed(self, pubsub_evt): + def OnEndSeed(self): Publisher.sendMessage("Create surface from seeds", - self.seed_points) + seeds=self.seed_points) - def OnExportPicture(self, pubsub_evt): - id, filename, filetype = pubsub_evt.data - if id == const.VOLUME: + def OnExportPicture(self, orientation, filename, filetype): + if orientation == const.VOLUME: Publisher.sendMessage('Begin busy cursor') if _has_win32api: utils.touch(filename) win_filename = win32api.GetShortPathName(filename) - self._export_picture(id, win_filename, filetype) + self._export_picture(orientation, win_filename, filetype) else: - self._export_picture(id, filename, filetype) + self._export_picture(orientation, filename, filetype) Publisher.sendMessage('End busy cursor') def _export_picture(self, id, filename, filetype): @@ -419,7 +411,7 @@ class Viewer(wx.Panel): wx.MessageBox(_("InVesalius was not able to export this picture"), _("Export picture error")) - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): if self.raycasting_volume: self.raycasting_volume = False @@ -436,22 +428,21 @@ class Viewer(wx.Panel): self.SetInteractorStyle(const.STATE_DEFAULT) self._last_state = const.STATE_DEFAULT - def OnHideText(self, pubsub_evt): + def OnHideText(self): self.text.Hide() self.interactor.Render() - def OnShowText(self, pubsub_evt): + def OnShowText(self): if self.on_wl: self.text.Show() self.interactor.Render() - def AddActors(self, pubsub_evt): + def AddActors(self, actors): "Inserting actors" - actors = pubsub_evt.data[0] for actor in actors: self.ren.AddActor(actor) - def RemoveVolume(self, pub_evt): + def RemoveVolume(self): volumes = self.ren.GetVolumes() if (volumes.GetNumberOfItems()): self.ren.RemoveVolume(volumes.GetLastProp()) @@ -459,9 +450,8 @@ class Viewer(wx.Panel): self._to_show_ball -= 1 self._check_and_set_ball_visibility() - def RemoveActors(self, pubsub_evt): + def RemoveActors(self, actors): "Remove a list of actors" - actors = pubsub_evt.data[0] for actor in actors: self.ren.RemoveActor(actor) @@ -501,25 +491,22 @@ class Viewer(wx.Panel): actor = self.points_reference.pop(point) self.ren.RemoveActor(actor) - def AddMarker(self, pubsub_evt): + def AddMarker(self, ball_id, size, colour, coord): """ Markers created by navigation tools and rendered in volume viewer. """ - self.ball_id = pubsub_evt.data[0] - ballsize = pubsub_evt.data[1] - ballcolour = pubsub_evt.data[2][:3] - coord = pubsub_evt.data[3] + self.ball_id = ball_id x, y, z = bases.flip_x(coord) ball_ref = vtk.vtkSphereSource() - ball_ref.SetRadius(ballsize) + ball_ref.SetRadius(size) ball_ref.SetCenter(x, y, z) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(ball_ref.GetOutputPort()) prop = vtk.vtkProperty() - prop.SetColor(ballcolour) + prop.SetColor(colour) #adding a new actor for the present ball self.staticballs.append(vtk.vtkActor()) @@ -532,38 +519,37 @@ class Viewer(wx.Panel): #self.UpdateRender() self.Refresh() - def HideAllMarkers(self, pubsub_evt): - ballid = pubsub_evt.data + def HideAllMarkers(self, indexes): + ballid = indexes for i in range(0, ballid): self.staticballs[i].SetVisibility(0) self.UpdateRender() - def ShowAllMarkers(self, pubsub_evt): - ballid = pubsub_evt.data + def ShowAllMarkers(self, indexes): + ballid = indexes for i in range(0, ballid): self.staticballs[i].SetVisibility(1) self.UpdateRender() - def RemoveAllMarkers(self, pubsub_evt): - ballid = pubsub_evt.data + def RemoveAllMarkers(self, indexes): + ballid = indexes for i in range(0, ballid): self.ren.RemoveActor(self.staticballs[i]) self.staticballs = [] self.UpdateRender() - def RemoveMarker(self, pubsub_evt): - index = pubsub_evt.data + def RemoveMarker(self, index): for i in reversed(index): self.ren.RemoveActor(self.staticballs[i]) del self.staticballs[i] self.ball_id = self.ball_id - 1 self.UpdateRender() - def BlinkMarker(self, pubsub_evt): + def BlinkMarker(self, index): if self.timer: self.timer.Stop() self.staticballs[self.index].SetVisibility(1) - self.index = pubsub_evt.data + self.index = index self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnBlinkMarker, self.timer) self.timer.Start(500) @@ -574,31 +560,29 @@ class Viewer(wx.Panel): self.Refresh() self.timer_count += 1 - def StopBlinkMarker(self, pubsub_evt): + def StopBlinkMarker(self, index=None): if self.timer: self.timer.Stop() - if pubsub_evt.data is None: + if index is None: self.staticballs[self.index].SetVisibility(1) self.Refresh() self.index = False - def OnTargetMarkerTransparency(self, pubsub_evt): - status = pubsub_evt.data[0] - index = pubsub_evt.data[1] + def OnTargetMarkerTransparency(self, status, index): if status: self.staticballs[index].GetProperty().SetOpacity(1) # self.staticballs[index].GetProperty().SetOpacity(0.4) else: self.staticballs[index].GetProperty().SetOpacity(1) - def OnUpdateAngleThreshold(self, pubsub_evt): - self.anglethreshold = pubsub_evt.data + def OnUpdateAngleThreshold(self, angle): + self.anglethreshold = angle - def OnUpdateDistThreshold(self, pubsub_evt): - self.distthreshold = pubsub_evt.data + def OnUpdateDistThreshold(self, dist_threshold): + self.distthreshold = dist_threshold - def ActivateTargetMode(self, pubsub_evt): - self.target_mode = pubsub_evt.data + def ActivateTargetMode(self, evt=None, target_mode=None): + self.target_mode = target_mode if self.target_coord and self.target_mode: self.CreateTargetAim() @@ -691,8 +675,7 @@ class Viewer(wx.Panel): else: self.DisableCoilTracker() - def OnUpdateObjectTargetGuide(self, pubsub_evt): - coord = pubsub_evt.data[1] + def OnUpdateObjectTargetGuide(self, m_img, coord): if self.target_coord and self.target_mode: target_dist = distance.euclidean(coord[0:3], @@ -811,13 +794,12 @@ class Viewer(wx.Panel): self.Refresh() - def OnUpdateTargetCoordinates(self, pubsub_evt): - self.target_coord = pubsub_evt.data[0:6] + def OnUpdateTargetCoordinates(self, coord): + self.target_coord = coord self.target_coord[1] = -self.target_coord[1] self.CreateTargetAim() - def OnRemoveTarget(self, pubsub_evt): - status = pubsub_evt.data + def OnRemoveTarget(self, status): if not status: self.target_mode = None self.target_coord = None @@ -1108,12 +1090,12 @@ class Viewer(wx.Panel): self.ren.RemoveActor(self.ball_actor) self.ball_actor = None - def SetBallReferencePosition(self, pubsub_evt): + def SetBallReferencePosition(self, position): if self._to_show_ball: if not self.ball_actor: self.ActivateBallReference() - coord = pubsub_evt.data + coord = position x, y, z = bases.flip_x(coord) self.ball_actor.SetPosition(x, y, z) @@ -1198,18 +1180,15 @@ class Viewer(wx.Panel): # self.ren.AddActor(self.obj_axes) - def OnNavigationStatus(self, pubsub_evt): - self.nav_status = pubsub_evt.data + def OnNavigationStatus(self, status): + self.nav_status = status self.pTarget = self.CenterOfMass() if self.obj_actor and self.nav_status: self.obj_actor.SetVisibility(self.obj_state) if not self.obj_state: self.Refresh() - def UpdateObjectOrientation(self, pubsub_evt): - - m_img = pubsub_evt.data[0] - + def UpdateObjectOrientation(self, m_img, coord): m_img[:3, -1] = np.asmatrix(bases.flip_x_m((m_img[0, -1], m_img[1, -1], m_img[2, -1]))).reshape([3, 1]) m_img_vtk = vtk.vtkMatrix4x4() @@ -1223,22 +1202,19 @@ class Viewer(wx.Panel): self.Refresh() - def UpdateTrackObjectState(self, pubsub_evt): - if pubsub_evt.data[0]: - self.obj_name = pubsub_evt.data[1] - + def UpdateTrackObjectState(self, evt=None, flag=None, obj_name=None): + if flag: + self.obj_name = obj_name if not self.obj_actor: self.AddObjectActor(self.obj_name) - else: if self.obj_actor: self.ren.RemoveActor(self.obj_actor) self.obj_actor = None - self.Refresh() - def UpdateShowObjectState(self, pubsub_evt): - self.obj_state = pubsub_evt.data + def UpdateShowObjectState(self, state): + self.obj_state = state if self.obj_actor and not self.obj_state: self.obj_actor.SetVisibility(self.obj_state) self.Refresh() @@ -1371,8 +1347,8 @@ class Viewer(wx.Panel): diff_y = mouse_y - self.last_y self.last_x, self.last_y = mouse_x, mouse_y Publisher.sendMessage('Set raycasting relative window and level', - (diff_x, diff_y)) - Publisher.sendMessage('Refresh raycasting widget points', None) + diff_wl=diff_x, diff_ww=diff_y) + Publisher.sendMessage('Refresh raycasting widget points') self.interactor.Render() def OnWindowLevelClick(self, obj, evt): @@ -1387,31 +1363,29 @@ class Viewer(wx.Panel): if const.RAYCASTING_WWWL_BLUR: self.style.EndZoom() - def OnEnableStyle(self, pubsub_evt): - state = pubsub_evt.data - if (state in const.VOLUME_STYLES): - new_state = self.interaction_style.AddState(state) + def OnEnableStyle(self, style): + if (style in const.VOLUME_STYLES): + new_state = self.interaction_style.AddState(style) self.SetInteractorStyle(new_state) else: - new_state = self.interaction_style.RemoveState(state) + new_state = self.interaction_style.RemoveState(style) self.SetInteractorStyle(new_state) - def OnDisableStyle(self, pubsub_evt): - state = pubsub_evt.data - new_state = self.interaction_style.RemoveState(state) + def OnDisableStyle(self, style): + new_state = self.interaction_style.RemoveState(style) self.SetInteractorStyle(new_state) - def ResetCamClippingRange(self, pubsub_evt): + def ResetCamClippingRange(self): self.ren.ResetCamera() self.ren.ResetCameraClippingRange() - def SetVolumeCameraState(self, pubsub_evt): - self.camera_state = pubsub_evt.data + def SetVolumeCameraState(self, camera_state): + self.camera_state = camera_state - def SetVolumeCamera(self, pubsub_evt): + def SetVolumeCamera(self, arg, position): if self.camera_state: # TODO: exclude dependency on initial focus - cam_focus = np.array(bases.flip_x(pubsub_evt.data[1][:3])) + cam_focus = np.array(bases.flip_x(position[:3])) cam = self.ren.GetActiveCamera() if self.initial_focus is None: @@ -1442,8 +1416,7 @@ class Viewer(wx.Panel): #self.interactor.Render() self.Refresh() - def OnExportSurface(self, pubsub_evt): - filename, filetype = pubsub_evt.data + def OnExportSurface(self, filename, filetype): if filetype not in (const.FILETYPE_STL, const.FILETYPE_VTP, const.FILETYPE_PLY, @@ -1487,23 +1460,22 @@ class Viewer(wx.Panel): writer.SetInput(renwin) writer.Write() - def OnEnableBrightContrast(self, pubsub_evt): + def OnEnableBrightContrast(self): style = self.style style.AddObserver("MouseMoveEvent", self.OnMove) style.AddObserver("LeftButtonPressEvent", self.OnClick) style.AddObserver("LeftButtonReleaseEvent", self.OnRelease) - def OnDisableBrightContrast(self, pubsub_evt): + def OnDisableBrightContrast(self): style = vtk.vtkInteractorStyleTrackballCamera() self.interactor.SetInteractorStyle(style) self.style = style - def OnSetWindowLevelText(self, pubsub_evt): + def OnSetWindowLevelText(self, ww, wl): if self.raycasting_volume: - ww, wl = pubsub_evt.data self.text.SetValue("WL: %d WW: %d"%(wl, ww)) - def OnShowRaycasting(self, pubsub_evt): + def OnShowRaycasting(self): if not self.raycasting_volume: self.raycasting_volume = True self._to_show_ball += 1 @@ -1511,7 +1483,7 @@ class Viewer(wx.Panel): if self.on_wl: self.text.Show() - def OnHideRaycasting(self, pubsub_evt): + def OnHideRaycasting(self): self.raycasting_volume = False self.text.Hide() self._to_show_ball -= 1 @@ -1524,13 +1496,11 @@ class Viewer(wx.Panel): self.interactor.Update() evt.Skip() - def ChangeBackgroundColour(self, pubsub_evt): - colour = pubsub_evt.data + def ChangeBackgroundColour(self, colour): self.ren.SetBackground(colour[:3]) self.UpdateRender() - def LoadActor(self, pubsub_evt): - actor = pubsub_evt.data + def LoadActor(self, actor): self.added_actor = 1 ren = self.ren ren.AddActor(actor) @@ -1547,31 +1517,26 @@ class Viewer(wx.Panel): self._to_show_ball += 1 self._check_and_set_ball_visibility() - def RemoveActor(self, pubsub_evt): + def RemoveActor(self, actor): utils.debug("RemoveActor") - actor = pubsub_evt.data ren = self.ren ren.RemoveActor(actor) self.interactor.Render() self._to_show_ball -= 1 self._check_and_set_ball_visibility() - def RemoveAllActor(self, pubsub_evt): + def RemoveAllActor(self): utils.debug("RemoveAllActor") self.ren.RemoveAllProps() Publisher.sendMessage('Render volume viewer') - def LoadSlicePlane(self, pubsub_evt): + def LoadSlicePlane(self): self.slice_plane = SlicePlane() - def LoadVolume(self, pubsub_evt): + def LoadVolume(self, volume, colour, ww, wl): self.raycasting_volume = True self._to_show_ball += 1 - volume = pubsub_evt.data[0] - colour = pubsub_evt.data[1] - ww, wl = pubsub_evt.data[2] - self.light = self.ren.GetLights().GetNextItem() self.ren.AddVolume(volume) @@ -1593,16 +1558,14 @@ class Viewer(wx.Panel): self._check_and_set_ball_visibility() self.UpdateRender() - def UnloadVolume(self, pubsub_evt): - volume = pubsub_evt.data + def UnloadVolume(self, volume): self.ren.RemoveVolume(volume) del volume self.raycasting_volume = False self._to_show_ball -= 1 self._check_and_set_ball_visibility() - def OnSetViewAngle(self, evt_pubsub): - view = evt_pubsub.data + def OnSetViewAngle(self, view): self.SetViewAngle(view) def SetViewAngle(self, view): @@ -1657,14 +1620,14 @@ class Viewer(wx.Panel): orientation_widget.On() orientation_widget.InteractiveOff() - def UpdateRender(self, evt_pubsub=None): + def UpdateRender(self): self.interactor.Render() - def SetWidgetInteractor(self, evt_pubsub=None): - evt_pubsub.data.SetInteractor(self.interactor._Iren) + def SetWidgetInteractor(self, widget=None): + widget.SetInteractor(self.interactor._Iren) - def AppendActor(self, evt_pubsub=None): - self.ren.AddActor(evt_pubsub.data) + def AppendActor(self, actor): + self.ren.AddActor(actor) def OnInsertSeed(self, obj, evt): x,y = self.interactor.GetEventPosition() @@ -1693,7 +1656,10 @@ class Viewer(wx.Panel): # Publisher.sendMessage("Add measure to list", # (u"3D", _(u"%.3f mm" % m.GetValue()))) Publisher.sendMessage("Add measurement point", - ((x, y,z), const.LINEAR, const.SURFACE, radius)) + position=(x, y,z), + type=const.LINEAR, + location=const.SURFACE, + radius=radius) self.interactor.Render() def OnInsertAngularMeasurePoint(self, obj, evt): @@ -1724,21 +1690,23 @@ class Viewer(wx.Panel): # type_, location, # value)) Publisher.sendMessage("Add measurement point", - ((x, y,z), const.ANGULAR, const.SURFACE, radius)) + position=(x, y,z), + type=const.ANGULAR, + location=const.SURFACE, + radius=radius) self.interactor.Render() - def Reposition3DPlane(self, evt_pubsub): - position = evt_pubsub.data + def Reposition3DPlane(self, plane_label): if not(self.added_actor) and not(self.raycasting_volume): - if not(self.repositioned_axial_plan) and (position == 'Axial'): + if not(self.repositioned_axial_plan) and (plane_label == 'Axial'): self.SetViewAngle(const.VOL_ISO) self.repositioned_axial_plan = 1 - elif not(self.repositioned_sagital_plan) and (position == 'Sagital'): + elif not(self.repositioned_sagital_plan) and (plane_label == 'Sagital'): self.SetViewAngle(const.VOL_ISO) self.repositioned_sagital_plan = 1 - elif not(self.repositioned_coronal_plan) and (position == 'Coronal'): + elif not(self.repositioned_coronal_plan) and (plane_label == 'Coronal'): self.SetViewAngle(const.VOL_ISO) self.repositioned_coronal_plan = 1 @@ -1825,39 +1793,36 @@ class SlicePlane: selected_prop2 = plane_y.GetSelectedPlaneProperty() selected_prop2.SetColor(0, 1, 0) - Publisher.sendMessage('Set Widget Interactor', plane_x) - Publisher.sendMessage('Set Widget Interactor', plane_y) - Publisher.sendMessage('Set Widget Interactor', plane_z) + Publisher.sendMessage('Set Widget Interactor', widget=plane_x) + Publisher.sendMessage('Set Widget Interactor', widget=plane_y) + Publisher.sendMessage('Set Widget Interactor', widget=plane_z) self.Render() - def Enable(self, evt_pubsub=None): - if (evt_pubsub): - label = evt_pubsub.data - if(label == "Axial"): + def Enable(self, plane_label=None): + if plane_label: + if(plane_label == "Axial"): self.plane_z.On() - elif(label == "Coronal"): + elif(plane_label == "Coronal"): self.plane_y.On() - elif(label == "Sagital"): + elif(plane_label == "Sagital"): self.plane_x.On() - - Publisher.sendMessage('Reposition 3D Plane', label) - + Publisher.sendMessage('Reposition 3D Plane', plane_label=plane_label) else: self.plane_z.On() self.plane_x.On() self.plane_y.On() - Publisher.sendMessage('Set volume view angle', const.VOL_ISO) + Publisher.sendMessage('Set volume view angle', + view=const.VOL_ISO) self.Render() - def Disable(self, evt_pubsub=None): - if (evt_pubsub): - label = evt_pubsub.data - if(label == "Axial"): + def Disable(self, plane_label=None): + if plane_label: + if(plane_label == "Axial"): self.plane_z.Off() - elif(label == "Coronal"): + elif(plane_label == "Coronal"): self.plane_y.Off() - elif(label == "Sagital"): + elif(plane_label == "Sagital"): self.plane_x.Off() else: self.plane_z.Off() @@ -1869,23 +1834,33 @@ class SlicePlane: def Render(self): Publisher.sendMessage('Render volume viewer') - def ChangeSlice(self, pubsub_evt = None): - orientation, number = pubsub_evt.data - + def ChangeSlice(self, orientation, index): if orientation == "CORONAL" and self.plane_y.GetEnabled(): - Publisher.sendMessage('Update slice 3D', (self.plane_y,orientation)) + Publisher.sendMessage('Update slice 3D', + widget=self.plane_y, + orientation=orientation) self.Render() elif orientation == "SAGITAL" and self.plane_x.GetEnabled(): - Publisher.sendMessage('Update slice 3D', (self.plane_x,orientation)) + Publisher.sendMessage('Update slice 3D', + widget=self.plane_x, + orientation=orientation) self.Render() elif orientation == 'AXIAL' and self.plane_z.GetEnabled() : - Publisher.sendMessage('Update slice 3D', (self.plane_z,orientation)) + Publisher.sendMessage('Update slice 3D', + widget=self.plane_z, + orientation=orientation) self.Render() - def UpdateAllSlice(self, pubsub_evt): - Publisher.sendMessage('Update slice 3D', (self.plane_y,"CORONAL")) - Publisher.sendMessage('Update slice 3D', (self.plane_x,"SAGITAL")) - Publisher.sendMessage('Update slice 3D', (self.plane_z,"AXIAL")) + def UpdateAllSlice(self): + Publisher.sendMessage('Update slice 3D', + widget=self.plane_y, + orientation="CORONAL") + Publisher.sendMessage('Update slice 3D', + widget=self.plane_x, + orientation="SAGITAL") + Publisher.sendMessage('Update slice 3D', + widget=self.plane_z, + orientation="AXIAL") def DeletePlanes(self): diff --git a/invesalius/data/volume.py b/invesalius/data/volume.py index 31d2955..4bd4efd 100644 --- a/invesalius/data/volume.py +++ b/invesalius/data/volume.py @@ -110,17 +110,17 @@ class Volume(): Publisher.subscribe(self.ChangeBackgroundColour, 'Change volume viewer background colour') - Publisher.subscribe(self.ResetRayCasting, 'Reset Reaycasting') + Publisher.subscribe(self.ResetRayCasting, 'Reset Raycasting') Publisher.subscribe(self.OnFlipVolume, 'Flip volume') - def ResetRayCasting(self, pub_evt): + def ResetRayCasting(self): if self.exist: self.exist = None self.LoadVolume() - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): self.CloseProject() def CloseProject(self): @@ -134,9 +134,9 @@ class Volume(): if self.exist: self.exist = None - Publisher.sendMessage('Remove surface actor from viewer', self.volume) + Publisher.sendMessage('Remove surface actor from viewer', actor=self.volume) Publisher.sendMessage('Disable volume cut menu') - Publisher.sendMessage('Unload volume', self.volume) + Publisher.sendMessage('Unload volume', volume=self.volume) del self.image del self.imagedata @@ -155,19 +155,19 @@ class Volume(): self.color_transfer = None Publisher.sendMessage('Render volume viewer') - def OnLoadVolume(self, pubsub_evt): - label = pubsub_evt.data + def OnLoadVolume(self, label): + label = label #self.LoadConfig(label) self.LoadVolume() - def OnHideVolume(self, pubsub_evt): + def OnHideVolume(self): print('Hide Volume') self.volume.SetVisibility(0) if (self.plane and self.plane_on): self.plane.Disable() Publisher.sendMessage('Render volume viewer') - def OnShowVolume(self, pubsub_evt = None): + def OnShowVolume(self): print('Show volume') if self.exist: print('Volume exists') @@ -177,18 +177,19 @@ class Volume(): Publisher.sendMessage('Render volume viewer') else: print('Volume doesnt exit') - Publisher.sendMessage('Load raycasting preset', const.RAYCASTING_LABEL) + Publisher.sendMessage('Load raycasting preset', + preset_name=const.RAYCASTING_LABEL) self.LoadConfig() self.LoadVolume() self.exist = 1 - def OnUpdatePreset(self, pubsub_evt): + def OnUpdatePreset(self): self.__load_preset_config() if self.config: if self.to_reload: self.exist = False - Publisher.sendMessage('Unload volume', self.volume) + Publisher.sendMessage('Unload volume', volume=self.volume) if self.exist: self.__load_preset() @@ -200,10 +201,10 @@ class Volume(): self.exist = 1 colour = self.GetBackgroundColour() - Publisher.sendMessage('Change volume viewer background colour', colour) - Publisher.sendMessage('Change volume viewer gui colour', colour) + Publisher.sendMessage('Change volume viewer background colour', colour=colour) + Publisher.sendMessage('Change volume viewer gui colour', colour=colour) else: - Publisher.sendMessage('Unload volume', self.volume) + Publisher.sendMessage('Unload volume', volume=self.volume) del self.image del self.imagedata del self.final_imagedata @@ -221,7 +222,7 @@ class Volume(): self.color_transfer = None Publisher.sendMessage('Render volume viewer') - def OnFlipVolume(self, pubsub_evt): + def OnFlipVolume(self, axis): print("Flipping Volume") self.loaded_image = False del self.image @@ -252,28 +253,24 @@ class Volume(): self.SetShading() self.SetTypeRaycasting() - def OnSetCurve(self, pubsub_evt): - self.curve = pubsub_evt.data + def OnSetCurve(self, curve): + self.curve = curve self.CalculateWWWL() ww = self.ww wl = self.wl - Publisher.sendMessage('Set volume window and level text', - (ww, wl)) + Publisher.sendMessage('Set volume window and level text', ww=ww, wl=wl) - def OnSetRelativeWindowLevel(self, pubsub_evt): - diff_wl, diff_ww = pubsub_evt.data + def OnSetRelativeWindowLevel(self, diff_wl, diff_ww): ww = self.ww + diff_ww wl = self.wl + diff_wl - Publisher.sendMessage('Set volume window and level text', - (ww, wl)) + Publisher.sendMessage('Set volume window and level text', ww=ww, wl=wl) self.SetWWWL(ww, wl) self.ww = ww self.wl = wl - def OnSetWindowLevel(self, pubsub_evt): - ww, wl, n = pubsub_evt.data - self.curve = n - self.SetWWWL(ww,wl) + def OnSetWindowLevel(self, ww, wl, curve): + self.curve = curve + self.SetWWWL(ww, wl) def SetWWWL(self, ww, wl): if self.config['advancedCLUT']: @@ -321,7 +318,7 @@ class Volume(): self.ww = last_point - first_point self.wl = first_point + self.ww / 2.0 - def Refresh(self, pubsub_evt): + def Refresh(self): self.__update_colour_table() def Create16bColorTable(self, scale): @@ -445,11 +442,11 @@ class Volume(): self.config['backgroundColorBlueComponent']) return colour - def ChangeBackgroundColour(self, pubsub_evt): + def ChangeBackgroundColour(self, colour): if (self.config): - self.config['backgroundColorRedComponent'] = pubsub_evt.data[0] * 255 - self.config['backgroundColorGreenComponent'] = pubsub_evt.data[1] * 255 - self.config['backgroundColorBlueComponent'] = pubsub_evt.data[2] * 255 + self.config['backgroundColorRedComponent'] = colour[0] * 255 + self.config['backgroundColorGreenComponent'] = colour[1] * 255 + self.config['backgroundColorBlueComponent'] = colour[2] * 255 def BuildTable(): curve_table = p['16bitClutCurves'] @@ -663,16 +660,16 @@ class Volume(): self.plane.SetVolumeMapper(volume_mapper) Publisher.sendMessage('Load volume into viewer', - (volume, colour, (self.ww, self.wl))) + volume=volume, colour=colour, + ww=self.ww, wl=self.wl) del flip del cast - def OnEnableTool(self, pubsub_evt): - tool_name, enable = pubsub_evt.data + def OnEnableTool(self, tool_name, flag): if tool_name == _("Cut plane"): if self.plane: - if enable: + if flag: self.plane_on = True self.plane.Enable() else: @@ -695,8 +692,10 @@ class Volume(): accumulate.Update() n_image = numpy_support.vtk_to_numpy(accumulate.GetOutput().GetPointData().GetScalars()) del accumulate - Publisher.sendMessage('Load histogram', (n_image, - image.GetScalarRange())) + init, end = image.GetScalarRange() + Publisher.sendMessage('Load histogram', histogram=n_image, init=init, end=end) + + def TranslateScale(self, scale, value): #if value < 0: @@ -747,8 +746,8 @@ class CutPlane: plane_actor.GetProperty().BackfaceCullingOn() plane_actor.GetProperty().SetOpacity(0) plane_widget.AddObserver("InteractionEvent", self.Update) - Publisher.sendMessage('AppendActor', self.plane_actor) - Publisher.sendMessage('Set Widget Interactor', self.plane_widget) + Publisher.sendMessage('AppendActor', actor=self.plane_actor) + Publisher.sendMessage('Set Widget Interactor', widget=self.plane_widget) plane_actor.SetVisibility(1) plane_widget.On() self.plane = plane = vtk.vtkPlane() @@ -775,21 +774,21 @@ class CutPlane: self.plane_actor.VisibilityOn() self.plane.SetNormal(plane_source.GetNormal()) self.plane.SetOrigin(plane_source.GetOrigin()) - Publisher.sendMessage('Render volume viewer', None) + Publisher.sendMessage('Render volume viewer') - def Enable(self, evt_pubsub=None): + def Enable(self): self.plane_widget.On() self.plane_actor.VisibilityOn() self.volume_mapper.AddClippingPlane(self.plane) - Publisher.sendMessage('Render volume viewer', None) + Publisher.sendMessage('Render volume viewer') - def Disable(self,evt_pubsub=None): + def Disable(self): self.plane_widget.Off() self.plane_actor.VisibilityOff() self.volume_mapper.RemoveClippingPlane(self.plane) - Publisher.sendMessage('Render volume viewer', None) + Publisher.sendMessage('Render volume viewer') - def Reset(self, evt_pubsub=None): + def Reset(self): plane_source = self.plane_source plane_widget = self.plane_widget plane_source.SetOrigin(self.origin) @@ -799,10 +798,10 @@ class CutPlane: self.plane_actor.VisibilityOn() self.plane.SetNormal(self.normal) self.plane.SetOrigin(self.origin) - Publisher.sendMessage('Render volume viewer', None) + Publisher.sendMessage('Render volume viewer') def DestroyObjs(self): - Publisher.sendMessage('Remove surface actor from viewer', self.plane_actor) + Publisher.sendMessage('Remove surface actor from viewer', actor=self.plane_actor) self.Disable() del self.plane_widget del self.plane_source diff --git a/invesalius/data/vtk_utils.py b/invesalius/data/vtk_utils.py index 736f131..e69b449 100644 --- a/invesalius/data/vtk_utils.py +++ b/invesalius/data/vtk_utils.py @@ -81,8 +81,7 @@ def ShowProgress(number_of_filters = 1, progress[0] = progress[0] + ratio*difference # Tell GUI to update progress status value if (dialog_type == "GaugeProgress"): - Publisher.sendMessage('Update status in GUI', - (progress[0], label)) + Publisher.sendMessage('Update status in GUI', value=progress[0], label=label) else: if (progress[0] >= 99.999): progress[0] = 100 diff --git a/invesalius/gui/bitmap_preview_panel.py b/invesalius/gui/bitmap_preview_panel.py index 13306a7..33b675b 100644 --- a/invesalius/gui/bitmap_preview_panel.py +++ b/invesalius/gui/bitmap_preview_panel.py @@ -249,7 +249,7 @@ class Preview(wx.Panel): my_evt.SetEventObject(self) self.GetEventHandler().ProcessEvent(my_evt) - Publisher.sendMessage('Set bitmap in preview panel', self.bitmap_info.pos) + Publisher.sendMessage('Set bitmap in preview panel', pos=self.bitmap_info.pos) evt.Skip() @@ -369,15 +369,14 @@ class BitmapPreviewSeries(wx.Panel): self._display_previews() - def RemovePanel(self, pub_sub): - data = pub_sub.data + def RemovePanel(self, data): for p, f in zip(self.previews, self.files): if p.bitmap_info != None: if data.encode('utf-8') in p.bitmap_info.data: self.files.remove(f) p.Hide() self._display_previews() - Publisher.sendMessage('Update max of slidebar in single preview image', len(self.files)) + Publisher.sendMessage('Update max of slidebar in single preview image', max_value=len(self.files)) self.Update() self.Layout() @@ -539,8 +538,7 @@ class SingleImagePreview(wx.Panel): Publisher.subscribe(self.UpdateMaxValueSliderBar, 'Update max of slidebar in single preview image') Publisher.subscribe(self.ShowBlackSlice, 'Show black slice in single preview image') - def ShowBitmapByPosition(self, evt): - pos = evt.data + def ShowBitmapByPosition(self, pos): if pos != None: self.ShowSlice(int(pos)) @@ -584,8 +582,8 @@ class SingleImagePreview(wx.Panel): self.slider.SetValue(0) self.ShowSlice() - def UpdateMaxValueSliderBar(self, pub_sub): - self.slider.SetMax(pub_sub.data - 1) + def UpdateMaxValueSliderBar(self, max_value): + self.slider.SetMax(max_value - 1) self.slider.Refresh() self.slider.Update() diff --git a/invesalius/gui/data_notebook.py b/invesalius/gui/data_notebook.py index 36a9af9..41e6b19 100644 --- a/invesalius/gui/data_notebook.py +++ b/invesalius/gui/data_notebook.py @@ -98,20 +98,20 @@ class NotebookPanel(wx.Panel): 'Fold mask page') - def _FoldSurface(self, pubusb_evt): + def _FoldSurface(self): """ Fold surface notebook page. """ self.book.SetSelection(1) - def _FoldMeasure(self, pubsub_evt): + def _FoldMeasure(self): """ Fold measure notebook page. """ self.book.SetSelection(2) - def _FoldMask(self, pubsub_evt): + def _FoldMask(self): """ Fold mask notebook page. """ @@ -334,7 +334,8 @@ class ButtonControlPanel(wx.Panel): mask_name, thresh, colour = dialog.GetValue() if mask_name: Publisher.sendMessage('Create new mask', - (mask_name, thresh, colour)) + mask_name=mask_name, + thresh=thresh, colour=colour) dialog.Destroy() def OnRemove(self): @@ -343,7 +344,7 @@ class ButtonControlPanel(wx.Panel): def OnDuplicate(self): selected_items = self.parent.listctrl.GetSelected() if selected_items: - Publisher.sendMessage('Duplicate masks', selected_items) + Publisher.sendMessage('Duplicate masks', mask_indexes=selected_items) else: dlg.MaskSelectionRequiredForDuplication() @@ -398,7 +399,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): selected_items = self.GetSelected() if selected_items: - Publisher.sendMessage('Remove masks', selected_items) + Publisher.sendMessage('Remove masks', mask_indexes=selected_items) else: dlg.MaskSelectionRequiredForRemoval() return @@ -421,8 +422,8 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): if new_dict: if index == self.current_index: self.SetItemImage(0, 1) - Publisher.sendMessage('Change mask selected', 0) - Publisher.sendMessage('Show mask', (0, 1)) + Publisher.sendMessage('Change mask selected', index=0) + Publisher.sendMessage('Show mask', index=0, value=1) Publisher.sendMessage('Refresh viewer') for key in new_dict: if key: @@ -433,27 +434,26 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): self.SetItemImage(self.current_index, 1) - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): self.DeleteAllItems() self.mask_list_index = {} - def OnChangeCurrentMask(self, pubsub_evt): - mask_index = pubsub_evt.data + def OnChangeCurrentMask(self, index): try: - self.SetItemImage(mask_index, 1) - self.current_index = mask_index + self.SetItemImage(index, 1) + self.current_index = index except wx._core.PyAssertionError: #in SetItem(): invalid item index in SetItem pass for key in self.mask_list_index.keys(): - if key != mask_index: + if key != index: self.SetItemImage(key, 0) - def __hide_current_mask(self, pubsub_evt): + def __hide_current_mask(self): if self.mask_list_index: self.SetItemImage(self.current_index, 0) - def __show_current_mask(self, pubsub_evt): + def __show_current_mask(self): if self.mask_list_index: self.SetItemImage(self.current_index, 1) @@ -488,7 +488,7 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): def OnEditLabel(self, evt): Publisher.sendMessage('Change mask name', - (evt.GetIndex(), evt.GetLabel())) + index=evt.GetIndex(), name=evt.GetLabel()) evt.Skip() def OnItemActivated(self, evt): @@ -499,9 +499,9 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): for key in self.mask_list_index.keys(): if key != index: self.SetItemImage(key, 0) - Publisher.sendMessage('Change mask selected',index) + Publisher.sendMessage('Change mask selected', index=index) self.current_index = index - Publisher.sendMessage('Show mask', (index, flag)) + Publisher.sendMessage('Show mask', index=index, value=flag) def CreateColourBitmap(self, colour): """ @@ -536,19 +536,16 @@ class MasksListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): # self.SetItemImage(key, 0) # self.current_index = index - def AddMask(self, pubsub_evt): - index, mask_name, threshold_range, colour = pubsub_evt.data - image = self.CreateColourBitmap(colour) + def AddMask(self, mask): + image = self.CreateColourBitmap(mask.colour) image_index = self.imagelist.Add(image) - self.mask_list_index[index] = image_index - self.InsertNewItem(index, mask_name, str(threshold_range)) + self.mask_list_index[mask.index] = image_index + self.InsertNewItem(mask.index, mask.name, str(mask.threshold_range)) - def EditMaskThreshold(self, pubsub_evt): - index, threshold_range = pubsub_evt.data + def EditMaskThreshold(self, index, threshold_range): self.SetStringItem(index, 2, str(threshold_range)) - def EditMaskColour(self, pubsub_evt): - index, colour = pubsub_evt.data + def EditMaskColour(self, index, colour): image = self.CreateColourBitmap(colour) image_index = self.mask_list_index[index] self.imagelist.Replace(image_index, image) @@ -678,7 +675,8 @@ class SurfaceButtonControlPanel(wx.Panel): if ok: surface_options = dialog.GetValue() - Publisher.sendMessage('Create surface from index', surface_options) + Publisher.sendMessage('Create surface from index', + surface_parameters=surface_options) dialog.Destroy() def OnRemove(self): @@ -688,14 +686,14 @@ class SurfaceButtonControlPanel(wx.Panel): def OnDuplicate(self): selected_items = self.parent.listctrl.GetSelected() if selected_items: - Publisher.sendMessage('Duplicate surfaces', selected_items) + Publisher.sendMessage('Duplicate surfaces', surface_indexes=selected_items) else: dlg.SurfaceSelectionRequiredForDuplication() def OnOpenMesh(self): filename = dlg.ShowImportMeshFilesDialog() if filename: - Publisher.sendMessage('Import surface file', filename) + Publisher.sendMessage('Import surface file', filename=filename) class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): @@ -744,8 +742,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): elif (keycode == wx.WXK_DELETE): self.RemoveSurfaces() - def OnHideSurface(self, pubsub_evt): - surface_dict = pubsub_evt.data + def OnHideSurface(self, surface_dict): for key in surface_dict: if not surface_dict[key].is_shown: self.SetItemImage(key, False) @@ -770,11 +767,11 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): old_dict = new_dict self.surface_list_index = new_dict - Publisher.sendMessage('Remove surfaces', selected_items) + Publisher.sendMessage('Remove surfaces', surface_indexes=selected_items) else: dlg.SurfaceSelectionRequiredForRemoval() - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): self.DeleteAllItems() self.surface_list_index = {} self.surface_bmp_idx_to_name = {} @@ -786,7 +783,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): last_surface_index = evt.Index Publisher.sendMessage('Change surface selected', - last_surface_index) + surface_index=last_surface_index) evt.Skip() def GetSelected(self): @@ -837,7 +834,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): self.image_gray = Image.open(os.path.join(const.ICON_DIR, "object_colour.jpg")) def OnEditLabel(self, evt): - Publisher.sendMessage('Change surface name', (evt.GetIndex(), evt.GetLabel())) + Publisher.sendMessage('Change surface name', index=evt.GetIndex(), name=evt.GetLabel()) evt.Skip() def OnItemActivated(self, evt): @@ -845,38 +842,36 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): evt.Skip() def OnCheckItem(self, index, flag): - Publisher.sendMessage('Show surface', (index, flag)) + Publisher.sendMessage('Show surface', index=index, visibility=flag) - def OnShowSingle(self, pubsub_evt): - index, visibility = pubsub_evt.data + def OnShowSingle(self, index, visibility): for key in self.surface_list_index.keys(): if key != index: self.SetItemImage(key, not visibility) Publisher.sendMessage('Show surface', - (key, not visibility)) + index=key, visibility=not visibility) self.SetItemImage(index, visibility) Publisher.sendMessage('Show surface', - (index, visibility)) + index=index, visibility=visibility) - def OnShowMultiple(self, pubsub_evt): - index_list, visibility = pubsub_evt.data + def OnShowMultiple(self, index_list, visibility): for key in self.surface_list_index.keys(): if key not in index_list: self.SetItemImage(key, not visibility) Publisher.sendMessage('Show surface', - (key, not visibility)) + index=key, visibility=not visibility) for index in index_list: self.SetItemImage(index, visibility) Publisher.sendMessage('Show surface', - (index, visibility)) + index=index, visibility=visibility) - def AddSurface(self, pubsub_evt): - index = pubsub_evt.data[0] - name = pubsub_evt.data[1] - colour = pubsub_evt.data[2] - volume = "%.3f"%pubsub_evt.data[3] - area = "%.3f"%pubsub_evt.data[4] - transparency = "%d%%"%(int(100*pubsub_evt.data[5])) + def AddSurface(self, surface): + index = surface.index + name = surface.name + colour = surface.colour + volume = "%.3f" % surface.volume + area = "%.3f" % surface.area + transparency = "%d%%" % (int(100*surface.transparency)) if index not in self.surface_list_index: image = self.CreateColourBitmap(colour) @@ -941,20 +936,18 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): return wx.BitmapFromImage(wx_image.Scale(16, 16)) - def EditSurfaceTransparency(self, pubsub_evt): + def EditSurfaceTransparency(self, surface_index, transparency): """ Set actor transparency (oposite to opacity) according to given actor index and value. """ - index, value = pubsub_evt.data - self.SetStringItem(index, 4, "%d%%"%(int(value*100))) + self.SetStringItem(surface_index, 4, "%d%%"%(int(transparency*100))) - def EditSurfaceColour(self, pubsub_evt): + def EditSurfaceColour(self, surface_index, colour): """ """ - index, colour = pubsub_evt.data image = self.CreateColourBitmap(colour) - image_index = self.surface_list_index[index] + image_index = self.surface_list_index[surface_index] self.imagelist.Replace(image_index, image) self.Refresh() @@ -1007,15 +1000,14 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): elif (keycode == wx.WXK_DELETE): self.RemoveMeasurements() - def OnRemoveGUIMeasure(self, pubsub_evt): - idx = pubsub_evt.data - self.DeleteItem(idx) + def OnRemoveGUIMeasure(self, measure_index): + self.DeleteItem(measure_index) old_dict = self._list_index new_dict = {} j = 0 for i in old_dict: - if i != idx: + if i != measure_index: new_dict[j] = old_dict[i] j+=1 self._list_index = new_dict @@ -1041,12 +1033,12 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): new_dict[i-1] = old_dict[i] old_dict = new_dict self._list_index = new_dict - Publisher.sendMessage('Remove measurements', selected_items) + Publisher.sendMessage('Remove measurements', indexes=selected_items) else: dlg.MeasureSelectionRequiredForRemoval() - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): self.DeleteAllItems() self._list_index = {} self._bmp_idx_to_name = {} @@ -1057,8 +1049,8 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): # things will stop working, e.g.: OnCheckItem last_index = evt.Index - Publisher.sendMessage('Change measurement selected', - last_index) + # Publisher.sendMessage('Change measurement selected', + # last_index) evt.Skip() def GetSelected(self): @@ -1110,7 +1102,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): def OnEditLabel(self, evt): - Publisher.sendMessage('Change measurement name', (evt.GetIndex(), evt.GetLabel())) + Publisher.sendMessage('Change measurement name', index=evt.GetIndex(), name=evt.GetLabel()) evt.Skip() def OnItemActivated(self, evt): @@ -1119,38 +1111,32 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): def OnCheckItem(self, index, flag): - Publisher.sendMessage('Show measurement', (index, flag)) + Publisher.sendMessage('Show measurement', index=index, visibility=flag) - def OnShowSingle(self, pubsub_evt): - index, visibility = pubsub_evt.data + def OnShowSingle(self, index, visibility): for key in self._list_index.keys(): if key != index: self.SetItemImage(key, not visibility) Publisher.sendMessage('Show measurement', - (key, not visibility)) + index=key, visibility=not visibility) self.SetItemImage(index, visibility) Publisher.sendMessage('Show measurement', - (index, visibility)) + index=index, visibility=visibility) - def OnShowMultiple(self, pubsub_evt): - index_list, visibility = pubsub_evt.data + def OnShowMultiple(self, index_list, visibility): for key in self._list_index.keys(): if key not in index_list: self.SetItemImage(key, not visibility) Publisher.sendMessage('Show measurement', - (key, not visibility)) + index=key, visibility=not visibility) for index in index_list: self.SetItemImage(index, visibility) Publisher.sendMessage('Show measurement', - (index, visibility)) + index=index, visibility=visibility) - def OnLoadData(self, pubsub_evt): - try: - items_dict, spacing = pubsub_evt.data - except ValueError: - items_dict = pubsub_evt.data - for i in items_dict: - m = items_dict[i] + def OnLoadData(self, measurement_dict, spacing=(1.0, 1.0, 1.0)): + for i in measurement_dict: + m = measurement_dict[i] image = self.CreateColourBitmap(m.colour) image_index = self.imagelist.Add(image) @@ -1169,14 +1155,7 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): if not m.visible: self.SetItemImage(i, False) - def AddItem_(self, pubsub_evt): - index = pubsub_evt.data[0] - name = pubsub_evt.data[1] - colour = pubsub_evt.data[2] - location = pubsub_evt.data[3] - type_ = pubsub_evt.data[4] - value = pubsub_evt.data[5] - + def AddItem_(self, index, name, colour, location, type_, value): if index not in self._list_index: image = self.CreateColourBitmap(colour) image_index = self.imagelist.Add(image) @@ -1241,12 +1220,11 @@ class MeasuresListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): wx_image.SetData(new_image.tobytes()) return wx.BitmapFromImage(wx_image.Scale(16, 16)) - def EditItemColour(self, pubsub_evt): + def EditItemColour(self, measure_index, colour): """ """ - index, colour = pubsub_evt.data image = self.CreateColourBitmap(colour) - image_index = self._list_index[index] + image_index = self._list_index[measure_index] self.imagelist.Replace(image_index, image) self.Refresh() diff --git a/invesalius/gui/default_tasks.py b/invesalius/gui/default_tasks.py index 466aa53..000a063 100644 --- a/invesalius/gui/default_tasks.py +++ b/invesalius/gui/default_tasks.py @@ -204,8 +204,7 @@ class LowerTaskPanel(wx.Panel): def __bind_events(self): Publisher.subscribe(self.OnEnableState, "Enable state project") - def OnEnableState(self, pubsub_evt): - state = pubsub_evt.data + def OnEnableState(self, state): if state: self.SetStateProjectOpen() else: @@ -305,25 +304,24 @@ class UpperTaskPanel(wx.Panel): Publisher.subscribe(self.OnFoldExport, 'Fold export task') Publisher.subscribe(self.SetNavigationMode, "Set navigation mode") - def OnOverwrite(self, pubsub_evt): - self.overwrite = pubsub_evt.data['options']['overwrite'] + def OnOverwrite(self, surface_parameters): + self.overwrite = surface_parameters['options']['overwrite'] - def OnFoldSurface(self, pubsub_evt): + def OnFoldSurface(self): if not self.overwrite: self.fold_panel.Expand(self.fold_panel.GetFoldPanel(2)) - def OnFoldExport(self, pubsub_evt): + def OnFoldExport(self): self.fold_panel.Expand(self.fold_panel.GetFoldPanel(3)) - def OnEnableState(self, pubsub_evt): - state = pubsub_evt.data + def OnEnableState(self, state): if state: self.SetStateProjectOpen() else: self.SetStateProjectClose() - def SetNavigationMode(self, pubsub_evt): - self.navigation_mode_status = status = pubsub_evt.data + def SetNavigationMode(self, status): + self.navigation_mode_status = status name = _("Navigation system") panel = navigator.TaskPanel if status and (self.fold_panel.GetCount()<=4): diff --git a/invesalius/gui/default_viewers.py b/invesalius/gui/default_viewers.py index c7a92eb..27f4611 100644 --- a/invesalius/gui/default_viewers.py +++ b/invesalius/gui/default_viewers.py @@ -130,11 +130,11 @@ class Panel(wx.Panel): def OnMaximize(self, evt): if evt.GetPane().name == self.s4.name: - Publisher.sendMessage('Show raycasting widget', None) + Publisher.sendMessage('Show raycasting widget') def OnRestore(self, evt): if evt.GetPane().name == self.s4.name: - Publisher.sendMessage('Hide raycasting widget', None) + Publisher.sendMessage('Hide raycasting widget') def __init_four_way_splitter(self): @@ -156,7 +156,7 @@ class Panel(wx.Panel): p4 = volume_viewer.Viewer(self) splitter.AppendWindow(p4) - def _Exit(self, pubsub_evt): + def _Exit(self): self.aui_manager.UnInit() def __init_mix(self): @@ -256,28 +256,28 @@ class VolumeInteraction(wx.Panel): def __update_curve_wwwl_text(self, curve): ww, wl = self.clut_raycasting.GetCurveWWWl(curve) - Publisher.sendMessage('Set raycasting wwwl', (ww, wl, curve)) + Publisher.sendMessage('Set raycasting wwwl', ww=ww, wl=wl, curve=curve) - def ShowRaycastingWidget(self, evt_pubsub=None): + def ShowRaycastingWidget(self): self.can_show_raycasting_widget = 1 if self.clut_raycasting.to_draw_points: p = self.aui_manager.GetPane(self.clut_raycasting) p.Show() self.aui_manager.Update() - def HideRaycastingWidget(self, evt_pubsub=None): + def HideRaycastingWidget(self): self.can_show_raycasting_widget = 0 p = self.aui_manager.GetPane(self.clut_raycasting) p.Hide() self.aui_manager.Update() def OnPointChanged(self, evt): - Publisher.sendMessage('Set raycasting refresh', None) - Publisher.sendMessage('Set raycasting curve', evt.GetCurve()) + Publisher.sendMessage('Set raycasting refresh') + Publisher.sendMessage('Set raycasting curve', curve=evt.GetCurve()) Publisher.sendMessage('Render volume viewer') def OnCurveSelected(self, evt): - Publisher.sendMessage('Set raycasting curve', evt.GetCurve()) + Publisher.sendMessage('Set raycasting curve', curve=evt.GetCurve()) Publisher.sendMessage('Render volume viewer') def OnChangeCurveWL(self, evt): @@ -285,7 +285,7 @@ class VolumeInteraction(wx.Panel): self.__update_curve_wwwl_text(curve) Publisher.sendMessage('Render volume viewer') - def OnSetRaycastPreset(self, evt_pubsub): + def OnSetRaycastPreset(self): preset = project.Project().raycasting_preset p = self.aui_manager.GetPane(self.clut_raycasting) self.clut_raycasting.SetRaycastPreset(preset) @@ -296,17 +296,15 @@ class VolumeInteraction(wx.Panel): p.Hide() self.aui_manager.Update() - def LoadHistogram(self, pubsub_evt): - histogram = pubsub_evt.data[0] - init, end = pubsub_evt.data[1] + def LoadHistogram(self, histogram, init, end): self.clut_raycasting.SetRange((init, end)) self.clut_raycasting.SetHistogramArray(histogram, (init, end)) - def RefreshPoints(self, pubsub_evt): + def RefreshPoints(self): self.clut_raycasting.CalculatePixelPoints() self.clut_raycasting.Refresh() - def _Exit(self, pubsub_evt): + def _Exit(self): self.aui_manager.UnInit() @@ -434,7 +432,7 @@ class VolumeToolPanel(wx.Panel): Publisher.subscribe(self.StatusTargetSelect, 'Disable or enable coil tracker') Publisher.subscribe(self.StatusObjTracker, 'Status target button') - def DisablePreset(self, pubsub_evt): + def DisablePreset(self): self.off_item.Check(1) @@ -459,12 +457,12 @@ class VolumeToolPanel(wx.Panel): def OnButtonSlicePlane(self, evt): self.button_slice_plane.PopupMenu(self.slice_plane_menu) - def StatusObjTracker(self, pubsub_evt): - self.status_obj_tracker = pubsub_evt.data + def StatusObjTracker(self, status): + self.status_obj_tracker = status self.StatusNavigation() - def StatusTargetSelect(self, pubsub_evt): - self.status_target_select = pubsub_evt.data + def StatusTargetSelect(self, status): + self.status_target_select = status self.StatusNavigation() def StatusNavigation(self): @@ -477,19 +475,18 @@ class VolumeToolPanel(wx.Panel): def OnButtonTarget(self, evt): if not self.button_target.IsPressed() and evt is not False: self.button_target._pressed = True - Publisher.sendMessage('Target navigation mode', self.button_target._pressed) + Publisher.sendMessage('Target navigation mode', target_mode=self.button_target._pressed) elif self.button_target.IsPressed() or evt is False: self.button_target._pressed = False - Publisher.sendMessage('Target navigation mode', self.button_target._pressed) + Publisher.sendMessage('Target navigation mode', target_mode=self.button_target._pressed) def OnSavePreset(self, evt): d = wx.TextEntryDialog(self, _("Preset name")) if d.ShowModal() == wx.ID_OK: preset_name = d.GetValue() - Publisher.sendMessage(_("Save raycasting preset"), - preset_name) + Publisher.sendMessage("Save raycasting preset", preset_name=preset_name) - def __init_menus(self, pubsub_evt=None): + def __init_menus(self): # MENU RELATED TO RAYCASTING TYPES menu = self.menu = wx.Menu() #print "\n\n" @@ -576,7 +573,7 @@ class VolumeToolPanel(wx.Panel): self.Fit() self.Update() - def DisableVolumeCutMenu(self, pusub_evt): + def DisableVolumeCutMenu(self): self.menu.Enable(RAYCASTING_TOOLS, 0) item = ID_TO_TOOL_ITEM[self.id_cutplane] item.Check(0) @@ -596,23 +593,23 @@ class VolumeToolPanel(wx.Panel): label = item.GetLabel() if not (checked): - Publisher.sendMessage('Disable plane', label) + Publisher.sendMessage('Disable plane', plane_label=label) else: - Publisher.sendMessage('Enable plane', label) + Publisher.sendMessage('Enable plane', plane_label=label) def OnMenuStereo(self, evt): id = evt.GetId() mode = ID_TO_STEREO_NAME[id] - Publisher.sendMessage('Set stereo mode', mode) + Publisher.sendMessage('Set stereo mode', mode=mode) - def Uncheck(self, pubsub_evt): + def Uncheck(self): for item in self.slice_plane_menu.GetMenuItems(): if (item.IsChecked()): item.Check(0) - def ChangeButtonColour(self, pubsub_evt): - colour = [i*255 for i in pubsub_evt.data] + def ChangeButtonColour(self, colour): + colour = [i*255 for i in colour] self.button_colour.SetColour(colour) def OnMenuRaycasting(self, evt): @@ -622,7 +619,7 @@ class VolumeToolPanel(wx.Panel): # Raycassting type was selected name = ID_TO_NAME[id] Publisher.sendMessage('Load raycasting preset', - ID_TO_NAME[id]) + preset_name=ID_TO_NAME[id]) # Enable or disable tools if name != const.RAYCASTING_OFF_LABEL: self.menu_raycasting.Enable(RAYCASTING_TOOLS, 1) @@ -639,12 +636,12 @@ class VolumeToolPanel(wx.Panel): # i.Check(0) if not TOOL_STATE[id]: Publisher.sendMessage('Enable raycasting tool', - [ID_TO_TOOL[id],1]) + tool_name=ID_TO_TOOL[id], flag=1) TOOL_STATE[id] = True item.Check(1) else: Publisher.sendMessage('Enable raycasting tool', - [ID_TO_TOOL[id],0]) + tool_name=ID_TO_TOOL[id], flag=0) TOOL_STATE[id] = False item.Check(0) @@ -655,10 +652,10 @@ class VolumeToolPanel(wx.Panel): self.button_view.SetBitmapSelected(bmp) Publisher.sendMessage('Set volume view angle', - evt.GetId()) + view=evt.GetId()) self.Refresh() def OnSelectColour(self, evt): colour = c = [i/255.0 for i in evt.GetValue()] - Publisher.sendMessage('Change volume viewer background colour', colour) + Publisher.sendMessage('Change volume viewer background colour', colour=colour) diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 4bdd099..c9793db 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -726,7 +726,7 @@ class UpdateMessageDialog(wx.Dialog): self.Close() self.Destroy() - def _OnCloseInV(self, pubsub_evt): + def _OnCloseInV(self): # Closes and destroy this dialog. self.Close() self.Destroy() @@ -1880,12 +1880,12 @@ class ClutImagedataDialog(wx.Dialog): def OnClutChange(self, evt): Publisher.sendMessage('Change colour table from background image from widget', - evt.GetNodes()) + nodes=evt.GetNodes()) Publisher.sendMessage('Update window level text', - (self.clut_widget.window_width, - self.clut_widget.window_level)) + window=self.clut_widget.window_width, + level=self.clut_widget.window_level) - def _refresh_widget(self, pubsub_evt): + def _refresh_widget(self): self.clut_widget.Refresh() def Show(self, gen_evt=True, show=True): @@ -2068,7 +2068,8 @@ class MaskBooleanDialog(wx.Dialog): m1 = self.mask1.GetClientData(self.mask1.GetSelection()) m2 = self.mask2.GetClientData(self.mask2.GetSelection()) - Publisher.sendMessage('Do boolean operation', (op, m1, m2)) + Publisher.sendMessage('Do boolean operation', + operation=op, mask1=m1, mask2=m2) Publisher.sendMessage('Reload actual slice') Publisher.sendMessage('Refresh viewer') @@ -2152,13 +2153,13 @@ class ReorientImageDialog(wx.Dialog): self.btnapply.Bind(wx.EVT_BUTTON, self.apply_reorientation) self.Bind(wx.EVT_CLOSE, self.OnClose) - def _update_angles(self, pubsub_evt): - anglex, angley, anglez = pubsub_evt.data + def _update_angles(self, angles): + anglex, angley, anglez = angles self.anglex.SetValue("%.3f" % np.rad2deg(anglex)) self.angley.SetValue("%.3f" % np.rad2deg(angley)) self.anglez.SetValue("%.3f" % np.rad2deg(anglez)) - def _close_dialog(self, pubsub_evt): + def _close_dialog(self): self.Destroy() def apply_reorientation(self, evt): @@ -2167,13 +2168,13 @@ class ReorientImageDialog(wx.Dialog): def OnClose(self, evt): self._closed = True - Publisher.sendMessage('Disable style', const.SLICE_STATE_REORIENT) - Publisher.sendMessage('Enable style', const.STATE_DEFAULT) + Publisher.sendMessage('Disable style', style=const.SLICE_STATE_REORIENT) + Publisher.sendMessage('Enable style', style=const.STATE_DEFAULT) self.Destroy() def OnSelect(self, evt): im_code = self.interp_method.GetClientData(self.interp_method.GetSelection()) - Publisher.sendMessage('Set interpolation method', im_code) + Publisher.sendMessage('Set interpolation method', interp_method=im_code) def OnSetFocus(self, evt): self._last_ax = self.anglex.GetValue() @@ -2191,7 +2192,7 @@ class ReorientImageDialog(wx.Dialog): self.angley.SetValue(self._last_ay) self.anglez.SetValue(self._last_az) return - Publisher.sendMessage('Set reorientation angles', (ax, ay, az)) + Publisher.sendMessage('Set reorientation angles', angles=(ax, ay, az)) class ImportBitmapParameters(wx.Dialog): @@ -2350,7 +2351,7 @@ class ImportBitmapParameters(wx.Dialog): values = [self.tx_name.GetValue(), orientation,\ self.fsp_spacing_x.GetValue(), self.fsp_spacing_y.GetValue(),\ self.fsp_spacing_z.GetValue(), self.interval] - Publisher.sendMessage('Open bitmap files', values) + Publisher.sendMessage('Open bitmap files', rec_data=values) self.Close() self.Destroy() @@ -2759,7 +2760,7 @@ class FFillOptionsDialog(wx.Dialog): def OnClose(self, evt): print("ONCLOSE") if self.config.dlg_visible: - Publisher.sendMessage('Disable style', const.SLICE_STATE_MASK_FFILL) + Publisher.sendMessage('Disable style', style=const.SLICE_STATE_MASK_FFILL) evt.Skip() self.Destroy() @@ -2845,7 +2846,7 @@ class SelectPartsOptionsDialog(wx.Dialog): def OnClose(self, evt): if self.config.dlg_visible: - Publisher.sendMessage('Disable style', const.SLICE_STATE_SELECT_MASK_PARTS) + Publisher.sendMessage('Disable style', style=const.SLICE_STATE_SELECT_MASK_PARTS) evt.Skip() self.Destroy() @@ -3048,7 +3049,7 @@ class FFillSegmentationOptionsDialog(wx.Dialog): def OnClose(self, evt): if self.config.dlg_visible: - Publisher.sendMessage('Disable style', const.SLICE_STATE_MASK_FFILL) + Publisher.sendMessage('Disable style', style=const.SLICE_STATE_MASK_FFILL) evt.Skip() self.Destroy() @@ -3068,14 +3069,8 @@ class CropOptionsDialog(wx.Dialog): self._init_gui() - def UpdateValues(self, pubsub_evt): - - if type(pubsub_evt) == list: - data = pubsub_evt - else: - data = pubsub_evt.data - - xi, xf, yi, yf, zi, zf = data + def UpdateValues(self, limits): + xi, xf, yi, yf, zi, zf = limits self.tx_axial_i.SetValue(str(zi)) self.tx_axial_f.SetValue(str(zf)) @@ -3170,12 +3165,12 @@ class CropOptionsDialog(wx.Dialog): def OnOk(self, evt): self.config.dlg_visible = False Publisher.sendMessage('Crop mask') - Publisher.sendMessage('Disable style', const.SLICE_STATE_CROP_MASK) + Publisher.sendMessage('Disable style', style=const.SLICE_STATE_CROP_MASK) evt.Skip() def OnClose(self, evt): self.config.dlg_visible = False - Publisher.sendMessage('Disable style', const.SLICE_STATE_CROP_MASK) + Publisher.sendMessage('Disable style', style=const.SLICE_STATE_CROP_MASK) evt.Skip() self.Destroy() @@ -3260,14 +3255,14 @@ class FillHolesAutoDialog(wx.Dialog): conn = self.panel3dcon.GetConnSelected() orientation = 'VOLUME' - data = { + parameters = { 'target': target, 'conn': conn, 'orientation': orientation, 'size': self.spin_size.GetValue(), } - Publisher.sendMessage("Fill holes automatically", data) + Publisher.sendMessage("Fill holes automatically", parameters=parameters) def OnBtnClose(self, evt): diff --git a/invesalius/gui/dicom_preview_panel.py b/invesalius/gui/dicom_preview_panel.py index b6a90f7..5305eec 100644 --- a/invesalius/gui/dicom_preview_panel.py +++ b/invesalius/gui/dicom_preview_panel.py @@ -686,8 +686,8 @@ class DicomPreviewSlice(wx.Panel): self.selected_dicom = self.selected_panel.dicom_info self.GetEventHandler().ProcessEvent(my_evt) - Publisher.sendMessage("Selected Import Images", [self.first_selection, \ - self.last_selection]) + Publisher.sendMessage("Selected Import Images", + selection=(self.first_selection, self.last_selection)) def OnScroll(self, evt=None): if evt: diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index d8fd4d7..dbe7852 100644 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -248,14 +248,14 @@ class Frame(wx.Frame): # TODO: Allow saving and restoring perspectives self.perspective_all = aui_manager.SavePerspective() - def _BeginBusyCursor(self, pubsub_evt): + def _BeginBusyCursor(self): """ Start busy cursor. Note: _EndBusyCursor should be called after. """ wx.BeginBusyCursor() - def _EndBusyCursor(self, pubsub_evt): + def _EndBusyCursor(self): """ End busy cursor. Note: _BeginBusyCursor should have been called previously. @@ -266,7 +266,7 @@ class Frame(wx.Frame): #no matching wxBeginBusyCursor() for wxEndBusyCursor() pass - def _Exit(self, pubsub_evt): + def _Exit(self): """ Exit InVesalius. """ @@ -275,7 +275,7 @@ class Frame(wx.Frame): if hasattr(sys,"frozen") and sys.platform == 'darwin': sys.exit(0) - def _HideContentPanel(self, pubsub_evt): + def _HideContentPanel(self): """ Hide data and tasks panels. """ @@ -284,7 +284,7 @@ class Frame(wx.Frame): aui_manager.GetPane("Tasks").Show(1) aui_manager.Update() - def _HideImportPanel(self, evt_pubsub): + def _HideImportPanel(self): """ Hide import panel and show tasks. """ @@ -294,39 +294,37 @@ class Frame(wx.Frame): aui_manager.GetPane("Tasks").Show(1) aui_manager.Update() - def _HideTask(self, pubsub_evt): + def _HideTask(self): """ Hide task panel. """ self.aui_manager.GetPane("Tasks").Hide() self.aui_manager.Update() - def _SetProjectName(self, pubsub_evt): + def _SetProjectName(self, proj_name=""): """ Set project name into frame's title. """ - proj_name = pubsub_evt.data - if not(proj_name): self.SetTitle("InVesalius 3") else: self.SetTitle("%s - InVesalius 3"%(proj_name)) - def _ShowContentPanel(self, evt_pubsub): + def _ShowContentPanel(self): """ Show viewers and task, hide import panel. """ Publisher.sendMessage("Set layout button full") aui_manager = self.aui_manager aui_manager.GetPane("Import").Show(0) - + aui_manager.GetPane("ImportBMP").Show(0) aui_manager.GetPane("Data").Show(1) aui_manager.GetPane("Tasks").Show(1) aui_manager.Update() - def _ShowImportNetwork(self, evt_pubsub): + def _ShowImportNetwork(self): """ Show viewers and task, hide import panel. """ @@ -338,7 +336,7 @@ class Frame(wx.Frame): aui_manager.GetPane("Import").Show(0) aui_manager.Update() - def _ShowImportBitmap(self, evt_pubsub): + def _ShowImportBitmap(self): """ Show viewers and task, hide import panel. """ @@ -350,15 +348,14 @@ class Frame(wx.Frame): aui_manager.GetPane("Import").Show(0) aui_manager.Update() - def _ShowHelpMessage(self, evt_pubsub): + def _ShowHelpMessage(self, message): aui_manager = self.aui_manager pos = aui_manager.GetPane("Data").window.GetScreenPosition() - msg = evt_pubsub.data - self.mw = MessageWatershed(self, msg) + self.mw = MessageWatershed(self, message) self.mw.SetPosition(pos) self.mw.Show() - def _ShowImportPanel(self, evt_pubsub): + def _ShowImportPanel(self): """ Show only DICOM import panel. as dicom """ Publisher.sendMessage("Set layout button data only") @@ -368,14 +365,14 @@ class Frame(wx.Frame): aui_manager.GetPane("Tasks").Show(0) aui_manager.Update() - def _ShowTask(self, pubsub_evt): + def _ShowTask(self): """ Show task panel. """ self.aui_manager.GetPane("Tasks").Show() self.aui_manager.Update() - def _UpdateAUI(self, pubsub_evt): + def _UpdateAUI(self): """ Refresh AUI panels/data. """ @@ -457,19 +454,19 @@ class Frame(wx.Frame): self.OnReorientImg() elif id == const.ID_THRESHOLD_SEGMENTATION: - Publisher.sendMessage("Show panel", const.ID_THRESHOLD_SEGMENTATION) + Publisher.sendMessage("Show panel", panel_id=const.ID_THRESHOLD_SEGMENTATION) Publisher.sendMessage('Disable actual style') - Publisher.sendMessage('Enable style', const.STATE_DEFAULT) + Publisher.sendMessage('Enable style', style=const.STATE_DEFAULT) elif id == const.ID_MANUAL_SEGMENTATION: - Publisher.sendMessage("Show panel", const.ID_MANUAL_SEGMENTATION) + Publisher.sendMessage("Show panel", panel_id=const.ID_MANUAL_SEGMENTATION) Publisher.sendMessage('Disable actual style') - Publisher.sendMessage('Enable style', const.SLICE_STATE_EDITOR) + Publisher.sendMessage('Enable style', style=const.SLICE_STATE_EDITOR) elif id == const.ID_WATERSHED_SEGMENTATION: - Publisher.sendMessage("Show panel", const.ID_WATERSHED_SEGMENTATION) + Publisher.sendMessage("Show panel", panel_id=const.ID_WATERSHED_SEGMENTATION) Publisher.sendMessage('Disable actual style') - Publisher.sendMessage('Enable style', const.SLICE_STATE_WATERSHED) + Publisher.sendMessage('Enable style', style=const.SLICE_STATE_WATERSHED) elif id == const.ID_FLOODFILL_MASK: self.OnFillHolesManually() @@ -507,13 +504,13 @@ class Frame(wx.Frame): Publisher.sendMessage('New mask from shortcut') def OnInterpolatedSlices(self, status): - Publisher.sendMessage('Set interpolated slices', status) + Publisher.sendMessage('Set interpolated slices', flag=status) def OnNavigationMode(self, status): if status and self._show_navigator_message and sys.platform != 'win32': wx.MessageBox(_('Currently the Navigation mode is only working on Windows'), 'Info', wx.OK | wx.ICON_INFORMATION) self._show_navigator_message = False - Publisher.sendMessage('Set navigation mode', status) + Publisher.sendMessage('Set navigation mode', status=status) if not status: Publisher.sendMessage('Remove sensors ID') @@ -554,7 +551,7 @@ class Frame(wx.Frame): ses.Session().WriteSessionFile() Publisher.sendMessage('Remove Volume') - Publisher.sendMessage('Reset Reaycasting') + Publisher.sendMessage('Reset Raycasting') Publisher.sendMessage('Update Slice Interpolation') Publisher.sendMessage('Update Slice Interpolation MenuBar') Publisher.sendMessage('Update Navigation Mode MenuBar') @@ -570,7 +567,7 @@ class Frame(wx.Frame): """ Save project. """ - Publisher.sendMessage('Show save dialog', False) + Publisher.sendMessage('Show save dialog', save_as=False) def ShowGettingStarted(self): """ @@ -596,7 +593,7 @@ class Frame(wx.Frame): """ Show import Analyze, NiFTI1 or PAR/REC dialog. """ - Publisher.sendMessage('Show import other files dialog', id_file) + Publisher.sendMessage('Show import other files dialog', id_type=id_file) def ShowRetrieveDicomPanel(self): Publisher.sendMessage('Show retrieve dicom panel') @@ -611,20 +608,20 @@ class Frame(wx.Frame): """ Show save as dialog. """ - Publisher.sendMessage('Show save dialog', True) + Publisher.sendMessage('Show save dialog', save_as=True) def ShowBitmapImporter(self): """ Tiff, BMP, JPEG and PNG """ - Publisher.sendMessage('Show bitmap dialog', True) + Publisher.sendMessage('Show bitmap dialog') def FlipVolume(self, axis): - Publisher.sendMessage('Flip volume', axis) + Publisher.sendMessage('Flip volume', axis=axis) Publisher.sendMessage('Reload actual slice') def SwapAxes(self, axes): - Publisher.sendMessage('Swap volume axes', axes) + Publisher.sendMessage('Swap volume axes', axes=axes) Publisher.sendMessage('Update scroll') Publisher.sendMessage('Reload actual slice') @@ -642,31 +639,31 @@ class Frame(wx.Frame): Publisher.sendMessage('Reload actual slice') def OnReorientImg(self): - Publisher.sendMessage('Enable style', const.SLICE_STATE_REORIENT) + Publisher.sendMessage('Enable style', style=const.SLICE_STATE_REORIENT) rdlg = dlg.ReorientImageDialog() rdlg.Show() def OnFillHolesManually(self): - Publisher.sendMessage('Enable style', const.SLICE_STATE_MASK_FFILL) + Publisher.sendMessage('Enable style', style=const.SLICE_STATE_MASK_FFILL) def OnFillHolesAutomatically(self): fdlg = dlg.FillHolesAutoDialog(_(u"Fill holes automatically")) fdlg.Show() def OnRemoveMaskParts(self): - Publisher.sendMessage('Enable style', const.SLICE_STATE_REMOVE_MASK_PARTS) + Publisher.sendMessage('Enable style', style=const.SLICE_STATE_REMOVE_MASK_PARTS) def OnSelectMaskParts(self): - Publisher.sendMessage('Enable style', const.SLICE_STATE_SELECT_MASK_PARTS) + Publisher.sendMessage('Enable style', style=const.SLICE_STATE_SELECT_MASK_PARTS) def OnFFillSegmentation(self): - Publisher.sendMessage('Enable style', const.SLICE_STATE_FFILL_SEGMENTATION) + Publisher.sendMessage('Enable style', style=const.SLICE_STATE_FFILL_SEGMENTATION) def OnInterpolatedSlices(self, status): - Publisher.sendMessage('Set interpolated slices', status) - + Publisher.sendMessage('Set interpolated slices', flag=status) + def OnCropMask(self): - Publisher.sendMessage('Enable style', const.SLICE_STATE_CROP_MASK) + Publisher.sendMessage('Enable style', style=const.SLICE_STATE_CROP_MASK) # ------------------------------------------------------------------ # ------------------------------------------------------------------ @@ -959,20 +956,19 @@ class MenuBar(wx.MenuBar): else: return False - def OnUpdateSliceInterpolation(self, pubsub_evt): + def OnUpdateSliceInterpolation(self): v = self.SliceInterpolationStatus() self.view_menu.Check(const.ID_VIEW_INTERPOLATED, v) - def OnUpdateNavigationMode(self, pubsub_evt): + def OnUpdateNavigationMode(self): v = self.NavigationModeStatus() self.mode_menu.Check(const.ID_MODE_NAVIGATION, v) - def OnEnableState(self, pubsub_evt): + def OnEnableState(self, state): """ Based on given state, enables or disables menu items which depend if project is open or not. """ - state = pubsub_evt.data if state: self.SetStateProjectOpen() else: @@ -992,41 +988,38 @@ class MenuBar(wx.MenuBar): for item in self.enable_items: self.Enable(item, True) - def OnEnableUndo(self, pubsub_evt): - value = pubsub_evt.data + def OnEnableUndo(self, value): if value: self.FindItemById(wx.ID_UNDO).Enable(True) else: self.FindItemById(wx.ID_UNDO).Enable(False) - def OnEnableRedo(self, pubsub_evt): - value = pubsub_evt.data + def OnEnableRedo(self, value): if value: self.FindItemById(wx.ID_REDO).Enable(True) else: self.FindItemById(wx.ID_REDO).Enable(False) - def OnEnableNavigation(self, pubsub_evt): + def OnEnableNavigation(self, status): """ Disable mode menu when navigation is on. - :param pubsub_evt: Navigation status + :param status: Navigation status """ - value = pubsub_evt.data + value = status if value: self.FindItemById(const.ID_MODE_NAVIGATION).Enable(False) else: self.FindItemById(const.ID_MODE_NAVIGATION).Enable(True) - def OnAddMask(self, pubsub_evt): + def OnAddMask(self, mask): self.num_masks += 1 self.bool_op_menu.Enable(self.num_masks >= 2) - def OnRemoveMasks(self, pubsub_evt): - self.num_masks -= len(pubsub_evt.data) + def OnRemoveMasks(self, mask_indexes): + self.num_masks -= len(mask_indexes) self.bool_op_menu.Enable(self.num_masks >= 2) - def OnShowMask(self, pubsub_evt): - index, value = pubsub_evt.data + def OnShowMask(self, index, value): self.clean_mask_menu.Enable(value) self.crop_mask_menu.Enable(value) @@ -1054,7 +1047,7 @@ class ProgressBar(wx.Gauge): sub = Publisher.subscribe sub(self._Layout, 'ProgressBar Reposition') - def _Layout(self, evt_pubsub=None): + def _Layout(self): """ Compute new size and position, according to parent resize """ @@ -1104,12 +1097,11 @@ class StatusBar(wx.StatusBar): sub(self._SetProgressValue, 'Update status in GUI') sub(self._SetProgressLabel, 'Update status text in GUI') - def _SetProgressValue(self, pubsub_evt): + def _SetProgressValue(self, value, label): """ Set both percentage value in gauge and text progress label in status. """ - value, label = pubsub_evt.data self.progress_bar.SetPercentage(value) self.SetStatusText(label, 0) if (int(value) >= 99): @@ -1123,11 +1115,10 @@ class StatusBar(wx.StatusBar): except(wx._core.PyAssertionError): utils.debug("wx._core.PyAssertionError") - def _SetProgressLabel(self, pubsub_evt): + def _SetProgressLabel(self, label): """ Set text progress label. """ - label = pubsub_evt.data self.SetStatusText(label, 0) # ------------------------------------------------------------------ @@ -1262,12 +1253,11 @@ class ProjectToolBar(AuiToolBar): # "Print medical image...", # BMP_PRINT) - def _EnableState(self, pubsub_evt): + def _EnableState(self, state): """ Based on given state, enable or disable menu items which depend if project is open or not. """ - state = pubsub_evt.data if state: self.SetStateProjectOpen() else: @@ -1445,19 +1435,18 @@ class ObjectToolBar(AuiToolBar): # bitmap = BMP_ANNOTATE, # kind = wx.ITEM_CHECK) - def _EnableState(self, pubsub_evt): + def _EnableState(self, state): """ Based on given state, enable or disable menu items which depend if project is open or not. """ - state = pubsub_evt.data if state: self.SetStateProjectOpen() else: self.SetStateProjectClose() self.Refresh() - def _UntoggleAllItems(self, pubsub_evt=None): + def _UntoggleAllItems(self): """ Untoggle all items on toolbar. """ @@ -1467,14 +1456,14 @@ class ObjectToolBar(AuiToolBar): self.ToggleTool(id, False) self.Refresh() - def _ToggleLinearMeasure(self, pubsub_evt): + def _ToggleLinearMeasure(self): """ Force measure distance tool to be toggled and bind pubsub events to other classes whici are interested on this. """ id = const.STATE_MEASURE_DISTANCE self.ToggleTool(id, True) - Publisher.sendMessage('Enable style', id) + Publisher.sendMessage('Enable style', style=id) Publisher.sendMessage('Untoggle slice toolbar items') for item in const.TOOL_STATES: state = self.GetToolToggled(item) @@ -1482,14 +1471,14 @@ class ObjectToolBar(AuiToolBar): self.ToggleTool(item, False) - def _ToggleAngularMeasure(self, pubsub_evt): + def _ToggleAngularMeasure(self): """ Force measure angle tool to be toggled and bind pubsub events to other classes which are interested on this. """ id = const.STATE_MEASURE_ANGLE self.ToggleTool(id, True) - Publisher.sendMessage('Enable style', id) + Publisher.sendMessage('Enable style', style=id) Publisher.sendMessage('Untoggle slice toolbar items') for item in const.TOOL_STATES: state = self.GetToolToggled(item) @@ -1508,10 +1497,10 @@ class ObjectToolBar(AuiToolBar): Publisher.sendMessage('Fold measure task') if state: - Publisher.sendMessage('Enable style', id) + Publisher.sendMessage('Enable style', style=id) Publisher.sendMessage('Untoggle slice toolbar items') else: - Publisher.sendMessage('Disable style', id) + Publisher.sendMessage('Disable style', style=id) for item in const.TOOL_STATES: state = self.GetToolToggled(item) @@ -1519,8 +1508,7 @@ class ObjectToolBar(AuiToolBar): self.ToggleTool(item, False) evt.Skip() - def ToggleItem(self, evt): - _id, value = evt.data + def ToggleItem(self, _id, value): if _id in self.enable_items: self.ToggleTool(_id, value) self.Refresh() @@ -1613,12 +1601,11 @@ class SliceToolBar(AuiToolBar): """ self.Bind(wx.EVT_TOOL, self.OnToggle) - def _EnableState(self, pubsub_evt): + def _EnableState(self, state): """ Based on given state, enable or disable menu items which depend if project is open or not. """ - state = pubsub_evt.data if state: self.SetStateProjectOpen() else: @@ -1626,7 +1613,7 @@ class SliceToolBar(AuiToolBar): self._UntoggleAllItems() self.Refresh() - def _UntoggleAllItems(self, pubsub_evt=None): + def _UntoggleAllItems(self): """ Untoggle all items on toolbar. """ @@ -1636,16 +1623,15 @@ class SliceToolBar(AuiToolBar): self.ToggleTool(id, False) if id == const.SLICE_STATE_CROSS: msg = 'Set cross visibility' - Publisher.sendMessage(msg, 0) + Publisher.sendMessage(msg, visibility=0) self.Refresh() - def OnToggle(self, evt): + def OnToggle(self, evt=None, id=None): """ Update status of other items on toolbar (only one item should be toggle each time). """ - if hasattr(evt, 'data'): - id = evt.data + if id is not None: if not self.GetToolToggled(id): self.ToggleTool(id, True) self.Refresh() @@ -1656,10 +1642,10 @@ class SliceToolBar(AuiToolBar): state = self.GetToolToggled(id) if state: - Publisher.sendMessage('Enable style', id) + Publisher.sendMessage('Enable style', style=id) Publisher.sendMessage('Untoggle object toolbar items') else: - Publisher.sendMessage('Disable style', id) + Publisher.sendMessage('Disable style', style=id) for item in self.enable_items: state = self.GetToolToggled(item) @@ -1671,8 +1657,7 @@ class SliceToolBar(AuiToolBar): ##print ">>>", self.sst.IsToggled() #print ">>>", self.sst.GetState() - def ToggleItem(self, evt): - _id, value = evt.data + def ToggleItem(self, _id, value): if _id in self.enable_items: self.ToggleTool(_id, value) self.Refresh() @@ -1785,25 +1770,24 @@ class LayoutToolBar(AuiToolBar): wx.ITEM_NORMAL, short_help_string= _("Hide text")) - def _EnableState(self, pubsub_evt): + def _EnableState(self, state): """ Based on given state, enable or disable menu items which depend if project is open or not. """ - state = pubsub_evt.data if state: self.SetStateProjectOpen() else: self.SetStateProjectClose() self.Refresh() - def _SetLayoutWithoutTask(self, pubsub_evt): + def _SetLayoutWithoutTask(self): """ Set item bitmap to task panel hiden. """ self.SetToolNormalBitmap(ID_LAYOUT,self.BMP_WITHOUT_MENU) - def _SetLayoutWithTask(self, pubsub_evt): + def _SetLayoutWithTask(self): """ Set item bitmap to task panel shown. """ @@ -1958,25 +1942,24 @@ class HistoryToolBar(AuiToolBar): self.EnableTool(wx.ID_UNDO, False) self.EnableTool(wx.ID_REDO, False) - def _EnableState(self, pubsub_evt): + def _EnableState(self, state): """ Based on given state, enable or disable menu items which depend if project is open or not. """ - state = pubsub_evt.data if state: self.SetStateProjectOpen() else: self.SetStateProjectClose() self.Refresh() - def _SetLayoutWithoutTask(self, pubsub_evt): + def _SetLayoutWithoutTask(self): """ Set item bitmap to task panel hiden. """ self.SetToolNormalBitmap(ID_LAYOUT,self.BMP_WITHOUT_MENU) - def _SetLayoutWithTask(self, pubsub_evt): + def _SetLayoutWithTask(self): """ Set item bitmap to task panel shown. """ @@ -2054,16 +2037,14 @@ class HistoryToolBar(AuiToolBar): Publisher.sendMessage('Update AUI') self.ontool_text = True - def OnEnableUndo(self, pubsub_evt): - value = pubsub_evt.data + def OnEnableUndo(self, value): if value: self.EnableTool(wx.ID_UNDO, True) else: self.EnableTool(wx.ID_UNDO, False) self.Refresh() - def OnEnableRedo(self, pubsub_evt): - value = pubsub_evt.data + def OnEnableRedo(self, value): if value: self.EnableTool(wx.ID_REDO, True) else: diff --git a/invesalius/gui/import_bitmap_panel.py b/invesalius/gui/import_bitmap_panel.py index 25c2ce6..b744434 100644 --- a/invesalius/gui/import_bitmap_panel.py +++ b/invesalius/gui/import_bitmap_panel.py @@ -127,14 +127,13 @@ class InnerPanel(wx.Panel): Publisher.subscribe(self.ShowBitmapPreview, "Load import bitmap panel") Publisher.subscribe(self.GetSelectedImages ,"Selected Import Images") - def ShowBitmapPreview(self, pubsub_evt): - data = pubsub_evt.data + def ShowBitmapPreview(self, data): #self.patients.extend(dicom_groups) self.text_panel.Populate(data) - def GetSelectedImages(self, pubsub_evt): - self.first_image_selection = pubsub_evt.data[0] - self.last_image_selection = pubsub_evt.data[1] + def GetSelectedImages(self, selection): + self.first_image_selection = selection[0] + self.last_image_selection = selection[1] def _bind_events(self): self.Bind(EVT_SELECT_SLICE, self.OnSelectSlice) @@ -230,23 +229,23 @@ class TextPanel(wx.Panel): data_size = len(bpr.BitmapData().GetData()) if index >= 0 and index < data_size: - Publisher.sendMessage('Set bitmap in preview panel', index) + Publisher.sendMessage('Set bitmap in preview panel', pos=index) elif index == data_size and data_size > 0: - Publisher.sendMessage('Set bitmap in preview panel', index - 1) + Publisher.sendMessage('Set bitmap in preview panel', pos=index - 1) elif data_size == 1: - Publisher.sendMessage('Set bitmap in preview panel', 0) + Publisher.sendMessage('Set bitmap in preview panel', pos=0) else: Publisher.sendMessage('Show black slice in single preview image') self.tree.Delete(selected_item) self.tree.Update() self.tree.Refresh() - Publisher.sendMessage('Remove preview panel', text_item) + Publisher.sendMessage('Remove preview panel', data=text_item) evt.Skip() - def SelectSeries(self, pubsub_evt): - group_index = pubsub_evt.data + def SelectSeries(self, group_index): + pass def Populate(self, data): tree = self.tree @@ -259,7 +258,7 @@ class TextPanel(wx.Panel): tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate) tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged) - Publisher.sendMessage('Load bitmap into import panel', data) + Publisher.sendMessage('Load bitmap into import panel', data=data) def OnSelChanged(self, evt): self.selected_items = self.tree.GetSelections() @@ -269,7 +268,7 @@ class TextPanel(wx.Panel): text_item = self.tree.GetItemText(item) index = bpr.BitmapData().GetIndexByPath(text_item) - Publisher.sendMessage('Set bitmap in preview panel', index) + Publisher.sendMessage('Set bitmap in preview panel', pos=index) evt.Skip() @@ -369,14 +368,10 @@ class SeriesPanel(wx.Panel): def GetSelectedImagesRange(self): return [self.bitmap_preview.first_selected, self.dicom_preview_last_selection] - def SetBitmapFiles(self, pubsub_evt): - - - bitmap = pubsub_evt.data + def SetBitmapFiles(self, data): + bitmap = data self.thumbnail_preview.Show(1) - self.thumbnail_preview.SetBitmapFiles(bitmap) - self.Update() def OnSelectSerie(self, evt): @@ -420,8 +415,7 @@ class SlicePanel(wx.Panel): self.SetAutoLayout(1) self.sizer = sizer - def SetBitmapFiles(self, pubsub_evt): - data = pubsub_evt.data + def SetBitmapFiles(self, data): self.bitmap_preview.SetBitmapFiles(data) self.sizer.Layout() self.Update() diff --git a/invesalius/gui/import_network_panel.py b/invesalius/gui/import_network_panel.py index ac625a5..2d0629c 100644 --- a/invesalius/gui/import_network_panel.py +++ b/invesalius/gui/import_network_panel.py @@ -266,8 +266,8 @@ class TextPanel(wx.Panel): self.root = tree.AddRoot(_("InVesalius Database")) self.tree = tree - def SelectSeries(self, pubsub_evt): - group_index = pubsub_evt.data + def SelectSeries(self, group_index): + pass def Populate(self, pubsub_evt): tree = self.tree diff --git a/invesalius/gui/import_panel.py b/invesalius/gui/import_panel.py index 4c80466..2c8da54 100644 --- a/invesalius/gui/import_panel.py +++ b/invesalius/gui/import_panel.py @@ -129,9 +129,9 @@ class InnerPanel(wx.Panel): Publisher.subscribe(self.ShowDicomPreview, "Load import panel") Publisher.subscribe(self.GetSelectedImages ,"Selected Import Images") - def GetSelectedImages(self, pubsub_evt): - self.first_image_selection = pubsub_evt.data[0] - self.last_image_selection = pubsub_evt.data[1] + def GetSelectedImages(self, selection): + self.first_image_selection = selection[0] + self.last_image_selection = selection[1] def _bind_events(self): self.Bind(EVT_SELECT_SERIE, self.OnSelectSerie) @@ -141,8 +141,7 @@ class InnerPanel(wx.Panel): self.btn_cancel.Bind(wx.EVT_BUTTON, self.OnClickCancel) self.text_panel.Bind(EVT_SELECT_SERIE_TEXT, self.OnDblClickTextPanel) - def ShowDicomPreview(self, pubsub_evt): - dicom_groups = pubsub_evt.data + def ShowDicomPreview(self, dicom_groups): self.patients.extend(dicom_groups) self.text_panel.Populate(dicom_groups) @@ -187,8 +186,9 @@ class InnerPanel(wx.Panel): nslices_result = slice_amont / (interval + 1) if (nslices_result > 1): - Publisher.sendMessage('Open DICOM group', (group, interval, - [self.first_image_selection, self.last_image_selection])) + Publisher.sendMessage('Open DICOM group', group=group, + interval=interval, + file_range=(self.first_image_selection, self.last_image_selection)) else: dlg.MissingFilesForReconstruction() @@ -251,8 +251,8 @@ class TextPanel(wx.Panel): self.root = tree.AddRoot(_("InVesalius Database")) self.tree = tree - def SelectSeries(self, pubsub_evt): - group_index = pubsub_evt.data + def SelectSeries(self, group_index): + pass def Populate(self, patient_list): tree = self.tree @@ -313,7 +313,7 @@ class TextPanel(wx.Panel): group = self.tree.GetItemPyData(item) if isinstance(group, dcm.DicomGroup): Publisher.sendMessage('Load group into import panel', - group) + group=group) elif isinstance(group, dcm.PatientGroup): id = group.GetDicomSample().patient.id @@ -322,7 +322,7 @@ class TextPanel(wx.Panel): self.GetEventHandler().ProcessEvent(my_evt) Publisher.sendMessage('Load patient into import panel', - group) + patient=group) else: parent_id = self.tree.GetItemParent(item) self.tree.Expand(parent_id) @@ -430,8 +430,7 @@ class SeriesPanel(wx.Panel): self.serie_preview.Bind(dpp.EVT_CLICK_SERIE, self.OnSelectSerie) self.dicom_preview.Bind(dpp.EVT_CLICK_SLICE, self.OnSelectSlice) - def SetDicomSeries(self, pubsub_evt): - group = pubsub_evt.data + def SetDicomSeries(self, group): self.dicom_preview.SetDicomGroup(group) self.dicom_preview.Show(1) self.serie_preview.Show(0) @@ -441,9 +440,7 @@ class SeriesPanel(wx.Panel): def GetSelectedImagesRange(self): return [self.dicom_preview.first_selected, self.dicom_preview_last_selection] - def SetPatientSeries(self, pubsub_evt): - patient = pubsub_evt.data - + def SetPatientSeries(self, patient): self.dicom_preview.Show(0) self.serie_preview.Show(1) @@ -474,8 +471,7 @@ class SeriesPanel(wx.Panel): my_evt.SetItemData(evt.GetItemData()) self.GetEventHandler().ProcessEvent(my_evt) - def ShowDicomSeries(self, pubsub_evt): - patient = pubsub_evt.data + def ShowDicomSeries(self, patient): if isinstance(patient, dcm.PatientGroup): self.serie_preview.SetPatientGroups(patient) self.dicom_preview.SetPatientGroups(patient) @@ -505,21 +501,18 @@ class SlicePanel(wx.Panel): self.SetAutoLayout(1) self.sizer = sizer - def SetPatientSeries(self, pubsub_evt): - patient = pubsub_evt.data + def SetPatientSeries(self, patient): group = patient.GetGroups()[0] self.dicom_preview.SetDicomGroup(group) self.sizer.Layout() self.Update() - def SetDicomSeries(self, evt): - group = evt.data + def SetDicomSeries(self, group): self.dicom_preview.SetDicomGroup(group) self.sizer.Layout() self.Update() - def ShowDicomSeries(self, pubsub_evt): - patient = pubsub_evt.data + def ShowDicomSeries(self, patient): group = patient.GetGroups()[0] self.dicom_preview.SetDicomGroup(group) self.sizer.Layout() diff --git a/invesalius/gui/preferences.py b/invesalius/gui/preferences.py index 88f5313..ae9782c 100644 --- a/invesalius/gui/preferences.py +++ b/invesalius/gui/preferences.py @@ -81,7 +81,7 @@ class Preferences(wx.Dialog): return values - def LoadPreferences(self, pub_evt): + def LoadPreferences(self): se = ses.Session() values = {const.RENDERING:se.rendering, diff --git a/invesalius/gui/task_exporter.py b/invesalius/gui/task_exporter.py index da5b49d..1fbae89 100644 --- a/invesalius/gui/task_exporter.py +++ b/invesalius/gui/task_exporter.py @@ -267,7 +267,7 @@ class InnerTaskPanel(wx.Panel): if value: filename, filetype = value Publisher.sendMessage('Export picture to file', - (id, filename, filetype)) + orientation=id, filename=filename, filetype=filetype) @@ -299,7 +299,8 @@ class InnerTaskPanel(wx.Panel): filename = filename + "."+ extension filetype = const.FILETYPE_IMAGEDATA Publisher.sendMessage('Export mask to file', - (filename, filetype)) + filename=filename, + filetype=filetype) def OnLinkExportSurface(self, evt=None): @@ -335,7 +336,7 @@ class InnerTaskPanel(wx.Panel): if filename.split(".")[-1] != extension: filename = filename + "."+ extension Publisher.sendMessage('Export surface to file', - (filename, filetype)) + filename=filename, filetype=filetype) if not os.path.exists(filename): dlg = wx.MessageDialog(None, _("It was not possible to save the surface."), diff --git a/invesalius/gui/task_importer.py b/invesalius/gui/task_importer.py index 263b2dd..70834d0 100644 --- a/invesalius/gui/task_importer.py +++ b/invesalius/gui/task_importer.py @@ -235,15 +235,15 @@ class InnerTaskPanel(wx.Panel): def OpenProject(self, path=None): if path: - Publisher.sendMessage('Open recent project', path) + Publisher.sendMessage('Open recent project', filepath=path) else: Publisher.sendMessage('Show open project dialog') def SaveAsProject(self): - Publisher.sendMessage('Show save dialog', True) + Publisher.sendMessage('Show save dialog', save_as=True) def SaveProject(self): - Publisher.sendMessage('Show save dialog', False) + Publisher.sendMessage('Show save dialog', save_as=False) def CloseProject(self): Publisher.sendMessage('Close Project') diff --git a/invesalius/gui/task_navigator.py b/invesalius/gui/task_navigator.py index f7b297c..816c5b4 100644 --- a/invesalius/gui/task_navigator.py +++ b/invesalius/gui/task_navigator.py @@ -220,14 +220,13 @@ class InnerFoldPanel(wx.Panel): self.SetSizer(sizer) self.Update() self.SetAutoLayout(1) - + def __bind_events(self): Publisher.subscribe(self.OnCheckStatus, 'Navigation status') Publisher.subscribe(self.OnShowObject, 'Update track object state') Publisher.subscribe(self.OnVolumeCamera, 'Target navigation mode') - def OnCheckStatus(self, pubsub_evt): - status = pubsub_evt.data + def OnCheckStatus(self, status): if status: self.checktrigger.Enable(False) self.checkobj.Enable(False) @@ -237,27 +236,25 @@ class InnerFoldPanel(wx.Panel): self.checkobj.Enable(True) def OnExternalTrigger(self, evt, ctrl): - Publisher.sendMessage('Update trigger state', ctrl.GetValue()) + Publisher.sendMessage('Update trigger state', trigger_state=ctrl.GetValue()) - def OnShowObject(self, evt): - if hasattr(evt, 'data'): - if evt.data[0]: - self.checkobj.Enable(True) - self.track_obj = True - Publisher.sendMessage('Status target button', True) - else: - self.checkobj.Enable(False) - self.checkobj.SetValue(False) - self.track_obj = False - Publisher.sendMessage('Status target button', False) + def OnShowObject(self, evt=None, flag=None, obj_name=None): + if flag: + self.checkobj.Enable(True) + self.track_obj = True + Publisher.sendMessage('Status target button', status=True) + else: + self.checkobj.Enable(False) + self.checkobj.SetValue(False) + self.track_obj = False + Publisher.sendMessage('Status target button', status=False) - Publisher.sendMessage('Update show object state', self.checkobj.GetValue()) + Publisher.sendMessage('Update show object state', state=self.checkobj.GetValue()) - def OnVolumeCamera(self, evt): - if hasattr(evt, 'data'): - if evt.data is True: - self.checkcamera.SetValue(0) - Publisher.sendMessage('Update volume camera state', self.checkcamera.GetValue()) + def OnVolumeCamera(self, evt=None, target_mode=None): + if target_mode is True: + self.checkcamera.SetValue(0) + Publisher.sendMessage('Update volume camera state', camera_state=self.checkcamera.GetValue()) class NeuronavigationPanel(wx.Panel): @@ -402,9 +399,7 @@ class NeuronavigationPanel(wx.Panel): Publisher.subscribe(self.UpdateObjectRegistration, 'Update object registration') Publisher.subscribe(self.OnCloseProject, 'Close project data') - def LoadImageFiducials(self, pubsub_evt): - marker_id = pubsub_evt.data[0] - coord = pubsub_evt.data[1] + def LoadImageFiducials(self, marker_id, coord): for n in const.BTNS_IMG_MKS: btn_id = list(const.BTNS_IMG_MKS[n].keys())[0] fid_id = list(const.BTNS_IMG_MKS[n].values())[0] @@ -414,9 +409,9 @@ class NeuronavigationPanel(wx.Panel): for m in [0, 1, 2]: self.numctrls_coord[btn_id][m].SetValue(coord[m]) - def UpdateImageCoordinates(self, pubsub_evt): + def UpdateImageCoordinates(self, position): # TODO: Change from world coordinates to matrix coordinates. They are better for multi software communication. - self.current_coord = pubsub_evt.data + self.current_coord = position for m in [0, 1, 2, 6]: if m == 6 and self.btns_coord[m].IsEnabled(): for n in [0, 1, 2]: @@ -427,29 +422,27 @@ class NeuronavigationPanel(wx.Panel): for n in [0, 1, 2]: self.numctrls_coord[m][n].SetValue(float(self.current_coord[n])) - def UpdateObjectRegistration(self, pubsub_evt): - if pubsub_evt.data: - self.obj_reg = pubsub_evt.data + def UpdateObjectRegistration(self, data=None): + if data: + self.obj_reg = data self.obj_reg_status = True else: self.obj_reg = None self.obj_reg_status = False - def UpdateTrackObjectState(self, pubsub_evt): - if pubsub_evt.data[0]: - self.track_obj = pubsub_evt.data[0] - else: - self.track_obj = False + def UpdateTrackObjectState(self, evt=None, flag=None, obj_name=None): + self.track_obj = flag - def UpdateTriggerState(self, pubsub_evt): - self.trigger_state = pubsub_evt.data + def UpdateTriggerState(self, trigger_state): + self.trigger_state = trigger_state - def OnDisconnectTracker(self, pubsub_evt): + def OnDisconnectTracker(self): if self.tracker_id: dt.TrackerConnection(self.tracker_id, self.trk_init[0], 'disconnect') def OnChoiceTracker(self, evt, ctrl): - Publisher.sendMessage('Update status text in GUI', _("Configuring tracker ...")) + Publisher.sendMessage('Update status text in GUI', + label=_("Configuring tracker ...")) if hasattr(evt, 'GetSelection'): choice = evt.GetSelection() else: @@ -464,24 +457,28 @@ class NeuronavigationPanel(wx.Panel): # has been initialized before if trck and choice != 6: self.ResetTrackerFiducials() - Publisher.sendMessage('Update status text in GUI', _("Disconnecting tracker...")) + Publisher.sendMessage('Update status text in GUI', + label=_("Disconnecting tracker...")) Publisher.sendMessage('Remove sensors ID') self.trk_init = dt.TrackerConnection(self.tracker_id, trck, 'disconnect') self.tracker_id = choice if not self.trk_init[0] and choice: - Publisher.sendMessage('Update status text in GUI', _("Tracker disconnected successfully")) + Publisher.sendMessage('Update status text in GUI', + label=_("Tracker disconnected successfully")) self.trk_init = dt.TrackerConnection(self.tracker_id, None, 'connect') if not self.trk_init[0]: dlg.NavigationTrackerWarning(self.tracker_id, self.trk_init[1]) ctrl.SetSelection(0) print("Tracker not connected!") else: - Publisher.sendMessage('Update status text in GUI', _("Ready")) + Publisher.sendMessage('Update status text in GUI', + label=_("Ready")) ctrl.SetSelection(self.tracker_id) print("Tracker connected!") elif choice == 6: if trck: - Publisher.sendMessage('Update status text in GUI', _("Disconnecting tracker ...")) + Publisher.sendMessage('Update status text in GUI', + label=_("Disconnecting tracker ...")) Publisher.sendMessage('Remove sensors ID') self.trk_init = dt.TrackerConnection(self.tracker_id, trck, 'disconnect') if not self.trk_init[0]: @@ -489,10 +486,12 @@ class NeuronavigationPanel(wx.Panel): dlg.NavigationTrackerWarning(self.tracker_id, 'disconnect') self.tracker_id = 0 ctrl.SetSelection(self.tracker_id) - Publisher.sendMessage('Update status text in GUI', _("Tracker disconnected")) + Publisher.sendMessage('Update status text in GUI', + label=_("Tracker disconnected")) print("Tracker disconnected!") else: - Publisher.sendMessage('Update status text in GUI', _("Tracker still connected")) + Publisher.sendMessage('Update status text in GUI', + label=_("Tracker still connected")) print("Tracker still connected!") else: ctrl.SetSelection(self.tracker_id) @@ -507,9 +506,11 @@ class NeuronavigationPanel(wx.Panel): self.tracker_id = 0 ctrl.SetSelection(self.tracker_id) else: - Publisher.sendMessage('Update status text in GUI', _("Ready")) + Publisher.sendMessage('Update status text in GUI', + label=_("Ready")) - Publisher.sendMessage('Update tracker initializer', (self.tracker_id, self.trk_init, self.ref_mode_id)) + Publisher.sendMessage('Update tracker initializer', + nav_prop=(self.tracker_id, self.trk_init, self.ref_mode_id)) def OnChoiceRefMode(self, evt, ctrl): # When ref mode is changed the tracker coordinates are set to zero @@ -518,7 +519,8 @@ class NeuronavigationPanel(wx.Panel): # Some trackers do not accept restarting within this time window # TODO: Improve the restarting of trackers after changing reference mode # self.OnChoiceTracker(None, ctrl) - Publisher.sendMessage('Update tracker initializer', (self.tracker_id, self.trk_init, self.ref_mode_id)) + Publisher.sendMessage('Update tracker initializer', + nav_prop=(self.tracker_id, self.trk_init, self.ref_mode_id)) print("Reference mode changed!") def OnSetImageCoordinates(self, evt): @@ -529,10 +531,10 @@ class NeuronavigationPanel(wx.Panel): self.numctrls_coord[btn_id][1].GetValue(),\ self.numctrls_coord[btn_id][2].GetValue() - Publisher.sendMessage('Set ball reference position', (ux, uy, uz)) + Publisher.sendMessage('Set ball reference position', position=(ux, uy, uz)) # Publisher.sendMessage('Set camera in volume', (ux, uy, uz)) - Publisher.sendMessage('Co-registered points', ((ux, uy, uz), (0., 0., 0.))) - Publisher.sendMessage('Update cross position', (ux, uy, uz)) + Publisher.sendMessage('Co-registered points', arg=(ux, uy, uz), position=(0., 0., 0.)) + Publisher.sendMessage('Update cross position', position=(ux, uy, uz)) def OnImageFiducials(self, evt): btn_id = list(const.BTNS_IMG_MKS[evt.GetId()].keys())[0] @@ -544,13 +546,13 @@ class NeuronavigationPanel(wx.Panel): self.numctrls_coord[btn_id][2].GetValue(), 0, 0, 0 self.fiducials[btn_id, :] = coord[0:3] - Publisher.sendMessage('Create marker', (coord, marker_id)) + Publisher.sendMessage('Create marker', coord=coord, marker_id=marker_id) else: for n in [0, 1, 2]: self.numctrls_coord[btn_id][n].SetValue(float(self.current_coord[n])) self.fiducials[btn_id, :] = np.nan - Publisher.sendMessage('Delete fiducial marker', marker_id) + Publisher.sendMessage('Delete fiducial marker', marker_id=marker_id) def OnTrackerFiducials(self, evt): btn_id = list(const.BTNS_TRK[evt.GetId()].keys())[0] @@ -627,8 +629,8 @@ class NeuronavigationPanel(wx.Panel): if self.trigger_state: self.trigger = trig.Trigger(nav_id) - Publisher.sendMessage("Navigation status", True) - Publisher.sendMessage("Toggle Cross", const.SLICE_STATE_CROSS) + Publisher.sendMessage("Navigation status", status=True) + Publisher.sendMessage("Toggle Cross", id=const.SLICE_STATE_CROSS) Publisher.sendMessage("Hide current mask") if self.track_obj: @@ -682,7 +684,7 @@ class NeuronavigationPanel(wx.Panel): self.correg.stop() - Publisher.sendMessage("Navigation status", False) + Publisher.sendMessage("Navigation status", status=False) def ResetImageFiducials(self): for m in range(0, 3): @@ -703,13 +705,13 @@ class NeuronavigationPanel(wx.Panel): self.txtctrl_fre.SetValue('') self.txtctrl_fre.SetBackgroundColour('WHITE') - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): self.ResetTrackerFiducials() self.ResetImageFiducials() self.OnChoiceTracker(False, self.choice_trck) - Publisher.sendMessage('Update object registration', False) - Publisher.sendMessage('Update track object state', (False, False)) - Publisher.sendMessage('Delete all markers', 'close') + Publisher.sendMessage('Update object registration') + Publisher.sendMessage('Update track object state', flag=False, obj_name=False) + Publisher.sendMessage('Delete all markers') # TODO: Reset camera initial focus Publisher.sendMessage('Reset cam clipping range') @@ -838,11 +840,11 @@ class ObjectRegistrationPanel(wx.Panel): Publisher.subscribe(self.UpdateNavigationStatus, 'Navigation status') Publisher.subscribe(self.OnCloseProject, 'Close project data') - def UpdateTrackerInit(self, pubsub_evt): - self.nav_prop = pubsub_evt.data + def UpdateTrackerInit(self, nav_prop): + self.nav_prop = nav_prop - def UpdateNavigationStatus(self, pubsub_evt): - nav_status = pubsub_evt.data + def UpdateNavigationStatus(self, status): + nav_status = status if nav_status: self.checkrecordcoords.Enable(1) self.checktrack.Enable(0) @@ -861,10 +863,10 @@ class ObjectRegistrationPanel(wx.Panel): Publisher.sendMessage('Enable target button', True) def OnSelectAngleThreshold(self, evt, ctrl): - Publisher.sendMessage('Update angle threshold', ctrl.GetValue()) + Publisher.sendMessage('Update angle threshold', angle=ctrl.GetValue()) def OnSelectDistThreshold(self, evt, ctrl): - Publisher.sendMessage('Update dist threshold', ctrl.GetValue()) + Publisher.sendMessage('Update dist threshold', dist_threshold=ctrl.GetValue()) def OnSelectTimestamp(self, evt, ctrl): self.timestamp = ctrl.GetValue() @@ -880,7 +882,7 @@ class ObjectRegistrationPanel(wx.Panel): None def OnTrackObject(self, evt, ctrl): - Publisher.sendMessage('Update track object state', (evt.GetSelection(), self.obj_name)) + Publisher.sendMessage('Update track object state', flag=evt.GetSelection(), obj_name=self.obj_name) def OnComboCoil(self, evt): # coil_name = evt.GetString() @@ -897,8 +899,9 @@ class ObjectRegistrationPanel(wx.Panel): if np.isfinite(self.obj_fiducials).all() and np.isfinite(self.obj_orients).all(): self.checktrack.Enable(1) Publisher.sendMessage('Update object registration', - (self.obj_fiducials, self.obj_orients, self.obj_ref_mode, self.obj_name)) - Publisher.sendMessage('Update status text in GUI', _("Ready")) + data=(self.obj_fiducials, self.obj_orients, self.obj_ref_mode, self.obj_name)) + Publisher.sendMessage('Update status text in GUI', + label=_("Ready")) except wx._core.PyAssertionError: # TODO FIX: win64 pass @@ -923,8 +926,8 @@ class ObjectRegistrationPanel(wx.Panel): self.checktrack.Enable(1) Publisher.sendMessage('Update object registration', - (self.obj_fiducials, self.obj_orients, self.obj_ref_mode, self.obj_name)) - Publisher.sendMessage('Update status text in GUI', _("Ready")) + data=(self.obj_fiducials, self.obj_orients, self.obj_ref_mode, self.obj_name)) + Publisher.sendMessage('Update status text in GUI', label=_("Ready")) wx.MessageBox(_("Object file successfully loaded"), _("Load")) def ShowSaveObjectDialog(self, evt): @@ -938,7 +941,7 @@ class ObjectRegistrationPanel(wx.Panel): np.savetxt(filename, data, fmt='%.4f', delimiter='\t', newline='\n', header=hdr) wx.MessageBox(_("Object file successfully saved"), _("Save")) - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): self.checkrecordcoords.SetValue(False) self.checkrecordcoords.Enable(0) self.checktrack.SetValue(False) @@ -1054,12 +1057,12 @@ class MarkersPanel(wx.Panel): Publisher.subscribe(self.OnCreateMarker, 'Create marker') Publisher.subscribe(self.UpdateNavigationStatus, 'Navigation status') - def UpdateCurrentCoord(self, pubsub_evt): - self.current_coord = pubsub_evt.data[1][:] + def UpdateCurrentCoord(self, arg, position): + self.current_coord = position[:] #self.current_angle = pubsub_evt.data[1][3:] - def UpdateNavigationStatus(self, pubsub_evt): - if pubsub_evt.data is False: + def UpdateNavigationStatus(self, status): + if not status: sleep(0.5) #self.current_coord[3:] = 0, 0, 0 self.nav_status = False @@ -1080,7 +1083,7 @@ class MarkersPanel(wx.Panel): menu_id.Destroy() def OnItemBlink(self, evt): - Publisher.sendMessage('Blink Marker', self.lc.GetFocusedItem()) + Publisher.sendMessage('Blink Marker', index=self.lc.GetFocusedItem()) def OnStopItemBlink(self, evt): Publisher.sendMessage('Stop Blink Marker') @@ -1107,7 +1110,7 @@ class MarkersPanel(wx.Panel): if self.tgt_flag: self.lc.SetItemBackgroundColour(self.tgt_index, 'white') - Publisher.sendMessage('Set target transparency', [False, self.tgt_index]) + Publisher.sendMessage('Set target transparency', status=False, index=self.tgt_index) self.lc.SetStringItem(self.tgt_index, 4, '') # Add the new ID to exported list if len(self.list_coord[self.tgt_index]) > 8: @@ -1118,16 +1121,16 @@ class MarkersPanel(wx.Panel): self.tgt_index = self.lc.GetFocusedItem() self.lc.SetItemBackgroundColour(self.tgt_index, 'RED') - Publisher.sendMessage('Update target', self.list_coord[self.tgt_index]) - Publisher.sendMessage('Set target transparency', [True, self.tgt_index]) - Publisher.sendMessage('Disable or enable coil tracker', True) + Publisher.sendMessage('Update target', coord=self.list_coord[self.tgt_index]) + Publisher.sendMessage('Set target transparency', status=True, index=self.tgt_index) + Publisher.sendMessage('Disable or enable coil tracker', status=True) self.OnMenuEditMarkerId('TARGET') self.tgt_flag = True dlg.NewTarget() - def OnDeleteAllMarkers(self, evt): + def OnDeleteAllMarkers(self, evt=None): if self.list_coord: - if hasattr(evt, 'data'): + if evt is None: result = wx.ID_OK else: result = dlg.DeleteAllMarkers() @@ -1135,22 +1138,21 @@ class MarkersPanel(wx.Panel): if result == wx.ID_OK: self.list_coord = [] self.marker_ind = 0 - Publisher.sendMessage('Remove all markers', self.lc.GetItemCount()) + Publisher.sendMessage('Remove all markers', indexes=self.lc.GetItemCount()) self.lc.DeleteAllItems() - Publisher.sendMessage('Stop Blink Marker', 'DeleteAll') + Publisher.sendMessage('Stop Blink Marker', index='DeleteAll') if self.tgt_flag: self.tgt_flag = self.tgt_index = None - Publisher.sendMessage('Disable or enable coil tracker', False) + Publisher.sendMessage('Disable or enable coil tracker', status=False) if not hasattr(evt, 'data'): dlg.DeleteTarget() - def OnDeleteSingleMarker(self, evt): + def OnDeleteSingleMarker(self, evt=None, marker_id=None): # OnDeleteSingleMarker is used for both pubsub and button click events # Pubsub is used for fiducial handle and button click for all others - if hasattr(evt, 'data'): - marker_id = evt.data + if marker_id is not None: if self.lc.GetItemCount(): for id_n in range(self.lc.GetItemCount()): item = self.lc.GetItem(id_n, 4) @@ -1168,7 +1170,7 @@ class MarkersPanel(wx.Panel): if index: if self.tgt_flag and self.tgt_index == index[0]: self.tgt_flag = self.tgt_index = None - Publisher.sendMessage('Disable or enable coil tracker', False) + Publisher.sendMessage('Disable or enable coil tracker', status=False) dlg.DeleteTarget() self.DeleteMarker(index) else: @@ -1181,14 +1183,14 @@ class MarkersPanel(wx.Panel): for n in range(0, self.lc.GetItemCount()): self.lc.SetStringItem(n, 0, str(n+1)) self.marker_ind -= 1 - Publisher.sendMessage('Remove marker', index) + Publisher.sendMessage('Remove marker', index=index) - def OnCreateMarker(self, evt): + def OnCreateMarker(self, evt=None, coord=None, marker_id=None): # OnCreateMarker is used for both pubsub and button click events # Pubsub is used for markers created with fiducial buttons, trigger and create marker button - if hasattr(evt, 'data'): - if evt.data is not None: - self.CreateMarker(evt.data[0], (0.0, 1.0, 0.0), self.marker_size, evt.data[1]) + if evt is None: + if coord: + self.CreateMarker(coord, (0.0, 1.0, 0.0), self.marker_size, marker_id) else: self.CreateMarker(self.current_coord, self.marker_colour, self.marker_size) else: @@ -1212,7 +1214,7 @@ class MarkersPanel(wx.Panel): if len(line) == 11: for i in const.BTNS_IMG_MKS: if line[10] in list(const.BTNS_IMG_MKS[i].values())[0]: - Publisher.sendMessage('Load image fiducials', (line[10], coord)) + Publisher.sendMessage('Load image fiducials', marker_id=line[10], coord=coord) elif line[10] == 'TARGET': target = count_line else: @@ -1230,7 +1232,7 @@ class MarkersPanel(wx.Panel): if len(line) == 8: for i in const.BTNS_IMG_MKS: if line[7] in list(const.BTNS_IMG_MKS[i].values())[0]: - Publisher.sendMessage('Load image fiducials', (line[7], coord)) + Publisher.sendMessage('Load image fiducials', marker_id=line[7], coord=coord) else: line.append("") self.CreateMarker(coord, colour, size, line[7]) @@ -1241,10 +1243,10 @@ class MarkersPanel(wx.Panel): def OnMarkersVisibility(self, evt, ctrl): if ctrl.GetValue(): - Publisher.sendMessage('Hide all markers', self.lc.GetItemCount()) + Publisher.sendMessage('Hide all markers', indexes=self.lc.GetItemCount()) ctrl.SetLabel('Show') else: - Publisher.sendMessage('Show all markers', self.lc.GetItemCount()) + Publisher.sendMessage('Show all markers', indexes=self.lc.GetItemCount()) ctrl.SetLabel('Hide') def OnSaveMarkers(self, evt): @@ -1278,7 +1280,7 @@ class MarkersPanel(wx.Panel): # TODO: Use matrix coordinates and not world coordinates as current method. # This makes easier for inter-software comprehension. - Publisher.sendMessage('Add marker', (self.marker_ind, size, colour, coord[0:3])) + Publisher.sendMessage('Add marker', ball_id=self.marker_ind, size=size, colour=colour, coord=coord[0:3]) self.marker_ind += 1 diff --git a/invesalius/gui/task_slice.py b/invesalius/gui/task_slice.py index d4e8545..6a6de71 100644 --- a/invesalius/gui/task_slice.py +++ b/invesalius/gui/task_slice.py @@ -190,7 +190,7 @@ class InnerTaskPanel(wx.Panel): "overwrite": overwrite} Publisher.sendMessage('Create surface from index', - {'method': method, 'options': srf_options}) + surface_parameters={'method': method, 'options': srf_options}) Publisher.sendMessage('Fold surface task') else: @@ -218,7 +218,9 @@ class InnerTaskPanel(wx.Panel): mask_name, thresh, colour = dialog.GetValue() if mask_name: Publisher.sendMessage('Create new mask', - (mask_name, thresh, colour)) + mask_name=mask_name, + thresh=thresh, + colour=colour) dialog.Destroy() def GetMaskSelected(self): @@ -371,23 +373,21 @@ class InnerFoldPanel(wx.Panel): if self.__id_editor == id: if closed: - Publisher.sendMessage('Disable style', const.SLICE_STATE_EDITOR) + Publisher.sendMessage('Disable style', style=const.SLICE_STATE_EDITOR) self.last_style = None else: - Publisher.sendMessage('Enable style', - const.SLICE_STATE_EDITOR) + Publisher.sendMessage('Enable style', style=const.SLICE_STATE_EDITOR) self.last_style = const.SLICE_STATE_EDITOR elif self.__id_watershed == id: if closed: - Publisher.sendMessage('Disable style', - const.SLICE_STATE_WATERSHED) + Publisher.sendMessage('Disable style', style=const.SLICE_STATE_WATERSHED) self.last_style = None else: - Publisher.sendMessage('Enable style', const.SLICE_STATE_WATERSHED) - Publisher.sendMessage('Show help message', 'Mark the object and the background') + Publisher.sendMessage('Enable style', style=const.SLICE_STATE_WATERSHED) + # Publisher.sendMessage('Show help message', 'Mark the object and the background') self.last_style = const.SLICE_STATE_WATERSHED else: - Publisher.sendMessage('Disable style', const.SLICE_STATE_EDITOR) + Publisher.sendMessage('Disable style', style=const.SLICE_STATE_EDITOR) self.last_style = None evt.Skip() @@ -399,18 +399,18 @@ class InnerFoldPanel(wx.Panel): self.fold_panel.SetMinSize((self.fold_panel.GetSize()[0], sizeNeeded )) self.fold_panel.SetSize((self.fold_panel.GetSize()[0], sizeNeeded)) - def OnRetrieveStyle(self, pubsub_evt): + def OnRetrieveStyle(self): if (self.last_style == const.SLICE_STATE_EDITOR): - Publisher.sendMessage('Enable style', const.SLICE_STATE_EDITOR) + Publisher.sendMessage('Enable style', style=const.SLICE_STATE_EDITOR) - def OnDisableStyle(self, pubsub_evt): + def OnDisableStyle(self): if (self.last_style == const.SLICE_STATE_EDITOR): - Publisher.sendMessage('Disable style', const.SLICE_STATE_EDITOR) + Publisher.sendMessage('Disable style', style=const.SLICE_STATE_EDITOR) - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): self.fold_panel.Expand(self.fold_panel.GetFoldPanel(0)) - def OnColapsePanel(self, pubsub_evt): + def OnColapsePanel(self, panel_id): panel_seg_id = { const.ID_THRESHOLD_SEGMENTATION: 0, const.ID_MANUAL_SEGMENTATION: 1, @@ -418,7 +418,7 @@ class InnerFoldPanel(wx.Panel): } try: - _id = panel_seg_id[pubsub_evt.data] + _id = panel_seg_id[panel_id] self.fold_panel.Expand(self.fold_panel.GetFoldPanel(_id)) except KeyError: pass @@ -515,7 +515,7 @@ class MaskProperties(wx.Panel): Publisher.subscribe(self.OnCloseProject, 'Close project data') Publisher.subscribe(self.SetThresholdValues2, 'Set threshold values') - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): self.CloseProject() def CloseProject(self): @@ -526,9 +526,8 @@ class MaskProperties(wx.Panel): for i in range(n-1, -1, -1): self.combo_thresh.Delete(i) - def OnRemoveMasks(self, pubsub_evt): - list_index = pubsub_evt.data - for i in list_index: + def OnRemoveMasks(self, mask_indexes): + for i in mask_indexes: self.combo_mask_name.Delete(i) if self.combo_mask_name.IsEmpty(): @@ -543,20 +542,18 @@ class MaskProperties(wx.Panel): self.combo_mask_name.Bind(wx.EVT_COMBOBOX, self.OnComboName) self.button_colour.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour) - def SelectMaskName(self, pubsub_evt): - index = pubsub_evt.data + def SelectMaskName(self, index): if index >= 0: self.combo_mask_name.SetSelection(index) else: self.combo_mask_name.SetValue('') - def ChangeMaskName(self, pubsub_evt): - index, name = pubsub_evt.data + def ChangeMaskName(self, index, name): self.combo_mask_name.SetString(index, name) self.combo_mask_name.Refresh() - def SetThresholdValues(self, pubsub_evt): - thresh_min, thresh_max = pubsub_evt.data + def SetThresholdValues(self, threshold_range): + thresh_min, thresh_max = threshold_range self.bind_evt_gradient = False self.gradient.SetMinValue(thresh_min) self.gradient.SetMaxValue(thresh_max) @@ -572,8 +569,8 @@ class MaskProperties(wx.Panel): self.combo_thresh.SetSelection(index) Project().threshold_modes[_("Custom")] = (thresh_min, thresh_max) - def SetThresholdValues2(self, pubsub_evt): - thresh_min, thresh_max = pubsub_evt.data + def SetThresholdValues2(self, threshold_range): + thresh_min, thresh_max = threshold_range self.gradient.SetMinValue(thresh_min) self.gradient.SetMaxValue(thresh_max) thresh = (thresh_min, thresh_max) @@ -586,17 +583,16 @@ class MaskProperties(wx.Panel): self.combo_thresh.SetSelection(index) Project().threshold_modes[_("Custom")] = (thresh_min, thresh_max) - def SetItemsColour(self, evt_pubsub): - colour = evt_pubsub.data + def SetItemsColour(self, colour): self.gradient.SetColour(colour) self.button_colour.SetColour(colour) - def AddMask(self, evt_pubsub): + def AddMask(self, mask): if self.combo_mask_name.IsEmpty(): self.Enable() - mask_name = evt_pubsub.data[1] - mask_thresh = evt_pubsub.data[2] - mask_colour = [int(c*255) for c in evt_pubsub.data[3]] + mask_name = mask.name + mask_thresh = mask.threshold_range + mask_colour = [int(c*255) for c in mask.colour] index = self.combo_mask_name.Append(mask_name) # self.combo_mask_name.SetSelection(index) # self.button_colour.SetColour(mask_colour) @@ -607,8 +603,7 @@ class MaskProperties(wx.Panel): x = self.combo_mask_name.GetSelection() return self.combo_mask_name.GetSelection() - def SetThresholdModes(self, pubsub_evt): - (thresh_modes_names, default_thresh) = pubsub_evt.data + def SetThresholdModes(self, thresh_modes_names, default_thresh): self.combo_thresh.SetItems(thresh_modes_names) self.threshold_modes_names = thresh_modes_names proj = Project() @@ -635,17 +630,17 @@ class MaskProperties(wx.Panel): self.gradient.SetMinValue(thresh_min) self.gradient.SetMaxValue(thresh_max) - def SetThresholdBounds(self, pubsub_evt): - thresh_min = pubsub_evt.data[0] - thresh_max = pubsub_evt.data[1] + def SetThresholdBounds(self, threshold_range): + thresh_min = threshold_range[0] + thresh_max = threshold_range[1] self.gradient.SetMinRange(thresh_min) self.gradient.SetMaxRange(thresh_max) def OnComboName(self, evt): mask_name = evt.GetString() mask_index = evt.GetSelection() - Publisher.sendMessage('Change mask selected', mask_index) - Publisher.sendMessage('Show mask', (mask_index, True)) + Publisher.sendMessage('Change mask selected', index=mask_index) + Publisher.sendMessage('Show mask', index=mask_index, value=True) def OnComboThresh(self, evt): (thresh_min, thresh_max) = Project().threshold_modes[evt.GetString()] @@ -658,7 +653,7 @@ class MaskProperties(wx.Panel): thresh_min = self.gradient.GetMinValue() thresh_max = self.gradient.GetMaxValue() Publisher.sendMessage('Set threshold values', - (thresh_min, thresh_max)) + threshold_range=(thresh_min, thresh_max)) session = ses.Session() session.ChangeProject() @@ -666,14 +661,14 @@ class MaskProperties(wx.Panel): thresh_min = self.gradient.GetMinValue() thresh_max = self.gradient.GetMaxValue() Publisher.sendMessage('Changing threshold values', - (thresh_min, thresh_max)) + threshold_range=(thresh_min, thresh_max)) session = ses.Session() session.ChangeProject() def OnSelectColour(self, evt): colour = evt.GetValue()[:3] self.gradient.SetColour(colour) - Publisher.sendMessage('Change mask colour', colour) + Publisher.sendMessage('Change mask colour', colour=colour) class EditionTools(wx.Panel): def __init__(self, parent): @@ -778,25 +773,23 @@ class EditionTools(wx.Panel): Publisher.subscribe(self.SetGradientColour, 'Add mask') Publisher.subscribe(self._set_brush_size, 'Set edition brush size') - def ChangeMaskColour(self, pubsub_evt): - colour = pubsub_evt.data + def ChangeMaskColour(self, colour): self.gradient_thresh.SetColour(colour) - def SetGradientColour(self, pubsub_evt): - vtk_colour = pubsub_evt.data[3] - wx_colour = [c*255 for c in vtk_colour] + def SetGradientColour(self, mask): + wx_colour = [c*255 for c in mask.colour] self.gradient_thresh.SetColour(wx_colour) - def SetThresholdValues(self, pubsub_evt): - thresh_min, thresh_max = pubsub_evt.data + def SetThresholdValues(self, threshold_range): + thresh_min, thresh_max = threshold_range self.bind_evt_gradient = False self.gradient_thresh.SetMinValue(thresh_min) self.gradient_thresh.SetMaxValue(thresh_max) self.bind_evt_gradient = True - def SetThresholdBounds(self, pubsub_evt): - thresh_min = pubsub_evt.data[0] - thresh_max = pubsub_evt.data[1] + def SetThresholdBounds(self, threshold_range): + thresh_min = threshold_range[0] + thresh_max = threshold_range[1] self.gradient_thresh.SetMinRange(thresh_min) self.gradient_thresh.SetMaxRange(thresh_max) self.gradient_thresh.SetMinValue(thresh_min) @@ -807,7 +800,7 @@ class EditionTools(wx.Panel): thresh_max = self.gradient_thresh.GetMaxValue() if self.bind_evt_gradient: Publisher.sendMessage('Set edition threshold values', - (thresh_min, thresh_max)) + threshold_range=(thresh_min, thresh_max)) def OnMenu(self, evt): SQUARE_BMP = wx.Bitmap(os.path.join(const.ICON_DIR, "brush_square.jpg"), wx.BITMAP_TYPE_JPEG) @@ -820,22 +813,21 @@ class EditionTools(wx.Panel): self.btn_brush_format.SetBitmap(bitmap[evt.GetId()]) - Publisher.sendMessage('Set brush format', brush[evt.GetId()]) + Publisher.sendMessage('Set brush format', cursor_format=brush[evt.GetId()]) def OnBrushSize(self, evt): """ """ # FIXME: Using wx.EVT_SPINCTRL in MacOS it doesnt capture changes only # in the text ctrl - so we are capturing only changes on text # Strangelly this is being called twice - Publisher.sendMessage('Set edition brush size',self.spin.GetValue()) + Publisher.sendMessage('Set edition brush size', size=self.spin.GetValue()) - def _set_brush_size(self, pubsub_evt): - size = pubsub_evt.data + def _set_brush_size(self, size): self.spin.SetValue(size) def OnComboBrushOp(self, evt): brush_op_id = evt.GetSelection() - Publisher.sendMessage('Set edition operation', brush_op_id) + Publisher.sendMessage('Set edition operation', operation=brush_op_id) if brush_op_id == const.BRUSH_THRESH: self.gradient_thresh.Enable() else: @@ -959,25 +951,24 @@ class WatershedTool(EditionTools): def __bind_pubsub_evt(self): Publisher.subscribe(self._set_brush_size, 'Set watershed brush size') - def ChangeMaskColour(self, pubsub_evt): - colour = pubsub_evt.data + def ChangeMaskColour(self, colour): self.gradient_thresh.SetColour(colour) - def SetGradientColour(self, pubsub_evt): - vtk_colour = pubsub_evt.data[3] + def SetGradientColour(self, mask): + vtk_colour = mask.colour wx_colour = [c*255 for c in vtk_colour] self.gradient_thresh.SetColour(wx_colour) - def SetThresholdValues(self, pubsub_evt): - thresh_min, thresh_max = pubsub_evt.data + def SetThresholdValues(self, threshold_range): + thresh_min, thresh_max = threshold_range self.bind_evt_gradient = False self.gradient_thresh.SetMinValue(thresh_min) self.gradient_thresh.SetMaxValue(thresh_max) self.bind_evt_gradient = True - def SetThresholdBounds(self, pubsub_evt): - thresh_min = pubsub_evt.data[0] - thresh_max = pubsub_evt.data[1] + def SetThresholdBounds(self, threshold_range): + thresh_min = threshold_range[0] + thresh_max = threshold_range[1] self.gradient_thresh.SetMinRange(thresh_min) self.gradient_thresh.SetMaxRange(thresh_max) self.gradient_thresh.SetMinValue(thresh_min) @@ -994,30 +985,29 @@ class WatershedTool(EditionTools): self.btn_brush_format.SetBitmap(bitmap[evt.GetId()]) - Publisher.sendMessage('Set watershed brush format', brush[evt.GetId()]) + Publisher.sendMessage('Set watershed brush format', brush_format=brush[evt.GetId()]) def OnBrushSize(self, evt): """ """ # FIXME: Using wx.EVT_SPINCTRL in MacOS it doesnt capture changes only # in the text ctrl - so we are capturing only changes on text # Strangelly this is being called twice - Publisher.sendMessage('Set watershed brush size',self.spin.GetValue()) + Publisher.sendMessage('Set watershed brush size', size=self.spin.GetValue()) - def _set_brush_size(self, pubsub_evt): - size = pubsub_evt.data + def _set_brush_size(self, size): self.spin.SetValue(size) def OnComboBrushOp(self, evt): brush_op = self.combo_brush_op.GetValue() - Publisher.sendMessage('Set watershed operation', brush_op) + Publisher.sendMessage('Set watershed operation', operation=brush_op) def OnCheckOverwriteMask(self, evt): value = self.check_box.GetValue() - Publisher.sendMessage('Set overwrite mask', value) + Publisher.sendMessage('Set overwrite mask', flag=value) def OnCheckWWWL(self, evt): value = self.ww_wl_cbox.GetValue() - Publisher.sendMessage('Set use ww wl', value) + Publisher.sendMessage('Set use ww wl', use_ww_wl=value) def OnConfig(self, evt): from invesalius.data.styles import WatershedConfig diff --git a/invesalius/gui/task_surface.py b/invesalius/gui/task_surface.py index 357ffb1..5bd4ca5 100644 --- a/invesalius/gui/task_surface.py +++ b/invesalius/gui/task_surface.py @@ -193,9 +193,9 @@ class InnerTaskPanel(wx.Panel): surface_options = dialog.GetValue() - Publisher.sendMessage('Create surface from index', surface_options) + Publisher.sendMessage('Create surface from index', + surface_parameters=surface_options) dialog.Destroy() - if evt: evt.Skip() @@ -424,12 +424,12 @@ class SurfaceTools(wx.Panel): def StartSeeding(self): print("Start Seeding") - Publisher.sendMessage('Enable style', const.VOLUME_STATE_SEED) + Publisher.sendMessage('Enable style', style=const.VOLUME_STATE_SEED) Publisher.sendMessage('Create surface by seeding - start') def EndSeeding(self): print("End Seeding") - Publisher.sendMessage('Disable style', const.VOLUME_STATE_SEED) + Publisher.sendMessage('Disable style', style=const.VOLUME_STATE_SEED) Publisher.sendMessage('Create surface by seeding - end') @@ -515,8 +515,7 @@ class SurfaceProperties(wx.Panel): Publisher.subscribe(self.OnRemoveSurfaces, 'Remove surfaces') - def OnRemoveSurfaces(self, pubsub_evt): - list_index = pubsub_evt.data + def OnRemoveSurfaces(self, surface_indexes): s = self.combo_surface_name.GetSelection() ns = 0 @@ -524,7 +523,7 @@ class SurfaceProperties(wx.Panel): new_dict = [] i = 0 for n, (name, index) in enumerate(old_dict): - if n not in list_index: + if n not in surface_indexes: new_dict.append([name, i]) if s == n: ns = i @@ -536,7 +535,7 @@ class SurfaceProperties(wx.Panel): if self.surface_list: self.combo_surface_name.SetSelection(ns) - def OnCloseProject(self, pubsub_evt): + def OnCloseProject(self): self.CloseProject() def CloseProject(self): @@ -545,16 +544,14 @@ class SurfaceProperties(wx.Panel): self.combo_surface_name.Delete(i) self.surface_list = [] - def ChangeSurfaceName(self, pubsub_evt): - index, name = pubsub_evt.data + def ChangeSurfaceName(self, index, name): self.surface_list[index][0] = name self.combo_surface_name.SetString(index, name) - def InsertNewSurface(self, pubsub_evt): - #not_update = len(pubsub_evt.data) == 5 - index = pubsub_evt.data[0] - name = pubsub_evt.data[1] - colour = [value*255 for value in pubsub_evt.data[2]] + def InsertNewSurface(self, surface): + index = surface.index + name = surface.name + colour = [value*255 for value in surface.colour] i = 0 try: i = self.surface_list.index([name, index]) @@ -570,21 +567,21 @@ class SurfaceProperties(wx.Panel): self.combo_surface_name.SetItems([n[0] for n in self.surface_list]) self.combo_surface_name.SetSelection(i) - transparency = 100*pubsub_evt.data[5] + transparency = 100*surface.transparency self.button_colour.SetColour(colour) self.slider_transparency.SetValue(transparency) - Publisher.sendMessage('Update surface data', (index)) + # Publisher.sendMessage('Update surface data', (index)) def OnComboName(self, evt): surface_name = evt.GetString() surface_index = evt.GetSelection() - Publisher.sendMessage('Change surface selected', self.surface_list[surface_index][1]) + Publisher.sendMessage('Change surface selected', surface_index=self.surface_list[surface_index][1]) def OnSelectColour(self, evt): colour = [value/255.0 for value in evt.GetValue()] Publisher.sendMessage('Set surface colour', - (self.combo_surface_name.GetSelection(), - colour)) + surface_index=self.combo_surface_name.GetSelection(), + colour=colour) def OnTransparency(self, evt): transparency = evt.GetInt()/float(MAX_TRANSPARENCY) @@ -594,8 +591,8 @@ class SurfaceProperties(wx.Panel): if (wx.Platform == "__WXMAC__"): transparency = evt.GetInt()/(0.96*float(MAX_TRANSPARENCY)) Publisher.sendMessage('Set surface transparency', - (self.combo_surface_name.GetSelection(), - transparency)) + surface_index=self.combo_surface_name.GetSelection(), + transparency=transparency) class QualityAdjustment(wx.Panel): diff --git a/invesalius/gui/task_tools.py b/invesalius/gui/task_tools.py index 56cfb41..b39e8af 100644 --- a/invesalius/gui/task_tools.py +++ b/invesalius/gui/task_tools.py @@ -128,12 +128,10 @@ class InnerTaskPanel(wx.Panel): print("TODO: Send Signal - Add text annotation (both 2d and 3d)") def OnLinkLinearMeasure(self): - Publisher.sendMessage('Enable style', - constants.STATE_MEASURE_DISTANCE) + Publisher.sendMessage('Enable style', style=constants.STATE_MEASURE_DISTANCE) def OnLinkAngularMeasure(self): - Publisher.sendMessage('Enable style', - constants.STATE_MEASURE_ANGLE) + Publisher.sendMessage('Enable style', style=constants.STATE_MEASURE_ANGLE) def OnButton(self, evt): id = evt.GetId() diff --git a/invesalius/gui/widgets/clut_raycasting.py b/invesalius/gui/widgets/clut_raycasting.py index 99e5b7c..ce6d97a 100644 --- a/invesalius/gui/widgets/clut_raycasting.py +++ b/invesalius/gui/widgets/clut_raycasting.py @@ -174,7 +174,7 @@ class CLUTRaycastingWidget(wx.Panel): print("Salvando") filename = dialog.ShowSavePresetDialog() if filename: - Publisher.sendMessage('Save raycasting preset', filename) + Publisher.sendMessage('Save raycasting preset', preset_name=filename) point = self._has_clicked_in_a_point((x, y)) # A point has been selected. It can be dragged. if point: diff --git a/invesalius/gui/widgets/slice_menu.py b/invesalius/gui/widgets/slice_menu.py index 536a783..7b02c76 100644 --- a/invesalius/gui/widgets/slice_menu.py +++ b/invesalius/gui/widgets/slice_menu.py @@ -181,7 +181,7 @@ class SliceMenu(wx.Menu): Publisher.subscribe(self._check_projection_menu, 'Check projection menu') - def FirstItemSelect(self, pusub_evt): + def FirstItemSelect(self): item = self.ID_TO_TOOL_ITEM[self.id_wl_first] item.Check(True) @@ -195,13 +195,12 @@ class SliceMenu(wx.Menu): # item = self.ID_TO_TOOL_ITEM[self.id_tiling_first] # item.Check(True) - def CheckWindowLevelOther(self, pubsub_evt): + def CheckWindowLevelOther(self): item = self.ID_TO_TOOL_ITEM[self.other_wl_id] item.Check() - def _check_projection_menu(self, pubsub_evt): - p_id = pubsub_evt.data - item = self.projection_items[p_id] + def _check_projection_menu(self, projection_id): + item = self.projection_items[projection_id] item.Check() def OnPopup(self, evt): @@ -211,11 +210,12 @@ class SliceMenu(wx.Menu): if(key in const.WINDOW_LEVEL.keys()): window, level = const.WINDOW_LEVEL[key] Publisher.sendMessage('Bright and contrast adjustment image', - (window, level)) - Publisher.sendMessage('Update window level value',\ - (window, level)) - Publisher.sendMessage('Update window and level text',\ - "WL: %d WW: %d"%(level, window)) + window=window, level=level) + Publisher.sendMessage('Update window level value', + window=window, + level=level) + # Publisher.sendMessage('Update window and level text', + # "WL: %d WW: %d"%(level, window)) Publisher.sendMessage('Update slice viewer') #Necessary update the slice plane in the volume case exists @@ -223,7 +223,7 @@ class SliceMenu(wx.Menu): elif(key in const.SLICE_COLOR_TABLE.keys()): values = const.SLICE_COLOR_TABLE[key] - Publisher.sendMessage('Change colour table from background image', values) + Publisher.sendMessage('Change colour table from background image', values=values) Publisher.sendMessage('Update slice viewer') if sys.platform.startswith('linux'): @@ -238,7 +238,7 @@ class SliceMenu(wx.Menu): elif key in self.plist_presets: values = presets.get_wwwl_preset_colours(self.plist_presets[key]) - Publisher.sendMessage('Change colour table from background image from plist', values) + Publisher.sendMessage('Change colour table from background image from plist', values=values) Publisher.sendMessage('Update slice viewer') if sys.platform.startswith('linux'): @@ -253,12 +253,12 @@ class SliceMenu(wx.Menu): elif(key in const.IMAGE_TILING.keys()): values = const.IMAGE_TILING[key] - Publisher.sendMessage('Set slice viewer layout', values) + Publisher.sendMessage('Set slice viewer layout', layout=values) Publisher.sendMessage('Update slice viewer') elif key in PROJECTIONS_ID: pid = PROJECTIONS_ID[key] - Publisher.sendMessage('Set projection type', pid) + Publisher.sendMessage('Set projection type', projection_id=pid) Publisher.sendMessage('Reload actual slice') elif key == _('Custom'): @@ -290,7 +290,7 @@ class SliceMenu(wx.Menu): if self.cdialog: self.cdialog.Hide() - def _close(self, pubsub_evt): + def _close(self): if self.cdialog: self.cdialog.Destroy() self.cdialog = None diff --git a/invesalius/presets.py b/invesalius/presets.py index 39ea1f8..7a39760 100644 --- a/invesalius/presets.py +++ b/invesalius/presets.py @@ -64,14 +64,13 @@ class Presets(): _("Custom"):(0, 0) }) self.__bind_events() - + def __bind_events(self): Publisher.subscribe(self.UpdateThresholdModes, - 'Update threshold limits list') - - def UpdateThresholdModes(self, evt): - - thresh_min, thresh_max = evt.data + 'Update threshold limits list') + + def UpdateThresholdModes(self, threshold_range): + thresh_min, thresh_max = threshold_range presets_list = (self.thresh_ct, self.thresh_mri) for presets in presets_list: @@ -87,7 +86,7 @@ class Presets(): t_min = thresh_min if (t_max > thresh_max): t_max = thresh_max - + # This has happened in Analyze files # TODO: find a good solution for presets in Analyze files if (t_min > thresh_max): @@ -96,9 +95,9 @@ class Presets(): t_max = thresh_max presets[key] = (t_min, t_max) - - Publisher.sendMessage('Update threshold limits', (thresh_min, - thresh_max)) + + Publisher.sendMessage('Update threshold limits', + threshold_range=(thresh_min, thresh_max)) def SavePlist(self, filename): filename = "%s$%s" % (filename, 'presets.plist') diff --git a/invesalius/reader/bitmap_reader.py b/invesalius/reader/bitmap_reader.py index 2b09df0..e496f40 100644 --- a/invesalius/reader/bitmap_reader.py +++ b/invesalius/reader/bitmap_reader.py @@ -242,12 +242,12 @@ class ProgressBitmapReader: def __init__(self): Publisher.subscribe(self.CancelLoad, "Cancel bitmap load") - def CancelLoad(self, evt_pubsub): + def CancelLoad(self): self.running = False self.stoped = True def SetWindowEvent(self, frame): - self.frame = frame + self.frame = frame def SetDirectoryPath(self, path,recursive=True): self.running = True @@ -255,10 +255,10 @@ class ProgressBitmapReader: self.GetBitmaps(path,recursive) def UpdateLoadFileProgress(self,cont_progress): - Publisher.sendMessage("Update bitmap load", cont_progress) + Publisher.sendMessage("Update bitmap load", data=cont_progress) def EndLoadFile(self, bitmap_list): - Publisher.sendMessage("End bitmap load", bitmap_list) + Publisher.sendMessage("End bitmap load", data=bitmap_list) def GetBitmaps(self, path, recursive): @@ -359,7 +359,7 @@ def ReadBitmap(filepath): except UnicodeDecodeError: measures_info = False if measures_info: - Publisher.sendMessage('Set bitmap spacing', measures_info) + Publisher.sendMessage('Set bitmap spacing', spacing=measures_info) return False diff --git a/invesalius/reader/dicom_reader.py b/invesalius/reader/dicom_reader.py index 0fbf53e..d3f587b 100644 --- a/invesalius/reader/dicom_reader.py +++ b/invesalius/reader/dicom_reader.py @@ -313,7 +313,7 @@ class ProgressDicomReader: def __init__(self): Publisher.subscribe(self.CancelLoad, "Cancel DICOM load") - def CancelLoad(self, evt_pubsub): + def CancelLoad(self): self.running = False self.stoped = True @@ -326,10 +326,10 @@ class ProgressDicomReader: self.GetDicomGroups(path,recursive) def UpdateLoadFileProgress(self,cont_progress): - Publisher.sendMessage("Update dicom load", cont_progress) + Publisher.sendMessage("Update dicom load", data=cont_progress) def EndLoadFile(self, patient_list): - Publisher.sendMessage("End dicom load", patient_list) + Publisher.sendMessage("End dicom load", patient_series=patient_list) def GetDicomGroups(self, path, recursive): -- libgit2 0.21.2