return value from wx.CallAfter

So, how about getting the return value from wx.CallAfter?

  newitem= tree.AppendItem( item, ct_type= 1, data= fardmprt )

is the line I want to run in a non-GUI thread.

Hi,
     I encountered the same problem with you. My solution may be not
very beautiful, but it works. :slight_smile: The key is to put the function
calling and result fetching together.

class MyThread(...):
     def __init__(...):
           self.event_append_finish = threading.Event()
     def doAppend(...):
           self.append_result = tree.AppendItem(...)
           self.event_append_finish.set()
     def some_func(...):
           wx.CallAfter(self.doAppend, ....)
           self.event_append_finish.wait()
           # read self.append_result...

···

---
ShenLei

Generalize. I don't want to duplicate work.

  def doAppend(...): ...
  def doCopy(...): ...
  def doGetValue(...): ...
  def doSetValue(...): ...

···

-----Original Message-----
From: 甜瓜 [mailto:littlesweetmelon@gmail.com]
Sent: Sunday, January 13, 2008 10:37 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] return value from wx.CallAfter

Hi,
     I encountered the same problem with you. My solution may be not
very beautiful, but it works. :slight_smile: The key is to put the function
calling and result fetching together.

class MyThread(...):
     def __init__(...):
           self.event_append_finish = threading.Event()
     def doAppend(...):
           self.append_result = tree.AppendItem(...)
           self.event_append_finish.set()
     def some_func(...):
           wx.CallAfter(self.doAppend, ....)
           self.event_append_finish.wait()
           # read self.append_result...

I don't mean to duplicate each interface. You can put all calucations
needed after a wx.CallAfter into a single function.
Eg:
doAppend() will have a more meaningful name and do some real works.

def doAppendJobQueue(...):
      self.append_result = tree.AppendItem(...)
      # do some logging
      # sort tree, etc...
      self.event_append_job_queue_finish.set()

···

---
ShenLei

Aaron Brady wrote:

So, how about getting the return value from wx.CallAfter?

  newitem= tree.AppendItem( item, ct_type= 1, data= fardmprt )

is the line I want to run in a non-GUI thread.

There was a class similar to wx.CallAfter proposed in this thread: http://thread.gmane.org/gmane.comp.python.wxpython/54892/focus=54894 that allows the return value of the function to be captured, and then the calling thread waits until the result is available before returning.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!