Example By: justin
Few days back I updated the look of my Batch Render standalone application I made in PyQt. All I had to do is just add new stylesheet, since I had the stylesheet written in external file, I wanted it to load and apply. So at the beginning I knew that self.styleSheet(..) takes the stylesheet content as string that is always end up multiline, so instead of adding it within Python module within the triple commas string, this is what I did 1: styleFile=os.path.join(os.path.split(__file__)[0],"darkorange.stylesheet") 2: with open(styleFile,"r") as fh: 3: self.setStyleSheet(fh.read()) Today I spent hell lot of time understanding the clear difference between LGPL and GPL, and more importantly the difference between PySide & PyQt in terms of what to choose for learning and developing tools. however the later one needs still needs to be explored a bit more. But as far as beginner for GUI development using Qt is concerned I think this consideration should not be important. Since atleast both PyQt4 and PySide does use Qt API 2. However if you want to make a tool and sell it and at the same time you cannot afford to pay 350 pounds for PyQt4 commercial licence, to my understanding use PySide that is being distributed under LGPL.
There's basically three pivot points that I think about when it comes to PyQt vs. PySide. Longevity:
Both PyQt4 and PySide have very similar mappings to the Qt API. There are, however, some differences, my opinions on which are described below: I also found a good answer by guy name Alan to someone looking for similar question in mind on askUbuntu.com. I would repost here for my reference. 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.QStrings 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 The QtVariant.py that I use looks like this: 1: import sys 2: import os 3: 4: default_variant = 'PySide' 5: 6: env_api = os.environ.get('QT_API', 'pyqt') 7: if '--pyside' in sys.argv: 8: variant = 'PySide' 9: elif '--pyqt4' in sys.argv: 10: variant = 'PyQt4' 11: elif env_api == 'pyside': 12: variant = 'PySide' 13: elif env_api == 'pyqt': 14: variant = 'PyQt4' 15: else: 16: variant = default_variant 17: 18: if variant == 'PySide': 19: from PySide import QtGui, QtCore 20: # This will be passed on to new versions of matplotlib 21: os.environ['QT_API'] = 'pyside' 22: def QtLoadUI(uifile): 23: from PySide import QtUiTools 24: loader = QtUiTools.QUiLoader() 25: uif = QtCore.QFile(uifile) 26: uif.open(QtCore.QFile.ReadOnly) 27: result = loader.load(uif) 28: uif.close() 29: return result 30: elif variant == 'PyQt4': 31: import sip 32: api2_classes = [ 33: 'QData', 'QDateTime', 'QString', 'QTextStream', 34: 'QTime', 'QUrl', 'QVariant', 35: ] 36: for cl in api2_classes: 37: sip.setapi(cl, 2) 38: from PyQt4 import QtGui, QtCore 39: QtCore.Signal = QtCore.pyqtSignal 40: QtCore.QString = str 41: os.environ['QT_API'] = 'pyqt' 42: def QtLoadUI(uifile): 43: from PyQt4 import uic 44: return uic.loadUi(uifile) 45: else: 46: raise ImportError("Python Variant not specified") 47: 48: __all__ = [QtGui, QtCore, QtLoadUI, variant] So by the year end 2012, I am done with my new reel for the post of technical artist job profile. The showreel showcases my skills in python and pyqt4. In this video I choose to showcase 3 tools that I made recently in python. 1.Pose It: Pose Manager for Autodesk Maya can run as docked or as floating window made can display thumbnail of stored poses. 2. Mini Me: Maya Project manager that lets the maya artist access files and folder from within maya without having to switch to Explorer or finder set favorite projects, fix file texture paths, email scene or selected file or upload to ftp and even perform incremental save. (both 1. Pose manager & Project manager has multi platform compatibility i.e on mac, linux and Windows) 3. Batch Renderer for Autodesk Maya and Foundry Nuke performs batch render, what unique you might find it reads the ma, mb or nk file for the setting set by the artist for rendering and this reduces the chance of a mistake of entering wrong values manually. you can also choose the render camera in case of may from dropdown similarly choose write node in case of Nuke while doing render setup. I have written plenty of other tools that can be viewed on Creative crash website here: goo.gl/xCljF So today I finished my first PyQt4 Pyhon application that allows user to perform batch render maya and nuke files, without having to open the respective application. I started on 7th and had 2 days break as I had to go out of town. However, its overwhelming to me as I finished each and every functionality I thought of . I didn't really planned in logical order for its development having the knowledge of the process of batch rendering in maya and nuke. I decided to go go for it based on requirement. One useful thing you might find, I implemented it as soon as we browse for the maya scene or nuke script the settings are loaded in the GUI so that chances of mistakenly entering the wrong values is reduced since the artist will have some settings saved in the file. Have a look at how it function. I have made this app, to showcase my pythonic skills in PyQt4. 16/12 : I just updated the GUI using styleSheet & converted png images to resource files. As soon as I am done with my showreel I will release the code and a standalone executable on my website and my creative crash downloads page. |
Custom Search
Other Blogs & PagesGit Commands Animation & VFX SitesA MUST READ for Ani/VFX Artistsawakened by thoughts,
|