[Interest] Qt program scripting with PySide2

Cristián Maureira-Fredes Cristian.Maureira-Fredes at qt.io
Wed Sep 2 11:50:05 CEST 2020



On 9/2/20 11:32 AM, Filippo Rusconi via Interest wrote:
> Greetings, Fellow Developers,
> 
> [snip]
>>
>> I hope that helps you,
> 
> Thank you so much, Cristián, for your answer.
> 
> I have looked into the documents that you referred to above and found 
> them very
> exciting. I have a question, though:
> Logically, all the examples are citing the creation of Python bindings 
> to C++
> Qt-based libraries.

The ones I included yes,
but we do have cases with non-Qt projects,
for example:

https://code.qt.io/cgit/pyside/pyside-setup.git/tree/examples/samplebinding?h=5.15

which has this blog post associated:
https://www.qt.io/blog/2018/05/31/write-python-bindings

If you would like to see and even minimal example
on how to generate bindings, you can check this 'hello world'
example from the Virtual Tech Summit 2020:

http://maureira.xyz/talks/qt/qtforpython_vts2020/code/example_module.html


> In my GUI software, I use one public library that I co-develop with a 
> colleague,
> and making Python bindings to it appears to be perfectly feasible. The 
> point is
> that my program (executable GUI binary) is written in C++ and not using 
> PySide2.
> How can I make the features in the GUI binary's code accessible to 
> Python users?
> That is, can bindings be created not only for libs but also for executable
> binaries?  Or, in other words, how can I take control of the C++-based 
> program
> using Python? If this is no possible, then what should be the course of
> development? Switch all the GUI code to PySide2, put any non-GUI code in a
> private lib to which Python bindings would be created ?

I guess with the previous links you will be able to expose C++ code
to Python, independent of the libraries you use, however keep in mind
that if you want to expose a specific aspect of the library you wrote,
you might need bindings for it too.

You cannot create bindings for a specific executable,
but you can expose 'something' from what's forming that executable
to Python, and create bindings for it, for example, on the 
'scriptableapplication' example, we expose only the 'MainWindow' class
to Python, that's why that can provide control of the C++ application,
although, since that depended on a 'QMainWindow' which had bindings
for Python, it was simpler. If something that you want to expose to 
Python, does not have a plain C++ type, that type will require 
additional bindings.

If I may ask, what are you using for your GUI related code?

> 
> Sorry for these layman questions,

Not at all, pretty valid questions.

> 
> Most sincerely,
> 
> Filippo
> 

Cheers!

-- 
Dr. Cristian Maureira-Fredes
R&D Manager

The Qt Company GmbH
Erich-Thilo-Str. 10
D-12489 Berlin

Geschäftsführer: Mika Pälsi,
Juha Varelius, Mika Harjuaho
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B
--


More information about the Interest mailing list