将Python控制台集成到GUI C ++应用程序中 [英] Integration of Python console into a GUI C++ application

查看:1100
本文介绍了将Python控制台集成到GUI C ++应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将在一些其他控件下面添加一个python控制台小部件(到C ++ GUI):

I'm going to add a python console widget (into a C++ GUI) below some other controls:

许多类都将暴露给python代码,包括对GUI的访问考虑PyQt)。

Many classes are going to be exposed to the python code, including some access to GUI (maybe I'll consider PyQt).


我应该在一个单独的线程中运行Python代码吗?

Should I run the Python code in a separate thread?

我认为这是一个很好的方法,因为GUI在执行长命令时不会被冻结。

I think it's a good approach, because GUI won't be frozen while executing long commands. But on the other hand, shouldn't other controls be disabled to preserve objects' state and avoid conflicts?

推荐答案

因为你'显然想嵌入一个Python解释器来使用Python作为脚本语言在一个似乎是一个Qt应用程序,我建议你看看 PythonQt

Since you're apparently wanting to embed a Python interpreter to use Python as a scripting language in a what seems to be a Qt application, I suggest you have a look at PythonQt.

使用PythonQt模块,Python脚本将能够与主机应用程序的GUI交互。

With the PythonQt module, Python scripts will be able to interact with the GUI of your host application.


与PyQt和Qt Jambi不同,PythonQt不是为编写独立应用程序的开发人员提供支持。

Unlike PyQt and Qt Jambi, PythonQt is not designed to provide support for developers writing standalone applications. Instead, it provides facilities to embed a Python interpreter and focuses on making it easy to expose parts of the application to Python.

如果我使用了Python解释器,那么它会提供嵌入Python解释器的功能,正确理解您的需求。这是您需要的。

If I understood your needs correctly, that's all you need.

PyQt PySide (由诺基亚官方支持)旨在通过提供绑定来从Python程序访问Qt功能。

PyQt and PySide (officially supported by Nokia) aim at accessing Qt features from a Python program by providing bindings.

可以在您的应用程序中嵌入PyQt(甚至是Qt应用),您的Python脚本将能够在与您的应用程序脚本API进行交互时提供自己的GUI。

It's possible to embed PyQt in your application (even a Qt application) and your Python scripts will be able to provide their own GUI while interacting with your application scripting API.

关于线程安全,Qt提供了线程安全的事件发布方式,

About thread safety, Qt offers a thread-safe way of posting events, and signal-slot connections across threads.

参考文献:

  • Embedding Python into Qt Applications.
  • Notes for embedding python in your C/C++ app
  • EmbedingPyQtTutorial

这篇关于将Python控制台集成到GUI C ++应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆