Could someone please give me a quick and dirty overview of the use of
wxCallAfter?
-Rick King
Southfield MI USA
Could someone please give me a quick and dirty overview of the use of
wxCallAfter?
-Rick King
Southfield MI USA
Rick King wrote:
Could someone please give me a quick and dirty overview of the use of
wxCallAfter?
This quick and dirty enough?
def wxCallAfter(callable, *args, **kw):
"""
Call the specified function after the current and pending event
handlers have been completed. This is also good for making GUI
method calls from non-GUI threads.
"""
app = wxGetApp()
assert app, 'No wxApp created yet'
global _wxCallAfterId
if _wxCallAfterId is None:
_wxCallAfterId = wxNewEventType()
app.Connect(-1, -1, _wxCallAfterId,
lambda event: event.callable(*event.args, **event.kw) )
evt = wxPyEvent()
evt.SetEventType(_wxCallAfterId)
evt.callable = callable
evt.args = args
evt.kw = kw
wxPostEvent(app, evt)
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
I still don't always keep in mind that I have access to the source...
This quick and dirty enough?
Robin already pointed you to the source. Here's a few notes that come to
mind as I look through my app:
* wxCallAfter() will make the call in later event, outside the current
one.
* wxCallAfter() is safe to invoke from any thread.
* The actual call will always take place in the main GUI thread.
* That makes wxCallAfter() a good tool for getting "background worker
threads" to update the GUI.
* In some cases, when I can't get a complex GUI operation to succeed, I
use wxCallAfter() to delay some of the work. For example, in a
subclass of wxGrid, as part of redimensioning the table I do this:
def redimension(self):
...
# lots of ugly code
...
wxCallAfter(self.postRedimensionTables)
def postRedimensionTables(self):
self.adjustScrollbars()
self.makeCellVisible(self.gridCursorRow, self.gridCursorCol)
Nothing else worked but that.
* One more example. Inside a draw() method, I had a condition that
determined that another UI element outside the current window should
be updated. Doing that in the middle of drawing a different window
seemed like a bad idea, so I used:
def onPaint(self, e):
...
if someCondition:
wxCallAfter(statusBar.setStatusText,
self.computeStatusText())
...
HTH,
On Wednesday 23 April 2003 05:05 am, Rick King wrote:
Could someone please give me a quick and dirty overview of the use of
wxCallAfter?
--
Chuck
http://ChuckEsterbrook.com