Hi,

I like both the one-argument version and the mapping interface ideas. The API should've been like the one-argument version from the beginning, but now that the C++ style version is out there, I guess both styles need to be supported...

Maybe you could file enhancement bugs for these suggestions so that they won't be forgotten?

Cheers,

ma.

On 02.04.2011 19:13, ext Petr Viktorin wrote:
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

_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside

Reply via email to