[Interest] Qt program scripting with PySide2 (follow-up)

Cristián Maureira-Fredes Cristian.Maureira-Fredes at qt.io
Thu Sep 3 15:17:17 CEST 2020


Hello,

On 9/3/20 2:40 PM, Filippo Rusconi via Interest wrote:
> Greetings, Fellow Developers,
> 
> [I am using the digest method for list mails delivery, so I cannot reply 
> cleanly
> to a defined message ]
> 
>> Subject: Re: [Interest] Qt program scripting with PySide2
>>
>> 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
> 
> Thank you, Cristian for these pointers.
> 
> Yes, I have looked into them and definitely I will try the Qt
> for Python journey.
> 
> I have indeed followed the install instructions, at
> https://doc.qt.io/qtforpython/gettingstarted-linux.html.
> 
> Using a virtual environment I could perform all the steps on my Debian box,
> until bulding where an error was encountered. Where can I find a place 
> to report
> that error and try to resolve it with the help of gurus ? Maybe 
> #qt-pyside on
> freenode ?

Yes, or any other of the platforms the project has:
https://wiki.qt.io/Qt_for_Python#Community

> 
>> > 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.
> 
> Understood.
> 
>> If I may ask, what are you using for your GUI related code?

Python and C++, with Qt :)

> 
> Sure, I have been writing Qt-based software for a long time. My GUI code is
> Qt-based.  For all the line and heat map plots that I need to display, I 
> use the
> wonderful library called QCustomPlot (see https://www.qcustomplot.com/, GPL
> software by Emanuel Eichhammer).

That looks cool :)
I recently came across https://github.com/alandefreitas/matplotplusplus
which seems to be inspired in the Python module:
https://matplotlib.org/gallery/index.html

On the Python side, you can mix matplotlib with PySide:
https://code.qt.io/cgit/pyside/pyside-setup.git/tree/examples/external/matplotlib

Additionally, PyQtGraph seems to be quite popular:
http://pyqtgraph.org/ (don't get fooled by the name, it's
also compatible with PySide, but it was  there long before PySide
was announced, that's why it uses the 'PyQt' name).


You might even be brave enough to generate Python Bindings
for QCustomPlot using Shiboken :)


> Most sincerely,
> 
> Filippo

I'm certain many people from the community will be able
to give you a hand with your current project idea
on any of the community platforms for PySide.

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