Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add progress bar to saving project #725

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions invesalius/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 23 additions & 1 deletion invesalius/gui/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
# detalhes.
#--------------------------------------------------------------------------

import itertools
import os
import random
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions invesalius/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,23 @@ def SavePlistProject(self, dir_, filename, compress=False):
project['matrix'] = matrix
filelist[self.matrix_filename] = 'matrix.dat'
#shutil.copyfile(self.matrix_filename, filename_tmp)
Publisher.sendMessage('update_progress', value=1)

# Saving the masks
masks = {}
for index in self.mask_dict:
masks[str(index)] = self.mask_dict[index].SavePlist(dir_temp,
filelist)
project['masks'] = masks
Publisher.sendMessage('update_progress',value=2)

# Saving the surfaces
surfaces = {}
for index in self.surface_dict:
surfaces[str(index)] = self.surface_dict[index].SavePlist(dir_temp,
filelist)
project['surfaces'] = surfaces
Publisher.sendMessage('update_progress', value=3)

# Saving the measurements
measurements = self.GetMeasuresDict()
Expand All @@ -264,10 +267,12 @@ def SavePlistProject(self, dir_, filename, compress=False):
plistlib.dump(measurements, f)
filelist[temp_mplist] = measurements_filename
project['measurements'] = measurements_filename
Publisher.sendMessage('update_progress', value=4)
os.close(fd_mplist)

# Saving the annotations (empty in this version)
project['annotations'] = {}
Publisher.sendMessage('update_progress', value=5)

# Saving the main plist
temp_fd, temp_plist = tempfile.mkstemp()
Expand All @@ -286,6 +291,10 @@ def SavePlistProject(self, dir_, filename, compress=False):
for f in filelist:
if filelist[f].endswith('.plist'):
os.remove(f)
Publisher.sendMessage('update_progress', value=6)

Publisher.sendMessage('destroy_progress')
wx.Yield()

def OpenPlistProject(self, filename):
if not const.VTK_WARNING:
Expand Down