From 58dc389e4832872bd8ea71483620aac151b7a093 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sat, 12 Dec 2009 17:01:06 +0000 Subject: [PATCH] Sometimes, the pending events can get into an infinite loop of causing more events to be handled; this fix makes it finite svn: r13778 --- src/DisplayState.py | 14 +++++--------- src/gui/utils.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/DisplayState.py b/src/DisplayState.py index e32879d70..d01c10a0a 100644 --- a/src/DisplayState.py +++ b/src/DisplayState.py @@ -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() diff --git a/src/gui/utils.py b/src/gui/utils.py index 81aec6789..9a7b99c9b 100644 --- a/src/gui/utils.py +++ b/src/gui/utils.py @@ -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