gpt4 book ai didi

python - pyside 嵌入 vim

转载 作者:行者123 更新时间:2023-12-01 05:53:48 27 4
gpt4 key购买 nike

我知道将 vim 嵌入 Gtk application使用像下面的代码片段这样的套接字

from gi.repository import Gtk
import subprocess

win=Gtk.Window()
win.set_default_size(600,800)
win.connect('delete-event', Gtk.main_quit)
editor = Gtk.Socket()
win.add(editor)
editor.connect("plug-removed", Gtk.main_quit)
subprocess.Popen(["/usr/bin/gvim", \
"--socketid", str(editor.get_id())])
win.show_all()
Gtk.main()

如何在 PySide 中做到这一点?我在 pyside 中找不到任何对套接字的引用。

更新(使用 JimP 的想法)

以下代码将 gvim 实例嵌入到 Pyside 小部件中。然而,当达到父窗口的完整大小时,gvim 窗口似乎没有调整大小。

import sys
from PySide import QtGui
from PySide import QtCore

app = QtGui.QApplication(sys.argv)
win = QtGui.QWidget()
win.resize(600, 800)

container = QtGui.QX11EmbedContainer(win)
container.show()
QtCore.QObject.connect(container,
QtCore.SIGNAL("clientClosed()"),
QtCore.QCoreApplication.instance().quit)
winId = container.winId()
process = QtCore.QProcess(container)
options = ["--socketid", str(winId)]
process.start("gvim", options)

win.show()
sys.exit(app.exec_())

最佳答案

我认为实现这一目标的关键是将 GTK 语言转换为 QT 语言。谷歌你的代码,我看到Gtk.Socket说:

The communication between a GtkSocket and a GtkPlug follows the XEmbed protocol. This protocol has also been implemented in other toolkits, e.g. Qt, allowing the same level of integration when embedding a Qt widget in GTK or vice versa.

那么问题就变成了 QT 怎样调用它们的 XEmbed 类?谷歌了一下我发现QX11EmbedContainer其中说:

It is possible for PySide.QtGui.QX11EmbedContainer to embed XEmbed widgets from toolkits other than Qt, such as GTK+. Arbitrary (non-XEmbed) X11 widgets can also be embedded, but the XEmbed-specific features such as window activation and focus handling are then lost.

The GTK+ equivalent of PySide.QtGui.QX11EmbedContainer is GtkSocket. The corresponding KDE 3 widget is called QXEmbed.

我目前没有运行 PySide,但运行 QX11EmbedContainer 上的页面包含一些示例 C++ 代码,我认为它们可以帮助您到达所需的位置。您需要将 C++ 转换为 Python,但我认为这不会太难。

关于python - pyside 嵌入 vim,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13359699/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com