Sometimes, the pending events can get into an infinite loop of causing more events to be handled; this fix makes it finite

svn: r13778
This commit is contained in:
Doug Blank 2009-12-12 17:01:06 +00:00
parent b1254d7820
commit 58dc389e48
2 changed files with 17 additions and 9 deletions

View File

@ -52,6 +52,7 @@ import gobject
#
#-------------------------------------------------------------------------
import gen.utils
from gui.utils import process_pending_events
import config
from BasicUtils import name_displayer
import const
@ -404,8 +405,7 @@ class DisplayState(gen.utils.Callback):
self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
else:
self.window.window.set_cursor(None)
while gtk.events_pending():
gtk.main_iteration()
process_pending_events()
def set_open_widget(self, widget):
self.widget = widget
@ -443,18 +443,14 @@ class DisplayState(gen.utils.Callback):
else:
name = _("No active person")
self.status.push(self.status_id, name)
while gtk.events_pending():
gtk.main_iteration()
process_pending_events()
def pulse_progressbar(self, value):
self.progress.set_fraction(min(value/100.0, 1.0))
self.progress.set_text("%d%%" % value)
while gtk.events_pending():
gtk.main_iteration()
process_pending_events()
def status_text(self, text):
self.status.pop(self.status_id)
self.status.push(self.status_id, text)
while gtk.events_pending():
gtk.main_iteration()
process_pending_events()

View File

@ -271,3 +271,15 @@ def open_file_with_default_application( file_path ):
if os.path.isfile(prog):
os.spawnvpe(os.P_NOWAIT, prog, [prog, norm_path], os.environ)
return
def process_pending_events(max_count=10):
"""
Process pending events, but don't get into an infinite loop.
"""
import gtk
count = 0
while gtk.events_pending():
gtk.main_iteration()
count += 1
if count >= max_count:
break