From: Robin Dunn Date: Thu, 23 Sep 2004 01:02:00 +0000 (+0000) Subject: Added limited support for wxEventLoop (you can't derive from a X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/96d49f0eea53dbaae6fd926d6a2107f9f6e87e7d 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 --- diff --git a/wxPython/demo/demoMainLoop.py b/wxPython/demo/demoMainLoop.py deleted file mode 100755 index 53aefda9be..0000000000 --- a/wxPython/demo/demoMainLoop.py +++ /dev/null @@ -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() - - - - - diff --git a/wxPython/distrib/DIRLIST b/wxPython/distrib/DIRLIST index 2534493c7b..3403ae3fe9 100644 --- a/wxPython/distrib/DIRLIST +++ b/wxPython/distrib/DIRLIST @@ -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 diff --git a/wxPython/docs/CHANGES.txt b/wxPython/docs/CHANGES.txt index 0e213b84b0..7a469f7971 100644 --- a/wxPython/docs/CHANGES.txt +++ b/wxPython/docs/CHANGES.txt @@ -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 diff --git a/wxPython/samples/mainloop/mainloop.py b/wxPython/samples/mainloop/mainloop.py new file mode 100755 index 0000000000..1074b83b3d --- /dev/null +++ b/wxPython/samples/mainloop/mainloop.py @@ -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() + + + + + diff --git a/wxPython/src/_evtloop.i b/wxPython/src/_evtloop.i new file mode 100644 index 0000000000..168666ecb1 --- /dev/null +++ b/wxPython/src/_evtloop.i @@ -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 +%} + +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); +}; + + +//--------------------------------------------------------------------------- diff --git a/wxPython/src/core.i b/wxPython/src/core.i index 93df66902a..8014c345ba 100644 --- a/wxPython/src/core.i +++ b/wxPython/src/core.i @@ -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