1999-09-01 16:53:22 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#---------------------------------------------------------------------------
|
2003-12-08 20:23:28 -05:00
|
|
|
# 11/9/2003 - Jeff Grimmett (grimmtooth@softhome.net
|
|
|
|
#
|
|
|
|
# o Updated for V2.5
|
|
|
|
# o Mainloop is freezing up app.
|
|
|
|
#
|
|
|
|
|
1999-08-24 16:14:14 -04:00
|
|
|
"""
|
|
|
|
This demo attempts to override the C++ MainLoop and implement it
|
|
|
|
in Python. This is not part of the demo framework.
|
|
|
|
|
|
|
|
|
|
|
|
THIS FEATURE IS STILL EXPERIMENTAL...
|
|
|
|
"""
|
|
|
|
|
|
|
|
import time
|
2003-12-08 20:23:28 -05:00
|
|
|
import wx
|
1999-08-24 16:14:14 -04:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
class MyFrame(wx.Frame):
|
1999-08-24 16:14:14 -04:00
|
|
|
|
|
|
|
def __init__(self, parent, id, title):
|
2003-07-02 19:13:10 -04:00
|
|
|
wx.Frame.__init__(self, parent, id, title,
|
2003-12-08 20:23:28 -05:00
|
|
|
(100, 100), (160, 150))
|
1999-08-24 16:14:14 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
self.Bind(wx.EVT_SIZE, self.OnSize)
|
|
|
|
self.Bind(wx.EVT_MOVE, self.OnMove)
|
|
|
|
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
|
|
|
self.Bind(wx.EVT_IDLE, self.OnIdle)
|
1999-08-24 16:14:14 -04:00
|
|
|
|
|
|
|
self.count = 0
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
panel = wx.Panel(self, -1)
|
|
|
|
wx.StaticText(panel, -1, "Size:",
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.DLG_PNT(panel, (4, 4)), wx.DefaultSize)
|
2003-07-02 19:13:10 -04:00
|
|
|
wx.StaticText(panel, -1, "Pos:",
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.DLG_PNT(panel, (4, 16)), wx.DefaultSize)
|
1999-08-24 16:14:14 -04:00
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
wx.StaticText(panel, -1, "Idle:",
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.DLG_PNT(panel, (4, 28)), wx.DefaultSize)
|
1999-08-24 16:14:14 -04:00
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
self.sizeCtrl = wx.TextCtrl(panel, -1, "",
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.DLG_PNT(panel, (24, 4)),
|
|
|
|
wx.DLG_SZE(panel, (36, -1)),
|
2003-07-02 19:13:10 -04:00
|
|
|
wx.TE_READONLY)
|
1999-08-24 16:14:14 -04:00
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
self.posCtrl = wx.TextCtrl(panel, -1, "",
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.DLG_PNT(panel, (24, 16)),
|
|
|
|
wx.DLG_SZE(panel, (36, -1)),
|
2003-07-02 19:13:10 -04:00
|
|
|
wx.TE_READONLY)
|
1999-08-24 16:14:14 -04:00
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
self.idleCtrl = wx.TextCtrl(panel, -1, "",
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.DLG_PNT(panel, (24, 28)),
|
|
|
|
wx.DLG_SZE(panel, (36, -1)),
|
2003-07-02 19:13:10 -04:00
|
|
|
wx.TE_READONLY)
|
1999-08-24 16:14:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
def OnCloseWindow(self, event):
|
2003-03-25 01:35:27 -05:00
|
|
|
app.keepGoing = False
|
1999-08-24 16:14:14 -04:00
|
|
|
self.Destroy()
|
|
|
|
|
|
|
|
def OnIdle(self, event):
|
|
|
|
self.idleCtrl.SetValue(str(self.count))
|
|
|
|
self.count = self.count + 1
|
|
|
|
|
|
|
|
def OnSize(self, event):
|
|
|
|
size = event.GetSize()
|
|
|
|
self.sizeCtrl.SetValue("%s, %s" % (size.width, size.height))
|
|
|
|
event.Skip()
|
|
|
|
|
|
|
|
def OnMove(self, event):
|
|
|
|
pos = event.GetPosition()
|
|
|
|
self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
class MyApp(wx.App):
|
1999-08-24 16:14:14 -04:00
|
|
|
def MainLoop(self):
|
|
|
|
# This outer loop determines when to exit the application, for
|
|
|
|
# this example we let the main frame reset this flag when it
|
|
|
|
# closes.
|
|
|
|
while self.keepGoing:
|
|
|
|
# At this point in the outer loop you could do whatever you
|
|
|
|
# implemented your own MainLoop for. It should be quick and
|
|
|
|
# non-blocking, otherwise your GUI will freeze. For example,
|
|
|
|
# call Fnorb's reactor.do_one_event(0), etc.
|
|
|
|
|
|
|
|
# call_your_code_here()
|
|
|
|
|
|
|
|
|
|
|
|
# This inner loop will process any GUI events until there
|
|
|
|
# are no more waiting.
|
2002-08-27 21:39:00 -04:00
|
|
|
while self.Pending():
|
1999-08-24 16:14:14 -04:00
|
|
|
self.Dispatch()
|
|
|
|
|
2003-10-01 20:58:06 -04:00
|
|
|
# Send idle events to idle handlers. You may want to throttle
|
1999-08-24 16:14:14 -04:00
|
|
|
# this back a bit so there is not too much CPU time spent in
|
|
|
|
# the idle handlers. For this example, I'll just snooze a
|
|
|
|
# little...
|
|
|
|
time.sleep(0.25)
|
|
|
|
self.ProcessIdle()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def OnInit(self):
|
2001-05-18 17:59:59 -04:00
|
|
|
frame = MyFrame(None, -1, "This is a test")
|
2003-03-25 01:35:27 -05:00
|
|
|
frame.Show(True)
|
1999-08-24 16:14:14 -04:00
|
|
|
self.SetTopWindow(frame)
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
self.keepGoing = True
|
1999-08-24 16:14:14 -04:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
return True
|
1999-08-24 16:14:14 -04:00
|
|
|
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
app = MyApp(False)
|
1999-08-24 16:14:14 -04:00
|
|
|
app.MainLoop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|