Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/video
diff options
context:
space:
mode:
authoryatinmaan <yatinmaan1@gmail.com>2023-06-25 13:49:06 +0300
committeryatin <yatinmaan1@gmail.com>2023-07-02 03:31:32 +0300
commit1ed9992775c0142e67628332f5b72ac598096baf (patch)
tree2b22cd21fcde74110ffe6f43afe51b579d9d15c5 /video
parent8417efc63039b8f8387157d54522d79e26f47c85 (diff)
gtk4: Add python example
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1259>
Diffstat (limited to 'video')
-rw-r--r--video/gtk4/examples/gtksink.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/video/gtk4/examples/gtksink.py b/video/gtk4/examples/gtksink.py
new file mode 100644
index 000000000..c9b0df0ae
--- /dev/null
+++ b/video/gtk4/examples/gtksink.py
@@ -0,0 +1,57 @@
+import gi
+import sys
+
+gi.require_version("Gtk", "4.0")
+gi.require_version('Gst', '1.0')
+
+from gi.repository import Gtk
+from gi.repository import Gst
+
+Gst.init(sys.argv[1:])
+
+gtksink = Gst.ElementFactory.make("gtk4paintablesink", "sink")
+# Get the paintable from the sink
+paintable = gtksink.props.paintable
+
+# Use GL if available
+if paintable.props.gl_context:
+ print("Using GL")
+ source = Gst.ElementFactory.make("gltestsrc", "source")
+ glsink = Gst.ElementFactory.make("glsinkbin", "sink")
+ glsink.props.sink = gtksink
+ sink = glsink
+else:
+ source = Gst.ElementFactory.make("videotestsrc", "source")
+ sink = gtksink
+
+pipeline = Gst.Pipeline.new()
+
+if not pipeline or not source or not sink:
+ print("Not all elements could be created.")
+ exit(-1)
+
+pipeline.add(source)
+pipeline.add(sink)
+source.link(sink)
+
+def on_activate(app):
+ win = Gtk.ApplicationWindow(application=app)
+ box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+
+ picture = Gtk.Picture.new()
+ picture.set_size_request(640, 480)
+ # Set the paintable on the picture
+ picture.set_paintable(paintable)
+ box.append(picture)
+
+ btn = Gtk.Button(label="▶/⏸")
+ box.append(btn)
+ btn.connect('clicked', lambda _: pipeline.set_state(Gst.State.PAUSED) if pipeline.get_state(1)[1]==Gst.State.PLAYING else pipeline.set_state(Gst.State.PLAYING))
+
+ win.set_child(box)
+ win.present()
+
+app = Gtk.Application()
+app.connect('activate', on_activate)
+
+app.run(None)