code_junkie

Progress bar not updating during operation

Nov 13th, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. while work_left:
  2. ...do something...
  3. progressbar.set_fraction(...)
  4.  
  5. while work_left:
  6. ...do something...
  7. progressbar.set_fraction(...)
  8. while gtk.events_pending():
  9. gtk.main_iteration()
  10.  
  11. def my_task(data):
  12. ...some work...
  13. while heavy_work_needed:
  14. ...do heavy work here...
  15. progress_label.set_text(data) # here we update parts of UI
  16. # there's more work, return True
  17. yield True
  18. # no more work, return False
  19. yield False
  20.  
  21. def on_start_my_task_button_click(data):
  22. task = my_task(data)
  23. gobject.idle_add(task.next)
  24.  
  25. #Callback function invoked when download/upload has progress
  26. def progress(download_t, download_d, upload_t, upload_d):
  27. print 'in fileupload progress'
  28. mainwin.mainw.prog_bar.set_fraction(upload_d/upload_t)
  29.  
  30. #Callback function invoked when download/upload has progress
  31. def progress(download_t, download_d, upload_t, upload_d):
  32. print 'in fileupload progress'
  33. mainwin.mainw.prog_bar.set_fraction(float(upload_d) / upload_t)
Add Comment
Please, Sign In to add comment