Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Threading with PyGTK is bit tricky if you want to do it right. Basically, you should not update GUI from within any other thread than main thread (common limitation in GUI libs). Usually this is done in PyGTK using mechanism of queued messages (for communication between workers and GUI) which are read periodically using timeout function. Once I had a presentation on my local LUG on this topic, you can grab example code for this presentation from <a href="http://code.google.com/p/leechfm/" rel="noreferrer">Google Code repository</a>. Have a look at <code>MainWindow</code> class in <code>forms/frmmain.py</code>, specially for method <code>_pulse()</code> and what is done in <code>on_entry_activate()</code> (thread is started there plus the idle timer is created).</p> <pre><code>def on_entry_activate(self, entry): text = entry.get_text().strip() if text: store = entry.get_completion().get_model() if text not in [row[0] for row in store]: store.append((text, )) thread = threads.RecommendationsFetcher(text, self.queue)# &lt;- 1 self.idle_timer = gobject.idle_add(self._pulse)# &lt;- 2 tv_results = self.widgets.get_widget('tv_results') model = tv_results.get_model() model.clear() thread.setDaemon(True)# &lt;- 3 progress_update = self.widgets.get_widget('progress_update') progress_update.show() thread.start()# &lt;- 4 </code></pre> <p>This way, application updates GUI when is "idle" (by GTK means) causing no freezes.</p> <ul> <li>1: create thread </li> <li>2: create idle timer</li> <li>3: daemonize thread so the app can be closed without waiting for thread completion</li> <li>4: start thread</li> </ul>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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