我制作了一个可运行的示例来演示错误行为:http : //pastebin.com/8KpzD4pw
这个问题非常令人恼火。我wx.ProgressDialog在保存文件时遇到了问题IOError,然后我想关闭进度对话框并显示错误消息。不幸的是,这似乎是不可能的。进度对话框在消息框关闭之前公然拒绝关闭:

如您所见,消息框出现在进度对话框下方,因此用户必须手动将焦点切换到消息框才能查看其内容。当消息框关闭时,进度对话框也会消失。这是保存函数的代码:
def save(self, path=None):
# Show a loading dialog while the document is staving.
progress = shared.show_loading(self, 'Saving document')
try:
raise IOError('Error message')
if not path:
self.document.save()
else:
self.document.save_to_file(path)
except IOError as e:
progress.done()
message = 'Failed to save file:\n\n{}'.format(e.message)
wx.MessageBox(message, 'Error', wx.OK | wx.ICON_ERROR)
progress.done()
Run Code Online (Sandbox Code Playgroud)
的show_loading和progress.done功能是使用只是快捷方式wx.ProgressDialog(源)。
我也试过用wx.CallAfter打开消息框,无济于事:
# ...
except IOError as e:
message = 'Failed to save file:\n\n{}'.format(e.message)
def show_error():
wx.MessageBox(message, 'Error', wx.OK | wx.ICON_ERROR)
progress.done()
wx.CallAfter(show_error)
# ...
Run Code Online (Sandbox Code Playgroud)
我还尝试在关闭进度对话框和打开消息框之间休眠 100 毫秒,wx.MicroSleep但没有成功。
我也尝试在销毁进度对话框后立即调用wx.Yield()和wx.WakeUpIdle(),但都没有任何效果。
只是出于好奇……您是否尝试过在调用 progressdialog.Destroy() 之后立即使用 wx.SafeYield() 或 wx.Yield() 或 wx.YieldIfNeeded() ?
您的示例无法按原样运行,所以我只是在黑暗中拍摄。
小智 3
我也遇到过类似的情况,最后通过调用以下方法解决了:
dlg.Update( dlg.GetRange( ) )
Run Code Online (Sandbox Code Playgroud)
看来,至少当您将进度对话框置于“脉冲”模式时,它不会立即响应 Destroy 调用。在销毁它之前或之后,无论进行多少睡眠或屈服,都无法说服我的进度对话框停止显示。然而,通过简单地将值更新为最大值,它似乎会立即自动销毁(或至少隐藏)自身。
| 归档时间: |
|
| 查看次数: |
2702 次 |
| 最近记录: |