程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在 pyqt 中嵌入 gnuplot qt?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何在 pyqt 中嵌入 gnuplot qt??

开发过程中遇到如何在 pyqt 中嵌入 gnuplot qt?的问题如何解决?下面主要结合日常开发的经验,给出你关于如何在 pyqt 中嵌入 gnuplot qt?的解决方法建议,希望对你解决如何在 pyqt 中嵌入 gnuplot qt?有所启发或帮助;

gnuplot 终端 addClasses 接受 qt (http://www.bersch.net/gnuplot-doc/complete-list-of-terminals.html#qt)。 如何使用此 ID 号将 gnuplot qt 窗口嵌入到 pyqt5 应用程序中?我希望有一个最少的工作代码。

C++ 的类似问题没有答案 (Embed gnuplot inside exisTing QtWidget)。

为了比较,使用 Widget ID (program tcl/tk) + wish 终端,以下工作

x11

如何在 pyqt 中嵌入 gnuplot qt?

解决方法

您可以使用 QProcess 发送命令,并在这些命令中将窗口 ID 传递给它:

import sys
from functools import cached_property

from PyQt5 import QtCore,QtWidgets


class GnuPlotManager(QtCore.QObject):
    @cached_property
    def process(self):
        qprocess = QtCore.QProcess()
        qprocess.setProgram("gnuplot")
        return qprocess

    def start(self):
        self.process.start()

    def send_command(self,command):
        self.process.write((command + "\n").encode())


class MainWindow(QtWidgets.QMainWindow):
    def __init__(self,parent=NonE):
        super().__init__(parent)

        central_widget = QtWidgets.QWidget()
        self.setCentralWidget(central_widget)

        button = QtWidgets.QPushButton("Send Command")

        lay = QtWidgets.QVBoxLayout(central_widget)
        lay.addWidget(self.command_lE)
        lay.addWidget(button)
        lay.addWidget(self.container)

        button.clicked.connect(self.handle_clicked)

        self.gnuplot_manager.start()
        self.gnuplot_manager.send_command("set terminal qt")
        wid = int(self.container.winId())
        self.gnuplot_manager.send_command(f"set term x11 window '{wid:x}'")

        self.gnuplot_manager.send_command("clear")

        self.command_le.setText("pl sin(X)")

        self.resize(640,480)

    @cached_property
    def container(self):
        return QtWidgets.QWidget()

    @cached_property
    def command_le(self):
        return QtWidgets.QLineEdit()

    @cached_property
    def gnuplot_manager(self):
        return GnuPlotManager()

    def handle_clicked(self):
        self.gnuplot_manager.send_command(self.command_le.text())
        self.updateGeometry()


def main(args):
    app = QtWidgets.QApplication(args)

    w = MainWindow()
    w.show()

    ret = app.exec_()
    sys.exit(ret)


if __name__ == "__main__":
    main(sys.argv)

如何在 pyqt 中嵌入 gnuplot qt?

大佬总结

以上是大佬教程为你收集整理的如何在 pyqt 中嵌入 gnuplot qt?全部内容,希望文章能够帮你解决如何在 pyqt 中嵌入 gnuplot qt?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。