]>
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 from wxPython
.wx
import *
16 #---------------------------------------------------------------------------
18 class MyFrame(wxFrame
):
20 def __init__(self
, parent
, id, title
):
21 wxFrame
.__init
__(self
, parent
, id, title
,
22 wxPoint(100, 100), wxSize(160, 150))
24 EVT_SIZE(self
, self
.OnSize
)
25 EVT_MOVE(self
, self
.OnMove
)
26 EVT_CLOSE(self
, self
.OnCloseWindow
)
27 EVT_IDLE(self
, self
.OnIdle
)
31 panel
= wxPanel(self
, -1)
32 wxStaticText(panel
, -1, "Size:",
33 wxDLG_PNT(panel
, wxPoint(4, 4)), wxDefaultSize
)
34 wxStaticText(panel
, -1, "Pos:",
35 wxDLG_PNT(panel
, wxPoint(4, 16)), wxDefaultSize
)
37 wxStaticText(panel
, -1, "Idle:",
38 wxDLG_PNT(panel
, wxPoint(4, 28)), wxDefaultSize
)
40 self
.sizeCtrl
= wxTextCtrl(panel
, -1, "",
41 wxDLG_PNT(panel
, wxPoint(24, 4)),
42 wxDLG_SZE(panel
, wxSize(36, -1)),
45 self
.posCtrl
= wxTextCtrl(panel
, -1, "",
46 wxDLG_PNT(panel
, wxPoint(24, 16)),
47 wxDLG_SZE(panel
, wxSize(36, -1)),
50 self
.idleCtrl
= wxTextCtrl(panel
, -1, "",
51 wxDLG_PNT(panel
, wxPoint(24, 28)),
52 wxDLG_SZE(panel
, wxSize(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 throtle
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(NULL
, -1, "This is a test")
108 self
.SetTopWindow(frame
)
110 self
.keepGoing
= true