mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-05 19:40:12 +01:00
Add a button to the mainloop sample to test wx.PostEvent
This commit is contained in:
@@ -7,21 +7,26 @@ in Python.
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
import wx
|
import wx
|
||||||
|
import wx.lib.newevent as ne
|
||||||
|
|
||||||
|
|
||||||
##import os; raw_input('PID: %d\nPress enter...' % os.getpid())
|
##import os; raw_input('PID: %d\nPress enter...' % os.getpid())
|
||||||
|
|
||||||
|
GooEvent, EVT_GOO = ne.NewCommandEvent()
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
|
||||||
class MyFrame(wx.Frame):
|
class MyFrame(wx.Frame):
|
||||||
|
|
||||||
def __init__(self, parent, id, title):
|
def __init__(self, parent, id, title):
|
||||||
wx.Frame.__init__(self, parent, id, title,
|
wx.Frame.__init__(self, parent, id, title, size=(300, 200))
|
||||||
(100, 100), (160, 150))
|
|
||||||
|
|
||||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||||
self.Bind(wx.EVT_MOVE, self.OnMove)
|
self.Bind(wx.EVT_MOVE, self.OnMove)
|
||||||
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
||||||
self.Bind(wx.EVT_IDLE, self.OnIdle)
|
self.Bind(wx.EVT_IDLE, self.OnIdle)
|
||||||
|
self.Bind(wx.EVT_BUTTON, self.OnButton)
|
||||||
|
self.Bind(EVT_GOO, self.OnGoo, id=123)
|
||||||
|
|
||||||
self.count = 0
|
self.count = 0
|
||||||
|
|
||||||
@@ -40,6 +45,10 @@ class MyFrame(wx.Frame):
|
|||||||
sizer.Add(wx.StaticText(panel, -1, "Idle:"))
|
sizer.Add(wx.StaticText(panel, -1, "Idle:"))
|
||||||
sizer.Add(self.idleCtrl)
|
sizer.Add(self.idleCtrl)
|
||||||
|
|
||||||
|
btn = wx.Button(panel, label='PostEvent')
|
||||||
|
sizer.Add(1,1)
|
||||||
|
sizer.Add(btn)
|
||||||
|
|
||||||
border = wx.BoxSizer()
|
border = wx.BoxSizer()
|
||||||
border.Add(sizer, 0, wx.ALL, 20)
|
border.Add(sizer, 0, wx.ALL, 20)
|
||||||
panel.SetSizer(border)
|
panel.SetSizer(border)
|
||||||
@@ -61,6 +70,12 @@ class MyFrame(wx.Frame):
|
|||||||
pos = event.GetPosition()
|
pos = event.GetPosition()
|
||||||
self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
|
self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
|
||||||
|
|
||||||
|
def OnButton(self, evt):
|
||||||
|
evt = GooEvent(id=123)
|
||||||
|
wx.PostEvent(self, evt)
|
||||||
|
|
||||||
|
def OnGoo(self, evt):
|
||||||
|
print('got EVT_GOO')
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
@@ -76,7 +91,7 @@ class MyEventLoop(wx.GUIEventLoop):
|
|||||||
# Do whatever you want to have done for each iteration of the event
|
# Do whatever you want to have done for each iteration of the event
|
||||||
# loop. In this example we'll just sleep a bit to simulate something
|
# loop. In this example we'll just sleep a bit to simulate something
|
||||||
# real happening.
|
# real happening.
|
||||||
time.sleep(0.10)
|
time.sleep(0.05)
|
||||||
|
|
||||||
|
|
||||||
def Run(self):
|
def Run(self):
|
||||||
@@ -95,10 +110,8 @@ class MyEventLoop(wx.GUIEventLoop):
|
|||||||
if self.shouldExit:
|
if self.shouldExit:
|
||||||
break
|
break
|
||||||
|
|
||||||
# dispatch all the pending events and call Dispatch() to wait
|
# Dispatch all the pending events
|
||||||
# for the next message
|
self.ProcessEvents()
|
||||||
if not self.ProcessEvents():
|
|
||||||
break
|
|
||||||
|
|
||||||
# Currently on wxOSX Pending always returns true, so the
|
# Currently on wxOSX Pending always returns true, so the
|
||||||
# ProcessIdle above is not ever called. Call it here instead.
|
# ProcessIdle above is not ever called. Call it here instead.
|
||||||
|
|||||||
Reference in New Issue
Block a user