Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integration of Python console into a GUI C++ application

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

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

Should I run the Python code in a separate thread?

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?

like image 914
Andrew T Avatar asked Jan 10 '10 19:01

Andrew T


People also ask

How do I convert a Python program to GUI?

If you're new to creating GUI's in Python the basic steps are to: Import the Tkinter module: import Tkinter, top = Tkinter.Tk() Create the GUI main window that will “house” your GUI and widgets. Add whatever widgets your GUI needs including buttons, labels, lists etc.

How does Python code connect to GUI?

Tkinter ProgrammingImport the Tkinter module. Create the GUI application main window. Add one or more of the above-mentioned widgets to the GUI application. Enter the main event loop to take action against each event triggered by the user.


1 Answers

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.

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

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.

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

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

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.

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

References:

  • Embedding Python into Qt Applications.
  • Notes for embedding python in your C/C++ app
  • EmbedingPyQtTutorial
like image 102
Gregory Pakosz Avatar answered Sep 22 '22 08:09

Gregory Pakosz