]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/mainloop/mainloop.py
4 This demo attempts to override the C++ MainLoop and implement it
11 #---------------------------------------------------------------------------
13 class MyFrame(wx
.Frame
):
15 def __init__(self
, parent
, id, title
):
16 wx
.Frame
.__init
__(self
, parent
, id, title
,
17 (100, 100), (160, 150))
19 self
.Bind(wx
.EVT_SIZE
, self
.OnSize
)
20 self
.Bind(wx
.EVT_MOVE
, self
.OnMove
)
21 self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
)
22 self
.Bind(wx
.EVT_IDLE
, self
.OnIdle
)
26 panel
= wx
.Panel(self
)
27 sizer
= wx
.FlexGridSizer(cols
=2, hgap
=5, vgap
=5)
29 self
.sizeCtrl
= wx
.TextCtrl(panel
, -1, "", style
=wx
.TE_READONLY
)
30 sizer
.Add(wx
.StaticText(panel
, -1, "Size:"))
31 sizer
.Add(self
.sizeCtrl
)
33 self
.posCtrl
= wx
.TextCtrl(panel
, -1, "", style
=wx
.TE_READONLY
)
34 sizer
.Add(wx
.StaticText(panel
, -1, "Pos:"))
35 sizer
.Add(self
.posCtrl
)
37 self
.idleCtrl
= wx
.TextCtrl(panel
, -1, "", style
=wx
.TE_READONLY
)
38 sizer
.Add(wx
.StaticText(panel
, -1, "Idle:"))
39 sizer
.Add(self
.idleCtrl
)
41 border
= wx
.BoxSizer()
42 border
.Add(sizer
, 0, wx
.ALL
, 20)
43 panel
.SetSizer(border
)
46 def OnCloseWindow(self
, event
):
50 def OnIdle(self
, event
):
51 self
.idleCtrl
.SetValue(str(self
.count
))
52 self
.count
= self
.count
+ 1
54 def OnSize(self
, event
):
55 size
= event
.GetSize()
56 self
.sizeCtrl
.SetValue("%s, %s" % (size
.width
, size
.height
))
59 def OnMove(self
, event
):
60 pos
= event
.GetPosition()
61 self
.posCtrl
.SetValue("%s, %s" % (pos
.x
, pos
.y
))
65 #---------------------------------------------------------------------------
70 # Create an event loop and make it active. If you are
71 # only going to temporarily have a nested event loop then
72 # you should get a reference to the old one and set it as
73 # the active event loop when you are done with this one...
74 evtloop
= wx
.EventLoop()
75 old
= wx
.EventLoop
.GetActive()
76 wx
.EventLoop
.SetActive(evtloop
)
78 # This outer loop determines when to exit the application,
79 # for this example we let the main frame reset this flag
82 # At this point in the outer loop you could do
83 # whatever you implemented your own MainLoop for. It
84 # should be quick and non-blocking, otherwise your GUI
87 # call_your_code_here()
90 # This inner loop will process any GUI events
91 # until there are no more waiting.
92 while evtloop
.Pending():
95 # Send idle events to idle handlers. You may want to
96 # throttle this back a bit somehow so there is not too
97 # much CPU time spent in the idle handlers. For this
98 # example, I'll just snooze a little...
102 wx
.EventLoop
.SetActive(old
)
107 frame
= MyFrame(None, -1, "This is a test")
109 self
.SetTopWindow(frame
)
111 self
.keepGoing
= True