Unable to destroy wx.Dialog in wxpython

混江龙づ霸主 提交于 2019-12-11 10:57:38

问题


After launching a process using subprocess.Popen() as shown, I would like to create a busy-window (wx.Dialog) with an "Abort"-button. This works as intended; however, in the case where the process is given the time needed to finish, the busy-window should be destroyed. In the code shown below, this does not happen?

import subprocess
import wx

ProcessToCall = [Some, process, with, some, arguments]

Process = subprocess.Popen(ProcessToCall)
BusyDialog = wx.Dialog(...)

if BusyDialog.ShowModal() == wx.ID_CANCEL:
    Process.kill()

Process.wait()
BusyDialog.Destroy()

I've been experimenting with EndModal and various other methods of wx.Dialog and consulted various tutorials online, but nothing seems to achieve the desired effect, and I'm all out of ideas.

I'm using Python 2.7 and wxPython 2.8 on Ubuntu 13.10.


回答1:


I think the problem is actually ShowModal, which won't exit until the user clicks something in the window to make it exit. From the docs:

Shows a modal dialog. Program flow does not return until the dialog has been dismissed with wxDialog::EndModal.

I think ShowModal is fine and appropriate, but you need to pass the process to the dialog, and the dialog probably needs some kind of periodic checking for the process to complete (perhaps EVT_TIMER) so that it can close itself and return when the process completes. It will still return the abort code if a user cancels, so you still want to catch that and kill the process if you see that.



来源:https://stackoverflow.com/questions/22383291/unable-to-destroy-wx-dialog-in-wxpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!