python: Fix GES.Timelineset_child_property
authorThibault Saunier <tsaunier@igalia.com>
Sun, 8 Jul 2018 14:36:36 +0000 (10:36 -0400)
committerThibault Saunier <tsaunier@igalia.com>
Sun, 8 Jul 2018 20:02:28 +0000 (16:02 -0400)
Implementing it in the overrides as PyGObject won't be able to properly
convert python values to GValues in some cases. Using
g_object_set_property works as some logic is implemented inside
PyGObject for that particular case. This is a "regression" due
to https://bugzilla.gnome.org/review?bug=769789&attachment=348766 were
we end up with an OverflowError while setting G_TYPE_UINT children
properties.

bindings/python/gi/overrides/GES.py
bindings/python/meson.build [new file with mode: 0644]
meson.build
meson_options.txt
tests/check/python/overrides_hack.py [new file with mode: 0644]
tests/check/python/test_clip.py
tests/check/python/test_group.py
tests/check/python/test_timeline.py

index 05b5f77..4df24d7 100644 (file)
@@ -28,6 +28,7 @@ import sys
 from ..overrides import override
 from ..importer import modules
 
+
 if sys.version_info >= (3, 0):
     _basestring = str
     _callable = lambda c: hasattr(c, '__call__')
@@ -50,6 +51,30 @@ python module to use with GES 0.10"
     warnings.warn(warn_msg, RuntimeWarning)
 
 
+class TrackElement(GES.TrackElement):
+    def set_child_property(self, prop_name, prop_value):
+        return TimelineElement.set_child_property(self, prop_name, prop_value)
+
+
+TrackElement = override(TrackElement)
+__all__.append('TrackElement')
+
+
+class TimelineElement(GES.TimelineElement):
+    def set_child_property(self, prop_name, prop_value):
+        res, child, unused_pspec = self.lookup_child(prop_name)
+        if not res:
+            print("No found any child")
+            return res
+
+        child.set_property(prop_name, prop_value)
+        return res
+
+
+TimelineElement = override(TimelineElement)
+__all__.append('TimelineElement')
+
+
 try:
     from gi.repository import Gst
     Gst
diff --git a/bindings/python/meson.build b/bindings/python/meson.build
new file mode 100644 (file)
index 0000000..f0e79c1
--- /dev/null
@@ -0,0 +1 @@
+install_data(['gi/overrides/GES.py'], install_dir: pygi_override_dir)
\ No newline at end of file
index a4d4c1e..909ae6b 100644 (file)
@@ -160,6 +160,50 @@ subdir('pkgconfig')
 subdir('tests')
 subdir('examples')
 
+override_detector = '''
+import sys
+import os
+
+prefix = sys.argv[1]
+version = sys.version_info
+
+# If we are installing in the same prefix as PyGobject
+# make sure to install in the right place.
+import gi.overrides
+
+overrides_path = os.path.dirname(gi.overrides.__file__)
+if os.path.commonprefix([overrides_path, prefix]) == prefix:
+    print(overrides_path)
+    exit(0)
+
+# Otherwise follow python's way of install site packages inside
+# the provided prefix
+if os.name == 'posix':
+    print(os.path.join(
+        prefix, 'lib', 'python%d.%d' % (version.major, version.minor),
+        'site-packages', 'gi', 'overrides'))
+else:
+    print(os.path.join(
+        prefix, 'Lib', 'Python%d%d' % (version.major, version.minor),
+        'site-packages', 'gi', 'overrides'))
+'''
+python3 = import('python3').find_python()
+pygi_override_dir = get_option('pygi-overrides-dir')
+if pygi_override_dir == ''
+    cres = run_command(python3, '-c', override_detector, get_option('prefix'))
+    if cres.returncode() == 0
+      pygi_override_dir = cres.stdout().strip()
+    endif
+    if cres.stderr() != ''
+        message(cres.stderr())
+    endif
+endif
+
+if pygi_override_dir != ''
+  message('pygobject overrides directory ' + pygi_override_dir)
+  subdir('bindings/python')
+endif
+
 if build_machine.system() == 'windows'
   message('Disabling gtk-doc while building on Windows')
 elif not get_option('gtk_doc')
@@ -172,5 +216,4 @@ else
   endif
 endif
 
-python3 = import('python3').find_python()
 run_command(python3, '-c', 'import shutil; shutil.copy("hooks/pre-commit.hook", ".git/hooks/pre-commit")')
index 2bf6061..7549107 100644 (file)
@@ -2,3 +2,5 @@ option('introspection', type : 'boolean', value : true, yield : true,
        description : 'Generate gobject-introspection bindings')
 option('gtk_doc', type : 'boolean', value : true, yield : true,
        description : 'Build API documentation with gtk-doc')
+option('pygi-overrides-dir', type : 'string', value : '',
+        description: 'Path to pygobject overrides directory')
\ No newline at end of file
diff --git a/tests/check/python/overrides_hack.py b/tests/check/python/overrides_hack.py
new file mode 100644 (file)
index 0000000..114b94c
--- /dev/null
@@ -0,0 +1,25 @@
+import os
+import gi.overrides
+
+LOCAL_OVERRIDE_PATH = "gst-editing-services/bindings/python/gi/overrides/"
+FILE = os.path.realpath(__file__)
+if not gi.overrides.__path__[0].endswith(LOCAL_OVERRIDE_PATH):
+    local_overrides = None
+    # our overrides don't take precedence, let's fix it
+    for i, path in enumerate(gi.overrides.__path__):
+        if path.endswith(LOCAL_OVERRIDE_PATH):
+            local_overrides = path
+
+    if local_overrides:
+        gi.overrides.__path__.remove(local_overrides)
+    else:
+        local_overrides = os.path.abspath(os.path.join(FILE, "../../../../../", LOCAL_OVERRIDE_PATH))
+
+    gi.overrides.__path__.insert(0, local_overrides)
+
+# Execute previously set sitecustomize.py script if it existed
+if os.environ.get("GST_ENV"):
+    old_sitecustomize = os.path.join(os.path.dirname(__file__),
+                                    "old.sitecustomize.gstuninstalled.py")
+    if os.path.exists(old_sitecustomize):
+        exec(compile(open(old_sitecustomize).read(), old_sitecustomize, 'exec'))
index efc3c2c..b62e141 100644 (file)
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
-import gi
+from . import overrides_hack
 
+import gi
 gi.require_version("Gst", "1.0")
 gi.require_version("GES", "1.0")
 
 from gi.repository import Gst  # noqa
+Gst.init(None)  # noqa
 from gi.repository import GES  # noqa
+GES.init()
 
 import unittest  # noqa
 
 
-
-Gst.init(None)
-GES.init()
-
-
 class TestCopyPaste(unittest.TestCase):
 
     def setUp(self):
@@ -72,6 +70,13 @@ class TestCopyPaste(unittest.TestCase):
 
 class TestTitleClip(unittest.TestCase):
 
+    def testSetColor(self):
+        timeline = GES.Timeline.new_audio_video()
+        clip = GES.TitleClip.new()
+        timeline.append_layer().add_clip(clip )
+        self.assertTrue(clip.set_child_property('color', 1))
+        self.assertTrue(clip.set_child_property('color', 4294967295))
+
     def testGetPropertyNotInTrack(self):
         title_clip = GES.TitleClip.new()
         self.assertEqual(title_clip.props.text, "")
index 1d220b0..9949712 100644 (file)
@@ -17,6 +17,8 @@
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
+from . import overrides_hack
+
 import gi
 
 gi.require_version("Gst", "1.0")
index ebc1c7d..045c0e0 100644 (file)
@@ -17,6 +17,8 @@
 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
+from . import overrides_hack
+
 import gi
 
 gi.require_version("Gst", "1.0")