Python GUI Programming With PySide
Python GUI Programming With PySide
Why Qt / PySide?
Pros:
Its NOT MFC style. Easy to build up by QtDesigner or text coding. Intuitive SIGNAL / SLOT mechanism. Supports I18N. (Internationalization) LGPL. (GNU Lesser General Public License) The API is more Pythonic.
Cons:
Qt is not written in standard C++ library. Application size is big. blabla
Before Starting
Install Python (What?!)
http://www.python.org/download User should note the compatibility between version 2.7.x and 3.x.
Install Qt
http://qt-project.org/downloads The latest version is 5.0. (Its too new for me... =.=)
Install PySide
http://qt-project.org/wiki/PySideDownloads Current version is 1.1.2, but most references on web is for 1.0.7.
A Simple Program
test.py
object oriented programming styles
Just so easy!
QLayout and QWidget are the most basic classes that make up your GUI.
QLayout
In fact, you dont need to start from QLayout itself. There are many pre-designed layout. Use them directly should be enough.
QHBoxLayout
QGridLayout
QVBoxLayout
QFormLayout
QWidget
Example
SIGNAL / SLOT
self.btn1.clicked.connect(self.typebig)
The advantage of SIGNAL / SLOT is the caller does not have to know anything about the receiver and vice versa. Any function could be a SLOT. One can connect several SLOT to a SIGNAL and vice versa.
Exercise
Try to modify the simple program to MD5 Encrypter.
Exercise (contd)
You need import hashlib first
Something To Be Continued
Decorations:
Take advantages of groups, tabs, tooltips, , etc. Add some icons, sounds or visual effects.
Maintains:
Debug, debug and debug.
CurveExpert (PyInstaller)
Packing/Release:
PyInstaller - Cross platform cx_Freeze - Cross platform py2exe - Window only
BitTorrent (py2exe)
Summary
GUI programming could help you interactively control the application and report visualized final data. Every programmer should familiar with its basic concept. Programming in PySide = Programming in OOP. All components in library can be easily adapted and modified. Try to use them as much as possible. There are many splendid functions like graphics, animation, drag & drop, etc. for GUI programming. You can improve the user experience by these, but remember to pay more attention on the performance of your application.
References
http://zh.wikipedia.org/wiki/Qt http://qt-project.org/wiki/PySide http://matplotlib.org http://www.scipy.org http://www.vtk.org http://www.pyinstaller.org http://cx-freeze.sourceforge.net http://www.py2exe.org