]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/demoMainLoop.py
2 This demo attempts to override the C++ MainLoop and implement it
3 in Python. This is not part of the demo framework.
6 THIS FEATURE IS STILL EXPERIMENTAL...
10 from wxPython
.wx
import *
14 #---------------------------------------------------------------------------
16 class MyFrame(wxFrame
):
18 def __init__(self
, parent
, id, title
):
19 wxFrame
.__init
__(self
, parent
, id, title
,
20 wxPoint(100, 100), wxSize(160, 150))
22 EVT_SIZE(self
, self
.OnSize
)
23 EVT_MOVE(self
, self
.OnMove
)
24 EVT_CLOSE(self
, self
.OnCloseWindow
)
25 EVT_IDLE(self
, self
.OnIdle
)
29 panel
= wxPanel(self
, -1)
30 wxStaticText(panel
, -1, "Size:",
31 wxDLG_PNT(panel
, wxPoint(4, 4)), wxDefaultSize
)
32 wxStaticText(panel
, -1, "Pos:",
33 wxDLG_PNT(panel
, wxPoint(4, 16)), wxDefaultSize
)
35 wxStaticText(panel
, -1, "Idle:",
36 wxDLG_PNT(panel
, wxPoint(4, 28)), wxDefaultSize
)
38 self
.sizeCtrl
= wxTextCtrl(panel
, -1, "",
39 wxDLG_PNT(panel
, wxPoint(24, 4)),
40 wxDLG_SZE(panel
, wxSize(36, -1)),
43 self
.posCtrl
= wxTextCtrl(panel
, -1, "",
44 wxDLG_PNT(panel
, wxPoint(24, 16)),
45 wxDLG_SZE(panel
, wxSize(36, -1)),
48 self
.idleCtrl
= wxTextCtrl(panel
, -1, "",
49 wxDLG_PNT(panel
, wxPoint(24, 28)),
50 wxDLG_SZE(panel
, wxSize(36, -1)),
54 def OnCloseWindow(self
, event
):
58 def OnIdle(self
, event
):
59 self
.idleCtrl
.SetValue(str(self
.count
))
60 self
.count
= self
.count
+ 1
62 def OnSize(self
, event
):
63 size
= event
.GetSize()
64 self
.sizeCtrl
.SetValue("%s, %s" % (size
.width
, size
.height
))
67 def OnMove(self
, event
):
68 pos
= event
.GetPosition()
69 self
.posCtrl
.SetValue("%s, %s" % (pos
.x
, pos
.y
))
73 #---------------------------------------------------------------------------
77 # This outer loop determines when to exit the application, for
78 # this example we let the main frame reset this flag when it
81 # At this point in the outer loop you could do whatever you
82 # implemented your own MainLoop for. It should be quick and
83 # non-blocking, otherwise your GUI will freeze. For example,
84 # call Fnorb's reactor.do_one_event(0), etc.
86 # call_your_code_here()
89 # This inner loop will process any GUI events until there
90 # are no more waiting.
94 # Send idle events to idle handlers. You may want to throtle
95 # this back a bit so there is not too much CPU time spent in
96 # the idle handlers. For this example, I'll just snooze a
104 frame
= MyFrame(NULL
, -1, "This is a test")
106 self
.SetTopWindow(frame
)
108 self
.keepGoing
= true