From 7f7b85264281679e6fe679c268ab649149ef8143 Mon Sep 17 00:00:00 2001 From: Kaushik-Iyer <84177184+Kaushik-Iyer@users.noreply.github.com> Date: Sun, 17 Mar 2024 01:23:41 +0530 Subject: [PATCH 1/2] Add progress bar to saving project --- invesalius/project.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/invesalius/project.py b/invesalius/project.py index f033fb0d3..3fa990004 100644 --- a/invesalius/project.py +++ b/invesalius/project.py @@ -206,6 +206,7 @@ def GetMeasuresDict(self): return measures def SavePlistProject(self, dir_, filename, compress=False): + progress_dialog = wx.ProgressDialog("Saving project", "Time remaining", maximum=6) dir_temp = decode(tempfile.mkdtemp(), const.FS_ENCODE) self.compress = compress @@ -241,6 +242,7 @@ def SavePlistProject(self, dir_, filename, compress=False): project['matrix'] = matrix filelist[self.matrix_filename] = 'matrix.dat' #shutil.copyfile(self.matrix_filename, filename_tmp) + progress_dialog.Update(1) # Saving the masks masks = {} @@ -248,6 +250,7 @@ def SavePlistProject(self, dir_, filename, compress=False): masks[str(index)] = self.mask_dict[index].SavePlist(dir_temp, filelist) project['masks'] = masks + progress_dialog.Update(2) # Saving the surfaces surfaces = {} @@ -255,6 +258,7 @@ def SavePlistProject(self, dir_, filename, compress=False): surfaces[str(index)] = self.surface_dict[index].SavePlist(dir_temp, filelist) project['surfaces'] = surfaces + progress_dialog.Update(3) # Saving the measurements measurements = self.GetMeasuresDict() @@ -264,10 +268,12 @@ def SavePlistProject(self, dir_, filename, compress=False): plistlib.dump(measurements, f) filelist[temp_mplist] = measurements_filename project['measurements'] = measurements_filename + progress_dialog.Update(4) os.close(fd_mplist) # Saving the annotations (empty in this version) project['annotations'] = {} + progress_dialog.Update(5) # Saving the main plist temp_fd, temp_plist = tempfile.mkstemp() @@ -286,6 +292,8 @@ def SavePlistProject(self, dir_, filename, compress=False): for f in filelist: if filelist[f].endswith('.plist'): os.remove(f) + progress_dialog.Update(6) + progress_dialog.Destroy() def OpenPlistProject(self, filename): if not const.VTK_WARNING: From fa814b380dd31662682faa6ec96ec9c738b4ae84 Mon Sep 17 00:00:00 2001 From: Kaushik-Iyer-skima Date: Mon, 1 Apr 2024 17:45:04 +0530 Subject: [PATCH 2/2] pubsub implementation --- invesalius/control.py | 1 + invesalius/gui/dialogs.py | 24 +++++++++++++++++++++++- invesalius/project.py | 17 +++++++++-------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/invesalius/control.py b/invesalius/control.py index d5bfeffb6..ba42cd2de 100644 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -379,6 +379,7 @@ def SaveProject(self, path=None, compress=False): proj = prj.Project() try: + dlg=dialogs.SaveProjectProgressWindow() prj.Project().SavePlistProject(dirpath, filename, compress) except PermissionError as err: if wx.GetApp() is None: diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 1ed91a418..bf8afdc34 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -17,7 +17,6 @@ # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais # detalhes. #-------------------------------------------------------------------------- - import itertools import os import random @@ -5391,6 +5390,29 @@ def Update(self, msg=None, value=None): def Close(self): self.dlg.Destroy() +class SaveProjectProgressWindow(object): + def __init__(self): + self.title = "InVesalius 3" + self.msg = _("Saving project ...") + self.style = wx.PD_APP_MODAL | wx.PD_APP_MODAL | wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME + self.dlg = wx.ProgressDialog(self.title, + self.msg, + parent=None, + style=self.style, + maximum=6) + self.running = True + self.error = None + self.dlg.Show() + + Publisher.subscribe(self.update, 'update_progress') + Publisher.subscribe(self.destroy, 'destroy_progress') + + + def update(self, value): + self.dlg.Update(value) + + def destroy(self): + wx.CallAfter(self.dlg.Destroy) class GoToDialog(wx.Dialog): def __init__(self, title=_("Go to slice ..."), init_orientation=const.AXIAL_STR): diff --git a/invesalius/project.py b/invesalius/project.py index 3fa990004..473380aa0 100644 --- a/invesalius/project.py +++ b/invesalius/project.py @@ -206,7 +206,6 @@ def GetMeasuresDict(self): return measures def SavePlistProject(self, dir_, filename, compress=False): - progress_dialog = wx.ProgressDialog("Saving project", "Time remaining", maximum=6) dir_temp = decode(tempfile.mkdtemp(), const.FS_ENCODE) self.compress = compress @@ -242,7 +241,7 @@ def SavePlistProject(self, dir_, filename, compress=False): project['matrix'] = matrix filelist[self.matrix_filename] = 'matrix.dat' #shutil.copyfile(self.matrix_filename, filename_tmp) - progress_dialog.Update(1) + Publisher.sendMessage('update_progress', value=1) # Saving the masks masks = {} @@ -250,7 +249,7 @@ def SavePlistProject(self, dir_, filename, compress=False): masks[str(index)] = self.mask_dict[index].SavePlist(dir_temp, filelist) project['masks'] = masks - progress_dialog.Update(2) + Publisher.sendMessage('update_progress',value=2) # Saving the surfaces surfaces = {} @@ -258,7 +257,7 @@ def SavePlistProject(self, dir_, filename, compress=False): surfaces[str(index)] = self.surface_dict[index].SavePlist(dir_temp, filelist) project['surfaces'] = surfaces - progress_dialog.Update(3) + Publisher.sendMessage('update_progress', value=3) # Saving the measurements measurements = self.GetMeasuresDict() @@ -268,12 +267,12 @@ def SavePlistProject(self, dir_, filename, compress=False): plistlib.dump(measurements, f) filelist[temp_mplist] = measurements_filename project['measurements'] = measurements_filename - progress_dialog.Update(4) + Publisher.sendMessage('update_progress', value=4) os.close(fd_mplist) # Saving the annotations (empty in this version) project['annotations'] = {} - progress_dialog.Update(5) + Publisher.sendMessage('update_progress', value=5) # Saving the main plist temp_fd, temp_plist = tempfile.mkstemp() @@ -292,8 +291,10 @@ def SavePlistProject(self, dir_, filename, compress=False): for f in filelist: if filelist[f].endswith('.plist'): os.remove(f) - progress_dialog.Update(6) - progress_dialog.Destroy() + Publisher.sendMessage('update_progress', value=6) + + Publisher.sendMessage('destroy_progress') + wx.Yield() def OpenPlistProject(self, filename): if not const.VTK_WARNING: