How to properly wrap a c++ library which uses qt with shiboken2? - python

I have seen the FAQ https://wiki.qt.io/Qt_for_Python#Frequently_Asked_Questions which states
Take into account that if you want to generate bindings for a Qt/C++
project, the linking to the Qt shared libraries will be missing, and
you will need to do this by hand. We recommend to build PySide2 from
scratch to have everything properly linked.
Suppose you want to use shiboken2 to wrap a c++ library which itself uses qt and it even uses qt classes in its interface. In the python world you should be able to
pip install PySide2 my_cpp_lib
and afterwards python scripts shall be able to
import my_cpp_lib
from PySide2.QtCore import QObject
my_cool_object = QObject()
my_cpp_lib.my_cool_api(my_cool_object)
It is pretty unclear to me how to achieve that setup. From the FAQ I deduce that it would be good to compile PySide2 from source in this case (because I want to use shiboken2_generator to wrap my_cpp_lib). However, I still want to be compatible to the standard PySide2 package (of course there will be a version dependency between my_cpp_lib and PySide2).
Is linking against the QT shared object/dll of PySide2 a bad idea? If so, why? what would be better instead?
If the qt library should be packaged together with the my_cpp_lib python package, then how is it possible to still use PySide without conflicts (because there are essential two different shared objects)?

Related

Is it impossible to create GUI in python without tkinter?

I wanna know, Is it possible to create GUI in python without using tkinter?
Tk isn't technically making the GUI, it's delegating to a C library; and that's exactly what you can do too. For simplicity however, it's pretty much standard to use TkInter, or some other framework (i recommend PySimpleGUI) that takes care of the Tk interaction for you
easygui is the easiest GUI python that I have used. Designs are prebuilt for you already. Examples of easygui can. be found here https://pypi.org/project/easygui/
You can also use Flask where the frontend will be the web browser.
Tcl/Tk is an external library although it comes as part of the standard python install and it is an external library. you can use other framework to do that .
Fundamentally, Python can’t talk to any GUI system without an external module. Since the most fundamental GUI libraries on any platform are usually C-based, that requires, at minimum, importing a library like ctypes which itself is minimal and allows you to load system GUI libraries (in dlls or delis, depending on your platform).It is possible, in theory at least, to drive a GUI solely from ctypes, but it’s not very practical .

Can I leverage the Qt Meta-Object system in PyQt like I can in PythonQt?

I know in PythonQt I can access MOC'd QObject based classes in Python code and that python code can be executed from C++. Is it possible to do something similar using PyQt or is it intended to be used only to write Qt in Python?
I understand SIP is used to expose C/C++ code to Python but that doesn't seem to be as elegant as using the meta-object system.
I have never used PythonQt, but after a brief skim of the features, it seems that, in terms of conceptual emphasis, it really should have been called QtPython.
PyQt started life as a tool for prototyping Qt C++ applications in python. As a consequence, it was originally a very thin wrapper around the Qt library, which made it almost trivial to port Qt code from python to C++ and vice versa. And it still is quite easy to do this. But since PyQt4, the emphasis has shifted strongly towards making it easier to write Qt applications in Python; and with PyQt5, it has moved even further in that direction.
So PyQt is now intended purely for writing Qt applications in python (and the same goes for PySide). It does not provide any facility for executing python code within C++ (other than indirectly via virtual functions). If you need to expose third-party Qt classes to python, you would need to wrap them using Sip.
As for the meta-object system: PyQt does wrap QMetaObject and so forth, but there is not enough information in your question to know whether that would be of any use to you.

Installation of PyQt4

I currently begin to use Python (2.7) with Eclipse(on windows). To run my script,I would need PyQt4 but I meet some problems when I try to install it.
I downloaded
PyQt4-4.10.3-gpl-Py2.7-Qt4.8.5-x64.exe,
PyQt-win-gpl-4.10.3.zip
and sip-4.15.2.zip
from the following link: http://www.riverbankcomputing.co.uk/software/pyqt/download .
I launched the execution of the first feature and a folder PyQt4 appeared into C:\Python27\Lib\site-packages.
To my mind, PyQt4 installation was finished and I simply did:
Eclipse>Preferences>Pydev>Interpreter-Python>python27>Apply
Nevertheless, when I try to import any function of PyQt4, I am said that the module name is unknown.
Could you help me to solve this problem?
Thank you very much
I want to comment for this .... but my reputation doesn't allow me to :(
anyway You could try this answer ..... (link below)
which is something like that :
Copy from This Answer
PyQt is actually a wrapping of C++ Qt libraries. So they are not .py
files an
d PyDev can't analyze them to
get what is in them. You need to add PyQt4 in the Forced Builtins tab,
so that PyDev can use a Python shell to "look into" those libraries
and know what is in them. That will also give you code-completion for
PyQt.
Apart from that, it is usually not a good practice to use from foo
import *. You'll be importing everything inside your namespace and you
wouldn't know which is coming from where. Moreover you might have name
clashes that mask each other. Though it is unlikely with PyQt, still
I'd suggest you get used to from PyQt4 import QtGui, QtCore and
reference classes like QtGui.QMainWindow.

Equivalent of pyrcc4 on KDE

Am working on a pyqt app, done the ui via qt-designer 4.8.1, and generated the corresponding py file using pykdeuic4 (available on OpenSuse 12.2), but can't find an equivalent for pyrcc4 to hadle the *.qrc files.
what's the equivalent tool/command?
Edit:
Most of the documentation on using QtDesigner with PyQt, indicates using pyuic4 / pyuic (which on my platform is pykdeuic4), but as for the other tool pyrcc4 / pyrcc, I can't find an equivalent.
Am wondering, where can I even get the original tool from (pyrcc4)?
There is no PyKDE-specific tool that corresponds with pyrrc4. The KDE python bindings are built on top of PyQt, so you can just use pyrrc4 itself.
PyKDE only needs a specialized tool (pykdeuic4) for compiling ui files, because obviously KDE has lots of widgets that PyQt doesn't know about.
For OpenSuse, I believe the package that contains pyrrc is python-qt4-utils.
NB: The PyKDE project is moribund: see here for details.
Well, turns out all I needed was to install the extra package python-qt4-utils ontop of the existing python-qt4. Now, I have the sought after utilities in place.

Any guidelines to develop a Qt UI with Pyside?

I'm new to Qt and Pyside, and confused with lots of dazzling concepts and tools.
Instead of using IDE provided, I prefer to vim.
So I wonder what the generic guideline is. That is to say, what're the QML, Qt Creator, Qt Designer? Do I need to use all of them? And what's the normal workflow?
And at last, there're few tutorials about Qt in python, so can I invoke the Qt C++ docs for help (any big differences between C++ Qt programming and Python one)?
I wrote some PyQt based tutorials after leaving my last job, they can apply to PySide also and have some helpful tips in there too: http://bitesofcode.blogspot.com/
I agree you don't need QML or Qt Creator - but using the Qt Designer for building your interfaces would definitely be the way I would recommend going about it.
I make GUIs in a text editor, right in the Python program. You don't have to use QML, Qt Creator. Just read the Jan Bodnar's PySide tutorial and then you'll be able to figure out the rest by yourself, by looking at PySide or C++ Qt documentation

Categories