[pitivi] Move the modules initialization to a single place



commit 0275c9c0cdd2cd1b75c0a1dc8d7a678b55e197fa
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Fri Jan 24 20:00:22 2014 +0100

    Move the modules initialization to a single place

 bin/pitivi.in               |   34 ++++++++++++++++++++++++++++------
 pitivi/check.py             |   26 ++++++--------------------
 pitivi/timeline/controls.py |    8 +++-----
 pitivi/timeline/timeline.py |    6 ------
 pitivi/viewer.py            |    4 ----
 5 files changed, 37 insertions(+), 41 deletions(-)
---
diff --git a/bin/pitivi.in b/bin/pitivi.in
index 4fd9f04..5bb7c48 100644
--- a/bin/pitivi.in
+++ b/bin/pitivi.in
@@ -98,6 +98,30 @@ def _add_pitivi_path():
         _prepend_env_path("GI_TYPELIB_PATH", [CONFIGURED_GI_TYPELIB_PATH])
 
 
+def _initialize_modules():
+    from gi.repository import Gdk
+    Gdk.init([])
+    from gi.repository import GtkClutter
+    GtkClutter.init([])
+    from gi.repository import ClutterGst
+    ClutterGst.init([])
+
+    import gi
+    if not gi.version_info >= (3, 11):
+        from gi.repository import GObject
+        GObject.threads_init()
+
+    from gi.repository import Gst
+    Gst.init(None)
+    from gi.repository import GES
+    GES.init()
+
+    # This is required because of:
+    # https://bugzilla.gnome.org/show_bug.cgi?id=656314
+    from gi.repository import GdkX11
+    GdkX11  # noop
+
+
 def _check_dependencies():
     from pitivi.check import check_hard_dependencies, check_soft_dependencies
     missing_hard_deps = check_hard_dependencies()
@@ -118,12 +142,6 @@ def _check_dependencies():
 
 def _run_pitivi():
     import pitivi.application as ptv
-    from pitivi.check import at_least_version
-    import gi
-
-    if not at_least_version(gi.version_info, (3, 11, 0)):
-        from gi.repository import GObject
-        GObject.threads_init()
 
     # Make it easy for developers to debug the application startup.
     if os.environ.get('PITIVI_DEBUG_NO_UI') == '1':
@@ -136,6 +154,10 @@ def _run_pitivi():
 
 try:
     _add_pitivi_path()
+    try:
+        _initialize_modules()
+    except Exception, e:
+        print "Failed to initialize modules: ", e
     # Dep checks really have to happen here, not in application.py. Otherwise,
     # as soon as application.py starts, it will try importing all the code and
     # the classes in application.py will not even have the opportunity to run.
diff --git a/pitivi/check.py b/pitivi/check.py
index ec16002..e7fe438 100644
--- a/pitivi/check.py
+++ b/pitivi/check.py
@@ -31,18 +31,11 @@ and not impact startup. Module imports have no impact (they get imported later
 by the app anyway). For more complex checks, you can measure (with time.time()),
 when called from application.py instead of bin/pitivi, if it has an impact.
 """
-from sys import modules
-from gettext import gettext as _
 
-# SHENANIGANS
-from gi.repository import Gdk
-Gdk.init([])
+import sys
 
-from gi.repository import GtkClutter
-GtkClutter.init([])
+from gettext import gettext as _
 
-from gi.repository import ClutterGst
-ClutterGst.init([])
 
 # This list is meant to be a complete list for packagers.
 # Unless otherwise noted, modules are accessed through gobject introspection
@@ -123,10 +116,10 @@ def _check_dependency(modulename, from_gobject_introspection):
     module = None
     if from_gobject_introspection is True:
         if _try_import_from_gi(modulename):
-            module = modules["gi.repository." + modulename]
+            module = sys.modules["gi.repository." + modulename]
     else:
         if _try_import(modulename):
-            module = modules[modulename]
+            module = sys.modules[modulename]
 
     if module is None:
         # Import failed, the dependency can't be satisfied, don't check versions
@@ -181,11 +174,11 @@ def check_hard_dependencies():
 
     # Since we had to check Gst beforehand, we only do the import now:
     from gi.repository import Gst
-    Gst.init(None)
 
+    registry = Gst.Registry.get()
     # Special case: gnonlin is a plugin, not a python module to be imported,
     # we can't use check_dependency to determine the version:
-    inst = Gst.Registry.get().find_plugin("gnonlin")
+    inst = registry.find_plugin("gnonlin")
     if not inst:
         missing_hard_deps["GNonLin"] = (HARD_DEPS["gnonlin"], inst)
     else:
@@ -193,10 +186,6 @@ def check_hard_dependencies():
         if _string_to_list(inst) < _string_to_list(HARD_DEPS["gnonlin"]):
             missing_hard_deps["GNonLin"] = (HARD_DEPS["gnonlin"], inst)
 
-    # GES is checked, import and intialize it
-    from gi.repository import GES
-    GES.init()
-
     # Prepare the list of hard deps errors to warn about later:
     for dependency in missing_hard_deps:
         req = missing_hard_deps[dependency][0]
@@ -226,10 +215,7 @@ def check_soft_dependencies():
     If those are missing from the system, the user will be notified of their
     existence by the presence of a "Missing dependencies..." button at startup.
     """
-    # Importing Gst again (even if we did it in hard deps checks), anyway it
-    # seems to have no measurable performance impact the 2nd time:
     from gi.repository import Gst
-    Gst.init(None)
 
     # Description strings are translatable as they are shown in the Pitivi UI.
     if not _try_import("pycanberra"):
diff --git a/pitivi/timeline/controls.py b/pitivi/timeline/controls.py
index 09e67cb..1f2f4c8 100644
--- a/pitivi/timeline/controls.py
+++ b/pitivi/timeline/controls.py
@@ -20,15 +20,13 @@
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
+from gi.repository import Clutter
+from gi.repository import GObject
 from gi.repository import GtkClutter
-GtkClutter.init([])
-
-from gi.repository import Clutter, GObject
 
+from pitivi.timeline.layer import VideoLayerControl, AudioLayerControl
 from pitivi.utils.ui import EXPANDED_SIZE, SPACING, CONTROL_WIDTH
 
-from layer import VideoLayerControl, AudioLayerControl
-
 
 class ControlActor(GtkClutter.Actor):
     def __init__(self, container, widget, layer, is_audio):
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 20ed640..f34a1ac 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -22,15 +22,11 @@
 
 import os
 
-import gi
 from gi.repository import GtkClutter
 
-GtkClutter.init([])
-
 from gi.repository import Gst, GES, GObject, Clutter, Gtk, GLib, Gdk
 
 from pitivi.autoaligner import AlignmentProgressDialog, AutoAligner
-from pitivi.check import at_least_version
 from pitivi.configure import get_ui_dir
 from pitivi.dialogs.prefs import PreferencesDialog
 from pitivi.settings import GlobalSettings
@@ -649,8 +645,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         Zoomable.__init__(self)
         Gtk.Grid.__init__(self)
         Loggable.__init__(self)
-        if not at_least_version(gi.version_info, (3, 11, 0)):
-            GObject.threads_init()
 
         # Allows stealing focus from other GTK widgets, prevent accidents:
         self.props.can_focus = True
diff --git a/pitivi/viewer.py b/pitivi/viewer.py
index 52a3235..4ba5fd2 100644
--- a/pitivi/viewer.py
+++ b/pitivi/viewer.py
@@ -24,12 +24,8 @@ from gi.repository import Gtk
 from gi.repository import GtkClutter
 from gi.repository import Gdk
 from gi.repository import Gst
-from gi.repository import GdkX11
 from gi.repository import GObject
 from gi.repository import GES
-GdkX11  # pyflakes
-from gi.repository import GstVideo
-GstVideo    # pyflakes
 import cairo
 
 from gettext import gettext as _


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]