Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top