summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2012-10-16 12:53:57 +0200
committerMartin Sivak <msivak@redhat.com>2012-10-16 13:07:50 +0200
commit8d65f4e89fc4f036be3b283c1b5a2041153593b5 (patch)
tree0a28244217c839305ad2b6e459390b2b63f1efa3
parent8580fde007d483f0e45a453b058f29b2a09d0c54 (diff)
downloadanaconda-8d65f4e89fc4f036be3b283c1b5a2041153593b5.tar.gz
anaconda-8d65f4e89fc4f036be3b283c1b5a2041153593b5.tar.xz
anaconda-8d65f4e89fc4f036be3b283c1b5a2041153593b5.zip
Remove Gdk thread initialization, introduce new helper functions and make exception handler be called by Gtk only once
-rw-r--r--pyanaconda/__init__.py3
-rw-r--r--pyanaconda/exception.py3
-rw-r--r--pyanaconda/ui/gui/utils.py67
3 files changed, 62 insertions, 11 deletions
diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py
index c46d20c6a..4844f00da 100644
--- a/pyanaconda/__init__.py
+++ b/pyanaconda/__init__.py
@@ -211,9 +211,6 @@ class Anaconda(object):
raise RuntimeError, "Second attempt to initialize the InstallInterface"
if self.displayMode == 'g':
- from gi.repository import Gdk
- Gdk.threads_init()
-
from pyanaconda.ui.gui import GraphicalUserInterface
self._intf = GraphicalUserInterface(self.storage, self.payload,
self.instClass)
diff --git a/pyanaconda/exception.py b/pyanaconda/exception.py
index 4e369d85c..94adf8255 100644
--- a/pyanaconda/exception.py
+++ b/pyanaconda/exception.py
@@ -59,7 +59,8 @@ class AnacondaExceptionHandler(ExceptionHandler):
super(AnacondaExceptionHandler, self).handleException((ty, value, tb),
obj)
-
+ return False
+
if issubclass(ty, storage.errors.StorageError) and value.hardware_fault:
hw_error_msg = _("The installation was stopped due to what "
"seems to be a problem with your hardware. "
diff --git a/pyanaconda/ui/gui/utils.py b/pyanaconda/ui/gui/utils.py
index fcd0f767f..10ad1dfe6 100644
--- a/pyanaconda/ui/gui/utils.py
+++ b/pyanaconda/ui/gui/utils.py
@@ -19,7 +19,66 @@
# Red Hat Author(s): Chris Lumens <clumens@redhat.com>
#
from contextlib import contextmanager
-from gi.repository import Gdk, Gtk
+from gi.repository import Gdk, Gtk, GLib
+import Queue
+
+def gtk_call_once(func, *args):
+ """Wrapper for GLib.idle_add call that ensures the func is called
+ only once.
+ """
+ def wrap(args):
+ func(*args)
+ return False
+
+ GLib.idle_add(wrap, args)
+
+def gtk_thread_wait(func):
+ """Decorator method which causes every call of the decorated function
+ to be executed in the context of Gtk main loop and returns the ret
+ value after the decorated method finishes.
+
+ Method decorated by this decorator must not be called from inside
+ of the Gtk main loop. It will cause a hang.
+ """
+ queue = Queue.Queue()
+
+ def _idle_method(q_args):
+ """This method contains the code for the main loop to execute.
+ """
+ queue, args = q_args
+ ret = func(*args)
+ queue.put(ret)
+ return False
+
+ def _call_method(*args):
+ """The new body for the decorated method. It uses closure bound
+ queue variable which is valid until the reference to this method
+ is destroyed."""
+ GLib.idle_add(_idle_method, (queue, args))
+ return queue.get()
+
+ return _call_method
+
+
+def gtk_thread_nowait(func):
+ """Decorator method which causes every call of the decorated function
+ to be executed in the context of Gtk main loop. The new method does
+ not wait for the callback to finish.
+ """
+
+ def _idle_method(args):
+ """This method contains the code for the main loop to execute.
+ """
+ ret = func(*args)
+ return False
+
+ def _call_method(*args):
+ """The new body for the decorated method.
+ """
+ GLib.idle_add(_idle_method, args)
+
+ return _call_method
+
@contextmanager
def enlightbox(mainWindow, dialog):
@@ -29,12 +88,6 @@ def enlightbox(mainWindow, dialog):
yield
lightbox.destroy()
-@contextmanager
-def gdk_threaded():
- Gdk.threads_enter()
- yield
- Gdk.threads_leave()
-
def setViewportBackground(vp, color="@theme_bg_color"):
"""Set the background color of the GtkViewport vp to be the same as the
overall UI background. This should not be called for every viewport,