[PyQt] uic regression in PyQt4 4.7.7
Lorenzo Berni
duplo at develer.com
Thu Sep 30 17:53:22 BST 2010
Hi all.
I'm working on a PyQt-based application. I decided to load ui files dynamically using uic.loadUi function and it just worked since my last PyQt4 upgrade (I was using PyQt4 4.7.3). With 4.7.7 I notice the following error while attempting to load a ui file:
...
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/__init__.py", line 181, in loadUi
return DynamicUILoader().loadUi(uifile, baseinstance)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/Loader/loader.py", line 24, in loadUi
return self.parse(filename, QtCore.QFileInfo(filename).path())
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 842, in parse
actor(elem)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 689, in createUserInterface
self.traverseWidgetTree(elem)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 667, in traverseWidgetTree
handler(self, child)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 403, in createLayout
self.traverseWidgetTree(elem)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 667, in traverseWidgetTree
handler(self, child)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 446, in handleItem
self.traverseWidgetTree(elem)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 667, in traverseWidgetTree
handler(self, child)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 403, in createLayout
self.traverseWidgetTree(elem)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 667, in traverseWidgetTree
handler(self, child)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 446, in handleItem
self.traverseWidgetTree(elem)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 667, in traverseWidgetTree
handler(self, child)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 163, in createWidget
self.stack.push(self.setupObject(widgetClass(elem), parent, elem))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/uiparser.py", line 136, in setupObject
self.wprops.setProperties(obj, branch)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/properties.py", line 365, in setProperties
prop_value = self.convert(prop, widget)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/properties.py", line 330, in convert
return func(prop[0], **args)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/properties.py", line 158, in _iconset
return self.icon_cache.get_icon(prop)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/icon_cache.py", line 30, in get_icon
iset = _IconSet(iconset, self._base_dir)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/icon_cache.py", line 63, in __init__
self._fallback = self._file_name(iconset.text, base_dir)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyQt4/uic/icon_cache.py", line 87, in _file_name
fname = os.path.join(base_dir, fname)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/posixpath.py", line 67, in join
elif path == '' or path.endswith('/'):
AttributeError: 'QString' object has no attribute 'endswith'
(on my mac)
and:
...
File "C:\Python26\lib\site-packages\PyQt4\uic\__init__.py", line 181, in loadUi
return DynamicUILoader().loadUi(uifile, baseinstance)
File "C:\Python26\lib\site-packages\PyQt4\uic\Loader\loader.py", line 25, in loadUi
return self.parse(filename, QtCore.QFileInfo(filename).path())
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 843, in parse
actor(elem)
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 689, in createUserInterface
self.traverseWidgetTree(elem)
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 667, in traverseWidgetTree
handler(self, child)
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 403, in createLayout
self.traverseWidgetTree(elem)
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 667, in traverseWidgetTree
handler(self, child)
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 446, in handleItem
self.traverseWidgetTree(elem)
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 667, in traverseWidgetTree
handler(self, child)
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 403, in createLayout
self.traverseWidgetTree(elem)
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 667, in traverseWidgetTree
handler(self, child)
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 446, in handleItem
self.traverseWidgetTree(elem)
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 667, in traverseWidgetTree
handler(self, child)
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 163, in createWidget
self.stack.push(self.setupObject(widgetClass(elem), parent, elem))
File "C:\Python26\lib\site-packages\PyQt4\uic\uiparser.py", line 136, in setupObject
self.wprops.setProperties(obj, branch)
File "C:\Python26\lib\site-packages\PyQt4\uic\properties.py", line 365, in setProperties
prop_value = self.convert(prop, widget)
File "C:\Python26\lib\site-packages\PyQt4\uic\properties.py", line 330, in convert
return func(prop[0], **args)
File "C:\Python26\lib\site-packages\PyQt4\uic\properties.py", line 158, in _iconset
return self.icon_cache.get_icon(prop)
File "C:\Python26\lib\site-packages\PyQt4\uic\icon_cache.py", line 30, in get_icon
iset = _IconSet(iconset, self._base_dir)
File "C:\Python26\lib\site-packages\PyQt4\uic\icon_cache.py", line 63, in __init__
self._fallback = self._file_name(iconset.text, base_dir)
File "C:\Python26\lib\site-packages\PyQt4\uic\icon_cache.py", line 87, in _file_name
fname = os.path.join(base_dir, fname)
File "C:\Python26\lib\ntpath.py", line 97, in join
if path[-1] in "/\\":
TypeError: 'in <string>' requires string as left operand, not QString
(on Windows XP virtual machine)
They're different errors but probably both of them are cause by the following code lines (from PyQt4.uic.Loader.loader):
...
def loadUi(self, filename, toplevelInst=None):
self.toplevelInst = toplevelInst
# By using QFileInfo.path() rather than os.path.dirname() we allow
# QString file names.
return self.parse(filename, QtCore.QFileInfo(filename).path())
In 4.7.3 there was only a parameter into the parse method, but in this new version, the second parameter (a QString) is used for various operations related to os.path python standard module (that require str).
In my case, replace the last row with the following, just works:
return self.parse(filename, unicode(QtCore.QFileInfo(filename).path()))
I don't know if this can break other parts of uic. Tell me if I'm doing something wrong :)
--
Lorenzo Berni, Develer s.r.l. - R&D team
[ http://www.develer.it - http://www.bertos.org ]
More information about the PyQt
mailing list