]>
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         if "wxMac" in wx
.PlatformInfo
: 
  71             # TODO:  Does wxMac implement wxEventLoop yet??? 
  75             # Create an event loop and make it active.  If you are 
  76             # only going to temporarily have a nested event loop then 
  77             # you should get a reference to the old one and set it as 
  78             # the active event loop when you are done with this one... 
  79             evtloop 
= wx
.EventLoop() 
  80             old 
= wx
.EventLoop
.GetActive() 
  81             wx
.EventLoop
.SetActive(evtloop
) 
  83             # This outer loop determines when to exit the application, 
  84             # for this example we let the main frame reset this flag 
  87                 # At this point in the outer loop you could do 
  88                 # whatever you implemented your own MainLoop for.  It 
  89                 # should be quick and non-blocking, otherwise your GUI 
  92                 # call_your_code_here() 
  95                 # This inner loop will process any GUI events 
  96                 # until there are no more waiting. 
  97                 while evtloop
.Pending(): 
 100                 # Send idle events to idle handlers.  You may want to 
 101                 # throttle this back a bit somehow so there is not too 
 102                 # much CPU time spent in the idle handlers.  For this 
 103                 # example, I'll just snooze a little... 
 107             wx
.EventLoop
.SetActive(old
) 
 112         frame 
= MyFrame(None, -1, "This is a test") 
 114         self
.SetTopWindow(frame
) 
 116         self
.keepGoing 
= True