From 0e6b2d4e86f50f8ae9770bb794cc76430e6a3d06 Mon Sep 17 00:00:00 2001 From: Tomas Zigo Date: Wed, 12 Aug 2020 06:45:04 +0200 Subject: [PATCH] wxGUI/animation: add export output animation file validation, before export file --- gui/wxpython/animation/dialogs.py | 74 +++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/gui/wxpython/animation/dialogs.py b/gui/wxpython/animation/dialogs.py index 6dbf8d09f3c..4e90f459546 100644 --- a/gui/wxpython/animation/dialogs.py +++ b/gui/wxpython/animation/dialogs.py @@ -1503,12 +1503,25 @@ def OnExport(self, event): "Export directory is missing.")) return elif self.formatChoice.GetSelection() == 1: - if not self.gifBrowse.GetValue(): - GError(parent=self, message=_("Export file is missing.")) + if not self._export_file_validation( + filebrowsebtn=self.gifBrowse, + file_path=self.gifBrowse.GetValue(), + file_postfix='.gif', + ): return elif self.formatChoice.GetSelection() == 2: - if not self.swfBrowse.GetValue(): - GError(parent=self, message=_("Export file is missing.")) + if not self._export_file_validation( + filebrowsebtn=self.swfBrowse, + file_path=self.swfBrowse.GetValue(), + file_postfix='.swf', + ): + return + elif self.formatChoice.GetSelection() == 3: + if not self._export_file_validation( + filebrowsebtn=self.aviBrowse, + file_path=self.aviBrowse.GetValue(), + file_postfix='.avi', + ): return # hide only to keep previous values @@ -1560,6 +1573,59 @@ def _hideAll(self): self.hidevbox.Show(self.informBox, True) self.hidevbox.Layout() + def _export_file_validation(self, filebrowsebtn, file_path, + file_postfix): + """File validation before export + + :param obj filebrowsebutton: filebrowsebutton widget + :param str file_path: exported file path + :param str file_postfix: exported file postfix + (.gif, .swf, .avi) + + :return bool: True if validation is ok + """ + + file_path_does_not_exist_err_message = _( + "Exported file directory '{base_dir}' " + "does not exist." + ) + if not file_path: + GError(parent=self, message=_("Export file is missing.")) + return False + else: + if file_postfix not in file_path: + filebrowsebtn.SetValue(file_path + file_postfix) + file_path += file_postfix + + base_dir = os.path.dirname(file_path) + if not os.path.exists(base_dir): + GError( + parent=self, + message=file_path_does_not_exist_err_message.format( + base_dir=base_dir, + ), + ) + return False + + if os.path.exists(file_path): + overwrite_dlg = wx.MessageDialog( + self.GetParent(), + message=_( + "Exported animation file <{file}> exists. " + "Do you want to overwrite it?".format( + file=file_path, + ), + ), + caption=_("Overwrite?"), + style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION, + ) + if not overwrite_dlg.ShowModal() == wx.ID_YES: + overwrite_dlg.Destroy() + return False + overwrite_dlg.Destroy() + + return True + class AnimSimpleLayerManager(SimpleLayerManager): """Simple layer manager for animation tool.