python - Using Gtk.spinner with a long time function -


i trying working gtk.spinner using pygobject in python. main thing use element show user long time action in progress. problem spinner stops when doing function.

the code here:

..... def create_image(self,spinner):     ....     spinner.start()     # heavy function     spinner.stop() ..... 

and doesn't works. accept help, thanks!

your heavy function needs let gui process accumulated events. example, can run:

while gtk.events_pending():     gtk.main_iteration() 

another option heavy function run in separate thread, leaving main thread process events , spin spinner. in case, need redesign create_image function asynchronous. example:

def create_image(self, spinner, finishcb):     spinner.start()      def thread_run():         # call heavy here         heavy_ret = heavy()         gobject.idle_add(cleanup, heavy_ret)      def cleanup(heavy_ret):         spinner.stop()         t.join()         finishcb(heavy_ret)      # start "heavy" in separate thread ,     # return mainloop     t = threading.thread(thread_run)     t.start() 

now, instead of calling create_image, need pass callback called when image ready. i.e., instead of:

image = self.create_image(spinner) 

you write:

self.create_image(spinner, self.store_created_image) 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -