> Message: 1
> Date: Mon, 04 Apr 2011 12:46:57 +0300
> From: Matti Airas <[email protected]>
> To: [email protected]
> Subject: Re: [PySide] A more pythonic QPixmapCache
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hi,
>
> I like both the one-argument version and the mapping interface ideas.
To clarify, I meant the ideas as alternatives. There should be one way to do it;
if there are no problems with [] on a class, there's no need for one-arg find.
> 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?
>
Yes! I'm afraid I'll not have time learn Shiboken to write a patch,
but I'll definitely
file a bug once the discussion here dies a bit.
> 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
Petr Viktorin
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside