Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, the problem is that the above code runs too fast, so you see the progress bar update so quick that it seems its not getting updated. It does that because you're not searching the directory and displaying the result at the same time. When the class <code>__init__</code> you do the search, and just then when you click the button the list is read and displayed in the progress bar at full speed. I'm pretty sure that if the directory is huge, when you start the script it will take a few seconds for the window to display, and the progress bar will eventually progress in a matter of milliseconds anyway.</p> <p>Basically the problem you're having is that you're doing everything in the same thread. Gtk is in it's own thread, listening to events from the GUI and updating the GUI. Most of the time, you will be using Gtk.ProgressBar for something that will require some time to complete, and you need to execute both, the GUI thread and the working thread (the one that is doing something), and send updates from the working thread to the GUI thread so it updates the progress bar. If, like the code above, you run everything in the same thread you will end up having this kind of problems, for example when the GUI freezes, that is, it become unresponsive because suddenly the GUI thread is doing some work not GUI-related.</p> <p>In PyGTK, you had the method <code>gobject.idle_add(function, parameters)</code> so you can communicate from the working thread to the GUI thread, so when the GUI thread is idle it will execute that function with those parameters, for example, to update the Gtk.ProgressBar. </p> <p>My approach to that problem is implemented here, please note is for PyGTK: <a href="https://github.com/carlos-jenkins/nested/blob/master/src/lib/nested/core/gallery/loading.py" rel="nofollow">https://github.com/carlos-jenkins/nested/blob/master/src/lib/nested/core/gallery/loading.py</a></p> <p>Basically, it is a "LoadingWindow" that the whole application share. When you want to start loading something or perform some heavy work you had to subclass the WorkingThread class (<a href="https://github.com/carlos-jenkins/nested/blob/master/src/lib/nested/core/gallery/gallery.py#L98" rel="nofollow">example</a>). Then, you just had to call the <code>show()</code> method with a WorkingThread subclass instance as parameter and done. In the WorkingThread subclass, you had to implement the <code>payload()</code> function, that is, the function that does the heavy work. You could directly call from the WorkingThread the <code>pulse</code> method in the LoadingWindow to update the ProgressBar and should not care about Thread communication because that logic is implemented there.</p> <p>Hope the explanation helps.</p> <p>EDIT:</p> <p>I just ported the above to PyGObject, you can find the example here: <a href="https://gist.github.com/carlos-jenkins/5358445" rel="nofollow">https://gist.github.com/carlos-jenkins/5358445</a></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.
    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.
 

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