The blend of Qt in Python
(Image taken from PyQT Wikipedia article)
Before we even begin this new article series, I would like to emphasize one thing : I would love to make this blog as a great starting point for you to learn many tidbits in Python software development. For example, even though what we learn is somewhat an advance topic in Python application development, I will always start with the basic. This eventually create a vast array of article series : Flask, Django, ProgrammedMe, Kivy, etc. The reason is quite simple : if you are new to a Python topic, you can always refer to the first article in a series to be able to follow the rest of the articles.
In this new article series, the target that I want to accomplished is to introduce you to the Python Android application development using either PySide or PyQt. Yes, previously you have been introduced to Kivy to develop Python application in Android. But, before going even further in Kivy, lets have a comparative experience on Python application development using another libray : PySide/PyQt. This come with a requirement : you must be introduced to and able to develop a PySide/PyQt application in its Desktop environment. Then, we move to its Android development.This is necessary, as differ with Kivy that directly support mobile application development in its first inception, Qt support in mobile development was gradually introduced.
Great. What are you waiting for? Lets go!
A Gentle Introduction to Qt, PyQt and PySide
Although in this blog I haven't officially talked about cross platform GUI toolkit for Python, the truth is, I have already show you how use TkInter (which is one in many libraries in doing cross platform GUI application using Python) in this article. Needless to say, trying to elaborately explained all of the existing GUI toolkit libraries and then choosing one of them as the center of discussion/talk/tutorial, may start a discussion that lead to a flame war : all GUI toolkits have their own loyal fans. For example, as I am going to focus my discussion on Qt, Linux users may aware of its legendary rival : GTK+. Now, for those who would like to know its head to head comparison, you may headed to this WikiVs article. There you go. I just cleaned my hand..
Qt is a C++ application framework brand and product that have its trademark being transferred from Trolltech (its original founder), to Nokia (greatly define path for Qt in mobile application development) and finally to Digia (continuing development lead, support and maintaining commercial license for Qt). Interesting thing about Qt is, even though it started as a proprietary product by Trolltech, throughout its epic development history, finally it became an Open Source LGPL product. The development of Qt is not in a closed manner inside Digia lab, but in an open governance mechanism coordinated by Qt Project. Everyone is invited to join in the Qt development!
You may wonder, "What do Python got to do with a C++ application framework?" To make the answer short : this is largely because PyQt, which is the work of of Phil Thompson starting in the late '90s, that open the door for Python developers to use Qt in their application development. It create an enormous possibility for Python developer to use Qt in much more pythonic way. Using Phil Thompson own words in foreword of the book Rapid GUI Programming with Python and Qt : "My primary goal has always been to allow Python and Qt to work together in a way that feels natural to Python programmers, while allowing them to do anything they want in Python that can be done in C++. The key to achieving this was the development of SIP". Eventually PyQt become the major product of Phil Thompson founded software consultation firm, Riverbankcomputing.
Until mid 2009, PyQt was the sole product for Python binding for Qt. This sole domination was somewhat challenged by Nokia (at that time was still owned Qt trademark) when it released PySide, which is also a Python binding for Qt. "Two product with exactly the same purpose? Why?", you may wonder. It's true. The reason is, because Nokia and the developer at Riverbankcomputing failed to reach an agreement to include LGPL in PyQt license. This means, without commercial PyQt license, you'll have to make your application that use PyQt to be also GPLed (in simple term, you must make your application source code available to the rest of the world). Up until now, Python developer who tried to use Qt in their application will be faced with two options : PyQt or PySide? The good news is, both were having (almost) the same level of compatibility in its Python level, which means Python developer can switch to use either PyQt or PySide in their application development, with little or no modifications.
The Edge of Changes
For those who would love to develop Python application that leverage Qt, will realize that we are somewhat standing in the bleeding edge of three changes :
- Python itself was undergo changes from Python 2 to Python 3. Throughout its development history, Python 3 is the only release that is not backward compatible. This means application that developed using Python 2.x is not guaranteed to work in Python 3. With a large base of applications, frameworks, libraries and utilities still being developed using Python 2.x, this will somewhat make Python community hesitate to move forward to Python 3.x. You will find a lot of popular libraries simply said that it currently didn't support Python 3.
Although PyQt already support Qt 5 (many thanks for this!), it dropped support for Python 2.7. Phil would like us to move forward to Python 3. What about PySide? Frankly, the current release of PySide not yet supporting Qt 5. According to PySide roadmap, "Further down the road (but not that far) is improving things at the C++ level and working on supporting qt5". Well, I believe we haven't got that support established then!
So, what's the best decision for the current state of changes in Python, Qt and PyQt/PySide? I will give a standard (and safe) answer, "It greatly depends on your application requirement or needs", or even on your boss! If however we are in the state of exploring things (like me in this blog), well, let just explore all of them and see whether interoperability, compatibility or even porting tools exists for either choices.
To make things even better, we are not restricting our exploration in Python only. We will also have a look on how it's done in its C++ counterpart. Using my personal opinion, I really love to have a holistic view for all ways, before choosing one way that will fit to the current application requirement.This will make my understanding better and thorough.
Installing Qt, PyQt and PySide
At the moment, I love working on Windows, with several occasion revert to Linux / Mac OS X when necessary. Therefore, for installation of this technologies, I am going to use its official download page (not using either apt, yum, brew, MacPorts, etc), listed below:
Download Qt 4 or Qt 5 from this download page. This is required if you like to develop Qt using C++ language. If not, you can simply skip this download. Choose the one that match your operating system.
- If you want to use a great IDE for Python development in Windows, you can try to use Python Tools for Visual Studio. This is what I enjoyed to use in my current Python application development. Another solution exist of course, such as PyCharm. However, if you are about to develop Qt using C++, the Qt distribution already include QtCreator : a cross platform C++ IDE specifically designed to develop C++ Qt or Qt Quick application. With special simple configuration, it can also be use to develop non-Qt C++ application.
Downloading the above prerequisites will somewhat take a helluva time. So, grab a coffee..Or beer. I never tried beer though..
This article should be regarded as a general introduction to Qt, PyQt and PySide. Moreover, I also laid out the current situation and condition of doing Qt development in Python using either PyQt or PySide. We will gradually increased our exploration in the next few articles starting from the development of a useful Desktop application (I am thinking of an application that fall in the category of productivity application) until the development of a Qt/PyQt/PySide mobile application (I am thinking of developing an alphabet match maker game for my kids).
By completing this article and installing the required tools, I assume that you have the interest and curiosity to develop Qt/PyQt/PySide desktop or mobile application. In that case, stay tuned for my next articles regarding this topic!
But my subsequent article will continue with the exploration of an education Kivy application though. Sorry..