chiark / gitweb /
Do not show a dialog inside a Modal dialog
authorYouness Alaoui <kakaroto@kakaroto.homelinux.net>
Mon, 26 Oct 2015 19:32:08 +0000 (15:32 -0400)
committerYouness Alaoui <kakaroto@kakaroto.homelinux.net>
Mon, 26 Oct 2015 19:32:08 +0000 (15:32 -0400)
This fixes T253. Showing a dialog (message box) while the main thread
is locked in a ShowModal will cause X errors and a python crash.
So we must delay the dialog until the modal dialog is done.

Cura/gui/firmwareInstall.py

index 60953dad07fff189e937fa959bf4d19f88716cc7..b91bfd4c861d680e16fde05e2ebcef12652d323a 100644 (file)
@@ -116,6 +116,7 @@ class InstallFirmwareDialog(wx.Dialog):
                self.Layout()
                self.Fit()
                self.success = False
+               self.show_connect_error_dialog = False
 
        def Run(self):
                if self.filename is None:
@@ -127,6 +128,11 @@ class InstallFirmwareDialog(wx.Dialog):
                self.thread.start()
 
                self.ShowModal()
+               # Creating a MessageBox in a separate thread while main thread is locked inside a ShowModal
+               # will cause Python to crash with X errors. So we need to show the dialog here instead
+               if self.show_connect_dialog:
+                       wx.MessageBox(_("Failed to find machine for firmware upgrade\nIs your machine connected to the PC?"),
+                                                 _("Firmware update"), wx.OK | wx.ICON_ERROR)
                return self.success
 
        def OnRun(self):
@@ -153,10 +159,12 @@ class InstallFirmwareDialog(wx.Dialog):
                                programmer.connect(self.port)
                        except ispBase.IspError:
                                programmer.close()
+                       if not self:
+                               #Window destroyed
+                               return
 
                if not programmer.isConnected():
-                       wx.MessageBox(_("Failed to find machine for firmware upgrade\nIs your machine connected to the PC?"),
-                                                 _("Firmware update"), wx.OK | wx.ICON_ERROR)
+                       self.show_connect_dialog = True
                        wx.CallAfter(self.Close)
                        return