【问题标题】:How to render MPV to GTK4 window on X11 with python?如何使用 python 在 X11 上将 MPV 渲染到 GTK4 窗口?
【发布时间】:2022-06-13 00:30:47
【问题描述】:

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

【问题讨论】:

    标签: python linux x11 gtk4 mpv


    【解决方案1】:

    我不知道这是否完全正确
    GdkX11.X11Surface.get_xid() 将 X11Surface 作为参数
    试试这个:

    self.mpv = mpv.MPV(wid=str(GdkX11.X11Surface.get_xid(self.get_surface())))
    

    这对我有用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-14
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 2012-07-03
      相关资源
      最近更新 更多