PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 821 - Mapping interface for QPixmapCache
: Mapping interface for QPixmapCache
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: PySide
: HEAD
: PC Linux
: P4 enhancement
Assigned To: Hugo Parente Lima
:
:
:
  Show dependency treegraph
 
Reported: 2011-04-10 02:11 EEST by Petr Viktorin
Modified: 2011-07-22 22:13 EEST (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Viktorin 2011-04-10 02:11:02 EEST
QPixmapCache should have a mapping interface instead of find(), insert() and
remove().

QPixmapCache.__getitem__(self, key)
Looks for a cached pixmap associated with the given key in the cache. If the
pixmap is found, it is returned; otherwise KeyError is raised.

QPixmapCache.__setitem__(self, key, pixmap)
Same as QPixmapCache.insert

QPixmapCache.__delitem__(self, key)
Same as QPixmapCache.remove

The mapping interface's __contains__, __iter__ and __len__ don't make much
sense for a cache (though __contains__ might be implemented for completeness).

The existing find(), insert() and remove() methods should be deprecated.

Usage example:

try:
    pm = QPixmapCache["my_big_image"]
except KeyError:
    pm = QPixmapCache["my_big_image"] = QPixmap("bigimage.png")
painter.drawPixmap(0, 0, pm)


Discussed in the mailing list thread statring with:
http://lists.pyside.org/pipermail/pyside/2011-April/002335.html
Comment 1 Hugo Parente Lima 2011-04-12 17:34:17 EEST
Prioritizing as P4, as it's just a small enhancement to QPixmapCache class to
provide features that already exists in this class.
Comment 2 Marcelo Lira 2011-05-19 20:40:50 EEST
We (the team, not me in the Royal Plural) liked the proposed solution very
much, nevertheless we decided not to implement it. The reason is that even
though we can add dictionary methods to the QPixmapCache, it would work for the
instance of a QPixmapCache and not be static as we need for this case.
Making the class work like a dictionary demands us to insert dictionary methods
into Shiboken.ObjectType, which would complicate things for every Shiboken
generated class that doesn't have anything to do with what we need for
QPixmapCache. If it was a common enough situation in other classes we certainly
would implement it there.
In summation, you design was just right, but the static requirement complicated
things.
Thanks for the help.

P.S.: In Python proper a "@staticmethod" decorator for the dictionary methods
would be enough, but in CPython the dictionary function is just an entry in a
struct.
Comment 3 Petr Viktorin 2011-05-19 21:22:29 EEST
My original proposal had a “less magic” alternative, a one-argument find():

http://lists.pyside.org/pipermail/pyside/2011-April/002335.html
> 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)

Would that still be wanted/possible? Should I file a new bug on this (or reopen
this one)?
Comment 4 Matti Airas 2011-05-26 11:18:07 EEST
(In reply to comment #3)

> Would that still be wanted/possible? Should I file a new bug on this (or reopen
> this one)?

Hi! I'm reopening this one so that your proposal won't be forgotten.
Comment 5 Hugo Parente Lima 2011-07-21 23:12:47 EEST
Ok, I did the “less magic” alternative, a one-argument find().

Fixed in commit:

pyside/0c2b68c9049980eaafb9fee77b2186837f00d843
Comment 6 renato filho 2011-07-22 22:13:00 EEST
release 1.0.5