diff --git a/bindings/python/gi/overrides/GES.py b/bindings/python/gi/overrides/GES.py index 05b5f775e1..4df24d7b71 100644 --- a/bindings/python/gi/overrides/GES.py +++ b/bindings/python/gi/overrides/GES.py @@ -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 index 0000000000..f0e79c14f7 --- /dev/null +++ b/bindings/python/meson.build @@ -0,0 +1 @@ +install_data(['gi/overrides/GES.py'], install_dir: pygi_override_dir) \ No newline at end of file diff --git a/meson.build b/meson.build index a4d4c1e611..909ae6b1af 100644 --- a/meson.build +++ b/meson.build @@ -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")') diff --git a/meson_options.txt b/meson_options.txt index 2bf6061f06..75491077c5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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 index 0000000000..114b94cdba --- /dev/null +++ b/tests/check/python/overrides_hack.py @@ -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')) diff --git a/tests/check/python/test_clip.py b/tests/check/python/test_clip.py index efc3c2c3d7..b62e1411a7 100644 --- a/tests/check/python/test_clip.py +++ b/tests/check/python/test_clip.py @@ -17,22 +17,20 @@ # 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, "") diff --git a/tests/check/python/test_group.py b/tests/check/python/test_group.py index 1d220b0cb0..99497129bf 100644 --- a/tests/check/python/test_group.py +++ b/tests/check/python/test_group.py @@ -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") diff --git a/tests/check/python/test_timeline.py b/tests/check/python/test_timeline.py index ebc1c7d130..045c0e05c5 100644 --- a/tests/check/python/test_timeline.py +++ b/tests/check/python/test_timeline.py @@ -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")