[英]How to render MPV to GTK4 window on X11 with python?
mpv 如何渲染到 GTK4 窗口或小部件? 在 GTK3 中很容易获得 XID(并将其作为 MPV 的参数),但在 GTK4 中似乎必须使用 GtkX11 和 X11Surface https://docs.gtk.org/gdk4-x11/method.X11Surface.get_xid .html但我不知道如何在 python 中做到这一点 - 无法从窗口/小部件获取表面。
#!/usr/bin/env python3
import gi
import mpv
gi.require_version('Gtk', '4.0')
gi.require_version('Gdk', '4.0')
gi.require_version('GdkX11', '4.0')
from gi.repository import Gtk, Gdk, GdkX11
class MainClass(Gtk.ApplicationWindow):
def __init__(self, app):
super(MainClass, self).__init__()
self.set_application(app)
self.set_default_size(600, 400)
self.connect("destroy", self.on_destroy)
widget = Gtk.Frame()
self.set_child(widget)
self.present()
# Can't get XID from widget there
self.mpv = mpv.MPV(wid=str(GdkX11.X11Surface.get_xid(widget)))
self.mpv.play("test.webm")
def on_destroy(self, widget, data=None):
self.mpv.terminate()
Gtk.main_quit()
def on_activate(app):
application = MainClass(app)
if __name__ == '__main__':
# This is necessary since like Qt, Gtk stomps over the locale settings needed by libmpv.
# Like with Qt, this needs to happen after importing Gtk but before creating the first mpv.MPV instance.
import locale
locale.setlocale(locale.LC_NUMERIC, 'C')
app = Gtk.Application()
app.connect('activate', on_activate)
app.run(None)
TypeError: argument self: Expected GdkX11.X11Surface, but got gi.repository.Gtk.Frame
我不知道这是否完全正确
GdkX11.X11Surface.get_xid() 将 X11Surface 作为参数
尝试这个:
self.mpv = mpv.MPV(wid=str(GdkX11.X11Surface.get_xid(self.get_surface())))
这对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.