]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/demoMainLoop.py
2 #---------------------------------------------------------------------------
4 This demo attempts to override the C++ MainLoop and implement it
5 in Python. This is not part of the demo framework.
8 THIS FEATURE IS STILL EXPERIMENTAL...
12 import wx
# This module uses the new wx namespace
16 #---------------------------------------------------------------------------
18 class MyFrame(wx
.Frame
):
20 def __init__(self
, parent
, id, title
):
21 wx
.Frame
.__init
__(self
, parent
, id, title
,
22 wx
.Point(100, 100), wx
.Size(160, 150))
24 wx
.EVT_SIZE(self
, self
.OnSize
)
25 wx
.EVT_MOVE(self
, self
.OnMove
)
26 wx
.EVT_CLOSE(self
, self
.OnCloseWindow
)
27 wx
.EVT_IDLE(self
, self
.OnIdle
)
31 panel
= wx
.Panel(self
, -1)
32 wx
.StaticText(panel
, -1, "Size:",
33 wx
.DLG_PNT(panel
, wx
.Point(4, 4)), wx
.DefaultSize
)
34 wx
.StaticText(panel
, -1, "Pos:",
35 wx
.DLG_PNT(panel
, wx
.Point(4, 16)), wx
.DefaultSize
)
37 wx
.StaticText(panel
, -1, "Idle:",
38 wx
.DLG_PNT(panel
, wx
.Point(4, 28)), wx
.DefaultSize
)
40 self
.sizeCtrl
= wx
.TextCtrl(panel
, -1, "",
41 wx
.DLG_PNT(panel
, wx
.Point(24, 4)),
42 wx
.DLG_SZE(panel
, wx
.Size(36, -1)),
45 self
.posCtrl
= wx
.TextCtrl(panel
, -1, "",
46 wx
.DLG_PNT(panel
, wx
.Point(24, 16)),
47 wx
.DLG_SZE(panel
, wx
.Size(36, -1)),
50 self
.idleCtrl
= wx
.TextCtrl(panel
, -1, "",
51 wx
.DLG_PNT(panel
, wx
.Point(24, 28)),
52 wx
.DLG_SZE(panel
, wx
.Size(36, -1)),
56 def OnCloseWindow(self
, event
):
60 def OnIdle(self
, event
):
61 self
.idleCtrl
.SetValue(str(self
.count
))
62 self
.count
= self
.count
+ 1
64 def OnSize(self
, event
):
65 size
= event
.GetSize()
66 self
.sizeCtrl
.SetValue("%s, %s" % (size
.width
, size
.height
))
69 def OnMove(self
, event
):
70 pos
= event
.GetPosition()
71 self
.posCtrl
.SetValue("%s, %s" % (pos
.x
, pos
.y
))
75 #---------------------------------------------------------------------------
79 # This outer loop determines when to exit the application, for
80 # this example we let the main frame reset this flag when it
83 # At this point in the outer loop you could do whatever you
84 # implemented your own MainLoop for. It should be quick and
85 # non-blocking, otherwise your GUI will freeze. For example,
86 # call Fnorb's reactor.do_one_event(0), etc.
88 # call_your_code_here()
91 # This inner loop will process any GUI events until there
92 # are no more waiting.
96 # Send idle events to idle handlers. You may want to throttle
97 # this back a bit so there is not too much CPU time spent in
98 # the idle handlers. For this example, I'll just snooze a
106 frame
= MyFrame(None, -1, "This is a test")
108 self
.SetTopWindow(frame
)
110 self
.keepGoing
= True