Added limited support for wxEventLoop (you can't derive from a
wx.PyEventLoop version yet...) Updated and moved the sample showing how to replace the MainLoop to samples/mainloop/mainloop.py. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29268 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
9213ca5d47
commit
96d49f0eea
@ -1,125 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#---------------------------------------------------------------------------
|
||||
# 11/9/2003 - Jeff Grimmett (grimmtooth@softhome.net
|
||||
#
|
||||
# o Updated for V2.5
|
||||
# o Mainloop is freezing up app.
|
||||
#
|
||||
|
||||
"""
|
||||
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
|
||||
import wx
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyFrame(wx.Frame):
|
||||
|
||||
def __init__(self, parent, id, title):
|
||||
wx.Frame.__init__(self, parent, id, title,
|
||||
(100, 100), (160, 150))
|
||||
|
||||
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)
|
||||
|
||||
self.count = 0
|
||||
|
||||
panel = wx.Panel(self, -1)
|
||||
wx.StaticText(panel, -1, "Size:",
|
||||
wx.DLG_PNT(panel, (4, 4)), wx.DefaultSize)
|
||||
wx.StaticText(panel, -1, "Pos:",
|
||||
wx.DLG_PNT(panel, (4, 16)), wx.DefaultSize)
|
||||
|
||||
wx.StaticText(panel, -1, "Idle:",
|
||||
wx.DLG_PNT(panel, (4, 28)), wx.DefaultSize)
|
||||
|
||||
self.sizeCtrl = wx.TextCtrl(panel, -1, "",
|
||||
wx.DLG_PNT(panel, (24, 4)),
|
||||
wx.DLG_SZE(panel, (36, -1)),
|
||||
wx.TE_READONLY)
|
||||
|
||||
self.posCtrl = wx.TextCtrl(panel, -1, "",
|
||||
wx.DLG_PNT(panel, (24, 16)),
|
||||
wx.DLG_SZE(panel, (36, -1)),
|
||||
wx.TE_READONLY)
|
||||
|
||||
self.idleCtrl = wx.TextCtrl(panel, -1, "",
|
||||
wx.DLG_PNT(panel, (24, 28)),
|
||||
wx.DLG_SZE(panel, (36, -1)),
|
||||
wx.TE_READONLY)
|
||||
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
app.keepGoing = False
|
||||
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))
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyApp(wx.App):
|
||||
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.
|
||||
while self.Pending():
|
||||
self.Dispatch()
|
||||
|
||||
# Send idle events to idle handlers. You may want to throttle
|
||||
# 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):
|
||||
frame = MyFrame(None, -1, "This is a test")
|
||||
frame.Show(True)
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
self.keepGoing = True
|
||||
|
||||
return True
|
||||
|
||||
|
||||
app = MyApp(False)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -64,6 +64,7 @@ wxPython/samples/doodle
|
||||
wxPython/samples/embedded
|
||||
wxPython/samples/frogedit
|
||||
wxPython/samples/hangman
|
||||
wxPython/samples/mainloop
|
||||
wxPython/samples/pySketch
|
||||
wxPython/samples/pySketch/images
|
||||
wxPython/samples/simple
|
||||
|
@ -84,6 +84,33 @@ wx.Sizer.Show (and Hide) now take an optional parameter specifying if
|
||||
the item to be shown should be searched for recursivly in subsizers,
|
||||
and return a boolean value indicating if the item was found.
|
||||
|
||||
wxMSW: fixed MaximizeEvent generation in wx.Frame
|
||||
|
||||
wxMSW: fixed sending duplicate EVT_COMBOBOX events
|
||||
|
||||
Smoother time estimation updates in wx.ProgressDialog (patch 992813)
|
||||
|
||||
Made wx.Listbook events more consistent with wx.Notebook ones (patch
|
||||
1001271)
|
||||
|
||||
Fixed rounding errors in variable status bar panes widths computation
|
||||
(patch 1030021)
|
||||
|
||||
Added possibility to specify printer bin (patch 910272)
|
||||
|
||||
wxMSW: fixed wx.ListCtrl's SetWindowStyleFlag() to not remove
|
||||
WS_VISIBLE; also refresh the control automatically (closes bug
|
||||
1019440)
|
||||
|
||||
Added wx.Choicebook, yet another notebook-like control.
|
||||
|
||||
wxMSW: Make radiobutton tab behaviour the same on MSW as in standard
|
||||
MSW app, i.e. tab into the activated, not necessarily the first radio
|
||||
button.
|
||||
|
||||
Added limited support for wxEventLoop (you can't derive from a
|
||||
wx.PyEventLoop version yet...) Updated and moved the sample showing
|
||||
how to replace the MainLoop to samples/mainloop/mainloop.py.
|
||||
|
||||
|
||||
|
||||
@ -1746,6 +1773,7 @@ in wx.cpp.
|
||||
|
||||
|
||||
|
||||
|
||||
What's new in 2.1b1
|
||||
--------------------
|
||||
Fixed wxComboBox.SetSelection so that it actually sets the selected
|
||||
|
126
wxPython/samples/mainloop/mainloop.py
Executable file
126
wxPython/samples/mainloop/mainloop.py
Executable file
@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This demo attempts to override the C++ MainLoop and implement it
|
||||
in Python.
|
||||
"""
|
||||
|
||||
import time
|
||||
import wx
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyFrame(wx.Frame):
|
||||
|
||||
def __init__(self, parent, id, title):
|
||||
wx.Frame.__init__(self, parent, id, title,
|
||||
(100, 100), (160, 150))
|
||||
|
||||
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)
|
||||
|
||||
self.count = 0
|
||||
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
|
||||
|
||||
self.sizeCtrl = wx.TextCtrl(panel, -1, "", style=wx.TE_READONLY)
|
||||
sizer.Add(wx.StaticText(panel, -1, "Size:"))
|
||||
sizer.Add(self.sizeCtrl)
|
||||
|
||||
self.posCtrl = wx.TextCtrl(panel, -1, "", style=wx.TE_READONLY)
|
||||
sizer.Add(wx.StaticText(panel, -1, "Pos:"))
|
||||
sizer.Add(self.posCtrl)
|
||||
|
||||
self.idleCtrl = wx.TextCtrl(panel, -1, "", style=wx.TE_READONLY)
|
||||
sizer.Add(wx.StaticText(panel, -1, "Idle:"))
|
||||
sizer.Add(self.idleCtrl)
|
||||
|
||||
border = wx.BoxSizer()
|
||||
border.Add(sizer, 0, wx.ALL, 20)
|
||||
panel.SetSizer(border)
|
||||
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
app.keepGoing = False
|
||||
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))
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class MyApp(wx.App):
|
||||
def MainLoop(self):
|
||||
|
||||
if "wxMac" in wx.PlatformInfo:
|
||||
# TODO: Does wxMac implement wxEventLoop yet???
|
||||
wx.App.MainLoop()
|
||||
|
||||
else:
|
||||
# Create an event loop and make it active. If you are
|
||||
# only going to temporarily have a nested event loop then
|
||||
# you should get a reference to the old one and set it as
|
||||
# the active event loop when you are done with this one...
|
||||
evtloop = wx.EventLoop()
|
||||
old = wx.EventLoop.GetActive()
|
||||
wx.EventLoop.SetActive(evtloop)
|
||||
|
||||
# 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.
|
||||
|
||||
# call_your_code_here()
|
||||
|
||||
|
||||
# This inner loop will process any GUI events
|
||||
# until there are no more waiting.
|
||||
while evtloop.Pending():
|
||||
evtloop.Dispatch()
|
||||
|
||||
# Send idle events to idle handlers. You may want to
|
||||
# throttle this back a bit somehow 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.10)
|
||||
self.ProcessIdle()
|
||||
|
||||
wx.EventLoop.SetActive(old)
|
||||
|
||||
|
||||
|
||||
def OnInit(self):
|
||||
frame = MyFrame(None, -1, "This is a test")
|
||||
frame.Show(True)
|
||||
self.SetTopWindow(frame)
|
||||
|
||||
self.keepGoing = True
|
||||
return True
|
||||
|
||||
|
||||
app = MyApp(False)
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
55
wxPython/src/_evtloop.i
Normal file
55
wxPython/src/_evtloop.i
Normal file
@ -0,0 +1,55 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: _evtloop.i
|
||||
// Purpose: SWIG interface for wxEventLoop
|
||||
//
|
||||
// Author: Robin Dunn
|
||||
//
|
||||
// Created: 18-Sept-2004
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2004 by Total Control Software
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Not a %module
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// TODO: wxPyEventLoop that virtualizes all the methods...
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
%newgroup
|
||||
|
||||
%{
|
||||
#include <wx/evtloop.h>
|
||||
%}
|
||||
|
||||
class wxEventLoop
|
||||
{
|
||||
public:
|
||||
wxEventLoop();
|
||||
virtual ~wxEventLoop();
|
||||
|
||||
// start the event loop, return the exit code when it is finished
|
||||
virtual int Run();
|
||||
|
||||
// exit from the loop with the given exit code
|
||||
virtual void Exit(int rc = 0);
|
||||
|
||||
// return true if any events are available
|
||||
virtual bool Pending() const;
|
||||
|
||||
// dispatch a single event, return false if we should exit from the loop
|
||||
virtual bool Dispatch();
|
||||
|
||||
// is the event loop running now?
|
||||
virtual bool IsRunning() const;
|
||||
|
||||
// return currently active (running) event loop, may be NULL
|
||||
static wxEventLoop *GetActive();
|
||||
|
||||
// set currently active (running) event loop
|
||||
static void SetActive(wxEventLoop* loop);
|
||||
};
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
@ -86,6 +86,7 @@ MAKE_CONST_WXSTRING(EmptyString);
|
||||
%include _evthandler.i
|
||||
%include _event.i
|
||||
%include _app.i
|
||||
%include _evtloop.i
|
||||
%include _accel.i
|
||||
%include _window.i
|
||||
%include _validator.i
|
||||
|
Loading…
Reference in New Issue
Block a user