]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/demoMainLoop.py
   2 #--------------------------------------------------------------------------- 
   3 # 11/9/2003 - Jeff Grimmett (grimmtooth@softhome.net 
   6 # o Mainloop is freezing up app. 
  10 This demo attempts to override the C++ MainLoop and implement it 
  11 in Python.  This is not part of the demo framework. 
  14                 THIS FEATURE IS STILL EXPERIMENTAL... 
  20 #--------------------------------------------------------------------------- 
  22 class MyFrame(wx
.Frame
): 
  24     def __init__(self
, parent
, id, title
): 
  25         wx
.Frame
.__init
__(self
, parent
, id, title
, 
  26                          (100, 100), (160, 150)) 
  28         self
.Bind(wx
.EVT_SIZE
, self
.OnSize
) 
  29         self
.Bind(wx
.EVT_MOVE
, self
.OnMove
) 
  30         self
.Bind(wx
.EVT_CLOSE
, self
.OnCloseWindow
) 
  31         self
.Bind(wx
.EVT_IDLE
, self
.OnIdle
) 
  35         panel 
= wx
.Panel(self
, -1) 
  36         wx
.StaticText(panel
, -1, "Size:", 
  37                      wx
.DLG_PNT(panel
, (4, 4)),  wx
.DefaultSize
) 
  38         wx
.StaticText(panel
, -1, "Pos:", 
  39                      wx
.DLG_PNT(panel
, (4, 16)), wx
.DefaultSize
) 
  41         wx
.StaticText(panel
, -1, "Idle:", 
  42                      wx
.DLG_PNT(panel
, (4, 28)), wx
.DefaultSize
) 
  44         self
.sizeCtrl 
= wx
.TextCtrl(panel
, -1, "", 
  45                                    wx
.DLG_PNT(panel
, (24, 4)), 
  46                                    wx
.DLG_SZE(panel
, (36, -1)), 
  49         self
.posCtrl 
= wx
.TextCtrl(panel
, -1, "", 
  50                                   wx
.DLG_PNT(panel
, (24, 16)), 
  51                                   wx
.DLG_SZE(panel
, (36, -1)), 
  54         self
.idleCtrl 
= wx
.TextCtrl(panel
, -1, "", 
  55                                    wx
.DLG_PNT(panel
, (24, 28)), 
  56                                    wx
.DLG_SZE(panel
, (36, -1)), 
  60     def OnCloseWindow(self
, event
): 
  64     def OnIdle(self
, event
): 
  65         self
.idleCtrl
.SetValue(str(self
.count
)) 
  66         self
.count 
= self
.count 
+ 1 
  68     def OnSize(self
, event
): 
  69         size 
= event
.GetSize() 
  70         self
.sizeCtrl
.SetValue("%s, %s" % (size
.width
, size
.height
)) 
  73     def OnMove(self
, event
): 
  74         pos 
= event
.GetPosition() 
  75         self
.posCtrl
.SetValue("%s, %s" % (pos
.x
, pos
.y
)) 
  79 #--------------------------------------------------------------------------- 
  83         # This outer loop determines when to exit the application,  for 
  84         # this example we let the main frame reset this flag when it 
  87             # At this point in the outer loop you could do whatever you 
  88             # implemented your own MainLoop for.  It should be quick and 
  89             # non-blocking, otherwise your GUI will freeze.  For example, 
  90             # call Fnorb's reactor.do_one_event(0), etc. 
  92             # call_your_code_here() 
  95             # This inner loop will process any GUI events until there 
  96             # are no more waiting. 
 100             # Send idle events to idle handlers.  You may want to throttle 
 101             # this back a bit so there is not too much CPU time spent in 
 102             # the idle handlers.  For this example, I'll just snooze a 
 110         frame 
= MyFrame(None, -1, "This is a test") 
 112         self
.SetTopWindow(frame
) 
 114         self
.keepGoing 
= True