Skip to content

Commit

Permalink
wxGUI/animation: add export output animation file validation, before …
Browse files Browse the repository at this point in the history
…export file
  • Loading branch information
tmszi committed Aug 12, 2020
1 parent 9bd3502 commit 0e6b2d4
Showing 1 changed file with 70 additions and 4 deletions.
74 changes: 70 additions & 4 deletions gui/wxpython/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0e6b2d4

Please sign in to comment.