Why wx.Yield () does not seem to lend itself to Windows

I cut out the guts from a small application to demonstrate this behavior. In osx, this works as I expect: when you click the button, it prints β€œAsked to start work”, then a message box appears, and everything pauses until the OK button is clicked, then the β€œyielding” print starts and the GUI stays moderately alive .

import wx
import time

class MainWindow(wx.Frame):
    def __init__(self, parent, id, title):

        wx.Frame.__init__(self, parent, id, title, size=(800, 700))
        self.tabbed = wx.Notebook(self, -1, style=(wx.NB_TOP))

        self.running = RunningPane(self.tabbed)
        self.submissions = SubmissionPane(self.tabbed, self.running)

        self.tabbed.AddPage(self.submissions, "Submit Job")
        self.tabbed.AddPage(self.running, "Running Jobs")
        self.Show()


class SubmissionPane(wx.Panel):
    def __init__(self, parent, run_pane):
        wx.Panel.__init__(self, parent, -1)

        self.run_pane = run_pane

        self.buttonGo = wx.Button(self, -1, "Submit", pos=(290,170))
        self.buttonGo.Bind(wx.EVT_BUTTON, self.OnSubmit)

        self.Show()

    def OnSubmit(self, event):
        self.run_pane.StartWork()
        print "requested work start"
        wx.MessageBox('Job Submitted')
        print "displayed message box"

class RunningPane(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

        self.running_log = wx.TextCtrl(self, -1, pos=(35, 210), size=(720,400))
        self.Show()


    def StartWork(self):
        print "Asked to Start Work..."
        wx.CallAfter(self.DoTheWork)
        print "registered the CallAfter"

    def DoTheWork(self):
        print "Actually starting work"
        self.running_log.WriteText("doing..."+"\n")
        for i in range(20):
            print "yielding"
            wx.Yield()
            time.sleep(1)
        print "I pretended to do the work :) "


app = wx.App()
MainWindow(None, -1, 'Application')
app.MainLoop()

However, on Windows, the dialog box does not appear until 20 lessons are printed, which begin immediately after the button is pressed, and the GUI does not respond within this time.

I misunderstood what to expect from wx.Yield()?

+3
source share
1 answer

, wxPython . Windows, Linux Mac, . , , . wx.MessageDialog, . , wx.MessageBox :

msg = wx.MessageDialog(self, 'Job Submitted', "Job", wx.OK)
msg.ShowModal()
+3

All Articles