Hello!
As a follow-up from bug 794 [1], I have a proposal for a more pythonic
API for QPixmapCache.find [2].
Currently it takes a key and a QPixmap, loads the pixmap if it finds
it, and returns a bool indicating success.
pm = QPixmap()
if not QPixmapCache.find("my_big_image", pm):
pm.load("bigimage.png")
QPixmapCache.insert("my_big_image", pm)
painter.drawPixmap(0, 0, pm)
I think a better API would be taking a key only, and returning either
QPixmap or None.
pm = QPixmapCache.find("my_big_image")
if not pm:
pm = QPixmap("bigimage.png")
QPixmapCache.insert("my_big_image", pm)
painter.drawPixmap(0, 0, pm)
The current two-arg behavior can be kept for C++ (and backwards) compatibility.
Going even further, QPixmapCache could have a mapping interface.
(Using [] on a class does look a bit weird though):
try:
pm = QPixmapCache["my_big_image"]
except KeyError:
pm = QPixmapCache["my_big_image"] = QPixmap("bigimage.png")
painter.drawPixmap(0, 0, pm)
del QPixmapCache["my_big_image"] # for completeness
Using my proposed one-arg find(), this could even be done just with a
trivial Python class, although having it built-in would be more
convenient.
Does any of these sound like a good idea to you?
Petr Viktorin
[1] http://bugs.pyside.org/show_bug.cgi?id=794
[2]
http://www.pyside.org/docs/pyside/PySide/QtGui/QPixmapCache.html#PySide.QtGui.PySide.QtGui.QPixmapCache.find
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside