I have recently migrated an application from python2.7.15 (wx 3.0.2.0) to python 3.7.9 (wx 4.1.1)
The application uses a wx.ProgressDialog set to Pulse() while waiting for some tasks to complete and then uses Destroy() to attempt to close the ProgressDialog window.
It runs without errors on Python27 but it crashes on Python37. In both ProgressDialog.Destroy() does not actually seem to close the dialog box but it is closed when the next wx element is displayed.
import wx
from time import sleep
def main():
app = wx.App()
progress_dlg = wx.ProgressDialog("Model Manager", "Connecting...")
progress_dlg.Pulse()
sleep(5) # some long tasks are done here
progress_dlg.Destroy()
print("waiting")
sleep(5)
extracted_names = ["ONE", "TWO", "THREE"]
CANDialog = wx.SingleChoiceDialog(None, "Please select:", "Selection", extracted_names)
CANDialog.SetSelection(0)
if CANDialog.ShowModal() == wx.ID_OK:
choosen_can = CANDialog.GetSelection()
else:
return
print(extracted_names[choosen_can])
if __name__ == '__main__':
main()
In python37 this gives the following error:
if CANDialog.ShowModal() == wx.ID_OK:
wx._core.wxAssertionError: C++ assertion ""wxEventLoopBase::GetActive() == m_tempEventLoop"" failed at ..\..\src\generic\progdlgg.cpp(718) in wxGenericProgressDialog::~wxGenericProgressDialog(): current event loop must not be changed during wxGenericProgressDialog lifetime
If I replace the Destroy() with Update() then the dialog is correctly closed automatically:
progress_dlg = wx.ProgressDialog("Model Manager", "Connecting...", maximum=1)
progress_dlg.Pulse()
sleep(5)
progress_dlg.Update(1)
Whilst I can solve my problem, I would like to understand if this is the right way to do it & why Destroy() is not working?
Thanks in advance for any advice.
Gabbo CH