]> git.saurik.com Git - wxWidgets.git/commitdiff
Added limited support for wxEventLoop (you can't derive from a
authorRobin Dunn <robin@alldunn.com>
Thu, 23 Sep 2004 01:02:00 +0000 (01:02 +0000)
committerRobin Dunn <robin@alldunn.com>
Thu, 23 Sep 2004 01:02:00 +0000 (01:02 +0000)
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

wxPython/demo/demoMainLoop.py [deleted file]
wxPython/distrib/DIRLIST
wxPython/docs/CHANGES.txt
wxPython/samples/mainloop/mainloop.py [new file with mode: 0755]
wxPython/src/_evtloop.i [new file with mode: 0644]
wxPython/src/core.i

diff --git a/wxPython/demo/demoMainLoop.py b/wxPython/demo/demoMainLoop.py
deleted file mode 100755 (executable)
index 53aefda..0000000
+++ /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()
-
-
-
-
-
index 2534493c7b637588e8cc5ff79160d59114cbd938..3403ae3fe9b88123fc6a501bc536033c9fb3927b 100644 (file)
@@ -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
index 0e213b84b06c8dd3b7090b3c0a7a3eacd02eb26f..7a469f79715abc8979e9986f1c37094c6bebe045 100644 (file)
@@ -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 (executable)
index 0000000..1074b83
--- /dev/null
@@ -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 (file)
index 0000000..168666e
--- /dev/null
@@ -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);
+};
+
+
+//---------------------------------------------------------------------------
index 93df66902a7bce875a881473fef72d95fddbcaa1..8014c345ba718b438069a926126a34c9b90e1c7c 100644 (file)
@@ -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