Both PyQt4 and PySide have very similar mappings to the Qt API. There are, however, some differences, my opinions on which are described below:
Maintenance
They are both well maintained. The PySide produces a lot more regular releases at the moment: I think it's more closely linked to Qt than PyQt4 and as a newer project has a more active community at the moment. However, that is just my impression and it may be wrong.
PyQt4 has the option of commercial support available (I don't know whether this is true for PySide or not).
Licence
PyQt4 is released under either a commercial licence or the GPL; PySide is released under the LGPL. For commercial applications, this is a significant difference.
APIs and Python versions
PyQt4 supports two different APIs. API version 1 is the default for python 2.x applications and API version 2 is the default for python 3.x applications.
PySide only supports one API, which is roughly equivalent to PyQt4's API version 2. API version 2 (or the PySide API) is much nicer to work with than PyQt4's API version 1. In API version 1 you have a lot of code that casts python strings to QtCore.QString
s and back again. In API version 2 (and PySide) you just use python strings throughout. See below for a simple way of switching between PyQt4 and PySide if you want to play with both.
Most code I write seems to work equally well in PyQt4 and PySide. Historically, I had always used PyQt4 for python GUIs but most new stuff I write now uses PySide (mainly due to the more flexible licensing). I'd certainly recommend you try both and see how you find them. If you use QtVariant.py (below), switching between them is trivial and when you make a decision there will only be one file that needs updating.
Documentation
The documentation for both PyQt4 and PySide are auto-generated from the main Qt documentation. In my opinion, the PySide documentation is a better representation of what you actually use, but in practice I tend to just use the Qt documentation anyway (it's quite easy to mentally translate the C++ documentation to python).
External Libraries
If you're using external libraries, some do not work with PySide yet. There aren't many that you need to work with PySide to be honest, but a couple of years ago I wrote some code that used twisted (with the Qt reactor) and matplotlib and that forced me down the line of using PyQt4 rather than PySide. I think it's quite likely that these libraries will have been updated to support both by now, but I haven't checked.
Making Code work with either PyQt4 or PySide
Assuming you're using python 2.x, you can fairly easily make your code compatible with both PySide and PyQt4 by making a QtVariant.py and using:
from QtVariant import QtGui, QtCore
or whatever. The QtVariant.py that I use looks like this:
import sys
import os
default_variant = 'PySide'
env_api = os.environ.get('QT_API', 'pyqt')
if '--pyside' in sys.argv:
variant = 'PySide'
elif '--pyqt4' in sys.argv:
variant = 'PyQt4'
elif env_api == 'pyside':
variant = 'PySide'
elif env_api == 'pyqt':
variant = 'PyQt4'
else:
variant = default_variant
if variant == 'PySide':
from PySide import QtGui, QtCore
# This will be passed on to new versions of matplotlib
os.environ['QT_API'] = 'pyside'
def QtLoadUI(uifile):
from PySide import QtUiTools
loader = QtUiTools.QUiLoader()
uif = QtCore.QFile(uifile)
uif.open(QtCore.QFile.ReadOnly)
result = loader.load(uif)
uif.close()
return result
elif variant == 'PyQt4':
import sip
api2_classes = [
'QData', 'QDateTime', 'QString', 'QTextStream',
'QTime', 'QUrl', 'QVariant',
]
for cl in api2_classes:
sip.setapi(cl, 2)
from PyQt4 import QtGui, QtCore
QtCore.Signal = QtCore.pyqtSignal
QtCore.QString = str
os.environ['QT_API'] = 'pyqt'
def QtLoadUI(uifile):
from PyQt4 import uic
return uic.loadUi(uifile)
else:
raise ImportError("Python Variant not specified")
__all__ = [QtGui, QtCore, QtLoadUI, variant]
Best Answer
Getting started quickly, so to say
The easiest thing to do is to base your first template on an existing one, and modify it to your needs. After running the following command, you'll have an ubuntu-application-qt template based on the ubuntu-application original template. You'll find it on
/home/$USER/quickly-templates
, ready to modify to your heart's content:Background
Here are some resources that will help you:
IMPORT
statement from the Quickly template language to import a subset of commands from an existing template. Here's an example taken from the ubuntu-cli templateQuickly templates can be written in whatever language you want. They are just a set of commands in a directory, containing commands to copy images, documents and interacting with the user.
Adding a command is quite easy: just drop it into the root template directory (
data/templates
in the Quickly source tree, or in/usr/share/quickly/templates/
) and make it executable. Quickly will know by this way that the current file is a command that Quickly Core can launch.Consequently, if you need additional internal commands that can be launched only by your own commands, just create a subdirectory in your template and add it there.
There are also some helpers if you need those names when creating a new command:
And to load the project_name (see the blog post above on part 6):