【发布时间】:2018-09-11 08:14:44
【问题描述】:
我正在设计某种pdf 转换器。它可以将图像和其他pdf文件合并为一个pdf文件。我正在使用wxPython 作为 GUI 框架。
有两个按钮:一个是设置输入文件,第二个是设置输出文件。 这是我的两个事件处理程序。
def pick_files(self, event):
with wx.FileDialog(self, "Pick files", wildcard=self.load_options,
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_MULTIPLE) as fileDialog:
if fileDialog.ShowModal() != wx.ID_CANCEL:
self.files_list = fileDialog.GetPaths()
self.convert_and_merge_button.Enable()
def convert_and_merge(self, event):
with wx.FileDialog(self, "Convert and merge", wildcard=self.save_options,
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fileDialog:
if fileDialog.ShowModal() != wx.ID_CANCEL:
# pass parameters to Converter class
self.converter.convert(self.files_list, fileDialog.GetPath())
问题是,如果我选择一个输入文件作为输出文件,程序就会崩溃。
如何防止在FileDialog 中选择某些文件?
我想知道是否有可能有某种MessageBox,比如“这个文件被设置为输入文件。你不能覆盖它。”并返回FileDialog。
【问题讨论】:
-
确保
self.save_options不包含self.load_options中的任何内容 -
@RolfofSaxony 好吧,问题是
self.load_options确实包含self.save_options,因为该转换器的目的是能够将两个图像和pdf合并到一个pdf文件中. -
您考虑过
load目录和save目录吗?顺便说一句,程序crash是通过什么方式实现的?