Note that there are some explanatory texts on larger screens.

plurals
  1. POwxPython: Threading GUI --> Using Custom Event Handler
    primarykey
    data
    text
    <p>I am trying to learn how to run a thread off the main GUI app to do my serial port sending/receiving while keeping my GUI alive. My best Googling attempts have landed me at the wxpython wiki on: <a href="http://wiki.wxpython.org/LongRunningTasks" rel="nofollow noreferrer">http://wiki.wxpython.org/LongRunningTasks</a> which provides several examples. I have settled on learning the first example, involving starting a worker thread when the particular button is selected.</p> <p>I am having trouble understanding the custom-event-definition:</p> <pre><code>def EVT_RESULT(win, func): """Define Result Event.""" win.Connect(-1, -1, EVT_RESULT_ID, func) class ResultEvent(wx.PyEvent): """Simple event to carry arbitrary result data.""" def __init__(self, data): """Init Result Event.""" wx.PyEvent.__init__(self) self.SetEventType(EVT_RESULT_ID) self.data = data </code></pre> <p>Primarily the </p> <pre><code>def EVT_RESULT(win, func): """Define Result Event.""" win.Connect(-1, -1, EVT_RESULT_ID, func) </code></pre> <p>I think EVT_RESULT is placed outside the classes so as to make it call-able by both classes (making it global?)</p> <p>And.. the main GUI app monitors the thread's progress via:</p> <pre><code># Set up event handler for any worker thread results EVT_RESULT(self,self.OnResult) </code></pre> <p>I also notice that in a lot of examples, when the writer uses </p> <pre><code>from wx import * </code></pre> <p>they simply bind things by</p> <pre><code>EVT_SOME_NEW_EVENT(self, self.handler) </code></pre> <p>as opposed to </p> <pre><code>wx.Bind(EVT_SOME_NEW_EVENT, self.handler) </code></pre> <p>Which doesn't help me understand it any faster. Thanks,</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload