Commit 0aebaad33de12dd5a6f75bd8b39602af36ec2633
1 parent
079333b3
Exists in
master
Showing error message when trying to export project inside a folder without write permission
Showing
1 changed file
with
22 additions
and
6 deletions
Show diff stats
invesalius/gui/frame.py
@@ -23,6 +23,7 @@ import platform | @@ -23,6 +23,7 @@ import platform | ||
23 | import subprocess | 23 | import subprocess |
24 | import sys | 24 | import sys |
25 | import webbrowser | 25 | import webbrowser |
26 | +import errno | ||
26 | 27 | ||
27 | import invesalius.constants as const | 28 | import invesalius.constants as const |
28 | import invesalius.gui.default_tasks as tasks | 29 | import invesalius.gui.default_tasks as tasks |
@@ -687,19 +688,34 @@ class Frame(wx.Frame): | @@ -687,19 +688,34 @@ class Frame(wx.Frame): | ||
687 | 688 | ||
688 | session = ses.Session() | 689 | session = ses.Session() |
689 | last_directory = session.get('paths', 'last_directory_export_prj', '') | 690 | last_directory = session.get('paths', 'last_directory_export_prj', '') |
690 | - dlg = wx.FileDialog(None, | 691 | + fdlg = wx.FileDialog(None, |
691 | "Export slice ...", | 692 | "Export slice ...", |
692 | last_directory, # last used directory | 693 | last_directory, # last used directory |
693 | os.path.split(p.name)[-1], # initial filename | 694 | os.path.split(p.name)[-1], # initial filename |
694 | WILDCARD_EXPORT_SLICE, | 695 | WILDCARD_EXPORT_SLICE, |
695 | wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) | 696 | wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) |
696 | - if dlg.ShowModal() == wx.ID_OK: | ||
697 | - filename = dlg.GetPath() | ||
698 | - ext = IDX_EXT[dlg.GetFilterIndex()] | 697 | + if fdlg.ShowModal() == wx.ID_OK: |
698 | + filename = fdlg.GetPath() | ||
699 | + ext = IDX_EXT[fdlg.GetFilterIndex()] | ||
700 | + dirpath = os.path.split(filename)[0] | ||
699 | if not filename.endswith(ext): | 701 | if not filename.endswith(ext): |
700 | filename += ext | 702 | filename += ext |
701 | - p.export_project(filename) | ||
702 | - session['paths']['last_directory_export_prj'] = os.path.split(filename)[0] | 703 | + try: |
704 | + p.export_project(filename) | ||
705 | + except (OSError, IOError) as err: | ||
706 | + if err.errno == errno.EACCES: | ||
707 | + message = "It was not possible to save because you don't have permission to write at {}".format(dirpath) | ||
708 | + else: | ||
709 | + message = "It was not possible to save because" | ||
710 | + d = dlg.ErrorMessageBox( | ||
711 | + None, | ||
712 | + "Save project error", | ||
713 | + "{}:\n{}".format(message, err) | ||
714 | + ) | ||
715 | + d.ShowModal() | ||
716 | + d.Destroy() | ||
717 | + else: | ||
718 | + session['paths']['last_directory_export_prj'] = dirpath | ||
703 | 719 | ||
704 | def ShowProjectProperties(self): | 720 | def ShowProjectProperties(self): |
705 | window = project_properties.ProjectProperties(self) | 721 | window = project_properties.ProjectProperties(self) |