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 | 23 | import subprocess |
24 | 24 | import sys |
25 | 25 | import webbrowser |
26 | +import errno | |
26 | 27 | |
27 | 28 | import invesalius.constants as const |
28 | 29 | import invesalius.gui.default_tasks as tasks |
... | ... | @@ -687,19 +688,34 @@ class Frame(wx.Frame): |
687 | 688 | |
688 | 689 | session = ses.Session() |
689 | 690 | last_directory = session.get('paths', 'last_directory_export_prj', '') |
690 | - dlg = wx.FileDialog(None, | |
691 | + fdlg = wx.FileDialog(None, | |
691 | 692 | "Export slice ...", |
692 | 693 | last_directory, # last used directory |
693 | 694 | os.path.split(p.name)[-1], # initial filename |
694 | 695 | WILDCARD_EXPORT_SLICE, |
695 | 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 | 701 | if not filename.endswith(ext): |
700 | 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 | 720 | def ShowProjectProperties(self): |
705 | 721 | window = project_properties.ProjectProperties(self) | ... | ... |