[Pypersyst-cvs] pypersyst/pypersyst/ui/qt iconcache.py,NONE,1.1 action.py,1.5,1.6 collection.py,1.33
Brought to you by:
pobrien
From: Matthew R. S. <gld...@us...> - 2004-08-10 21:49:44
|
Update of /cvsroot/pypersyst/pypersyst/pypersyst/ui/qt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7383/pypersyst/ui/qt Modified Files: action.py collection.py field.py Added Files: iconcache.py Log Message: Iconset caching. --- NEW FILE: iconcache.py --- """Cache of iconsets for objects.""" import weakref import qt _cache = weakref.WeakKeyDictionary() def iconset(domain, ob): if domain in _cache: iconCache = _cache[domain] else: iconCache = weakref.WeakKeyDictionary() _cache[domain] = iconCache if ob in iconCache: iconSet = iconCache[ob] else: icon = domain.IIcon(ob, None) iconSet = qt.QIconSet() if icon is not None: image = qt.QImage() image.loadFromData(icon) iconSet.setPixmap(qt.QPixmap(image), iconSet.Automatic) iconCache[ob] = iconSet return iconSet def largePixmap(domain, ob): iconSet = iconset(domain, ob) return iconSet.pixmap(iconSet.Large, iconSet.Normal) def smallPixmap(domain, ob): iconSet = iconset(domain, ob) return iconSet.pixmap(iconSet.Small, iconSet.Normal) Index: field.py =================================================================== RCS file: /cvsroot/pypersyst/pypersyst/pypersyst/ui/qt/field.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** field.py 10 Aug 2004 20:14:23 -0000 1.5 --- field.py 10 Aug 2004 21:49:33 -0000 1.6 *************** *** 10,13 **** --- 10,14 ---- from pypersyst.field import field as pfield + from pypersyst.ui.qt import iconcache from pypersyst.ui.qt import interface from pypersyst.ui.qt.image.image import uic_findImage as image *************** *** 259,264 **** except: pass ! icon = domain.IIcon(display.collection, None) ! values.append((label, icon, display)) values.sort() if self.field.allowNone: --- 260,265 ---- except: pass ! pixmap = iconcache.smallPixmap(domain, display.collection) ! values.append((label, pixmap, display)) values.sort() if self.field.allowNone: *************** *** 269,280 **** self.clear() index = 0 ! for label, icon, value in values: ! if icon is not None: ! iconSet = qt.QIconSet() ! image = qt.QImage() ! image.loadFromData(icon) ! iconSet.setPixmap(qt.QPixmap(image), iconSet.Automatic) ! self.insertItem(iconSet.pixmap(iconSet.Small, iconSet.Normal), ! label) else: self.insertItem(label) --- 270,276 ---- self.clear() index = 0 ! for label, pixmap, value in values: ! if pixmap is not None: ! self.insertItem(pixmap, label) else: self.insertItem(label) Index: action.py =================================================================== RCS file: /cvsroot/pypersyst/pypersyst/pypersyst/ui/qt/action.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** action.py 10 Aug 2004 19:30:21 -0000 1.5 --- action.py 10 Aug 2004 21:49:30 -0000 1.6 *************** *** 4,7 **** --- 4,8 ---- from pypersyst.ui.qt.autoconnector import AutoConnector + from pypersyst.ui.qt import iconcache from pypersyst.ui.qt import signal *************** *** 99,108 **** menu.insertSeparator() for actionlabel, action in actions: ! iconSet = qt.QIconSet() ! icon = domain.IIcon(action, None) ! if icon is not None: ! image = qt.QImage() ! image.loadFromData(icon) ! iconSet.setPixmap(qt.QPixmap(image), iconSet.Automatic) qAction = qt.QAction(iconSet, '&' + actionlabel, qt.QKeySequence(), parent) --- 100,104 ---- menu.insertSeparator() for actionlabel, action in actions: ! iconSet = iconcache.iconset(domain, action) qAction = qt.QAction(iconSet, '&' + actionlabel, qt.QKeySequence(), parent) *************** *** 136,145 **** buttons = [] for actionlabel, action in domain.actions(item): ! iconSet = qt.QIconSet() ! icon = domain.IIcon(action, None) ! if icon is not None: ! image = qt.QImage() ! image.loadFromData(icon) ! iconSet.setPixmap(qt.QPixmap(image), iconSet.Automatic) button = buttonClass(parent) button.setText(actionlabel) --- 132,136 ---- buttons = [] for actionlabel, action in domain.actions(item): ! iconSet = iconcache.iconset(domain, action) button = buttonClass(parent) button.setText(actionlabel) Index: collection.py =================================================================== RCS file: /cvsroot/pypersyst/pypersyst/pypersyst/ui/qt/collection.py,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** collection.py 10 Aug 2004 19:46:26 -0000 1.33 --- collection.py 10 Aug 2004 21:49:33 -0000 1.34 *************** *** 14,17 **** --- 14,18 ---- from pypersyst.ui.qt.autoconnector import AutoConnector import pypersyst.ui.qt.dragdrop + from pypersyst.ui.qt import iconcache from pypersyst.ui.qt import interface from pypersyst.ui.qt import signal *************** *** 143,152 **** collection = payload.collection plural = domain.IPluralLabel(collection) ! iconSet = qt.QIconSet() ! icon = domain.IIcon(collection, None) ! if icon is not None: ! image = qt.QImage() ! image.loadFromData(icon) ! iconSet.setPixmap(qt.QPixmap(image), iconSet.Automatic) # Create a submenu if requested. submenu = None --- 144,148 ---- collection = payload.collection plural = domain.IPluralLabel(collection) ! iconSet = iconcache.iconset(domain, collection) # Create a submenu if requested. submenu = None *************** *** 540,549 **** domain = self._domain collection = payload.collection ! iconSet = qt.QIconSet() ! icon = domain.IIcon(collection, None) ! if icon is not None: ! image = qt.QImage() ! image.loadFromData(icon) ! iconSet.setPixmap(qt.QPixmap(image), iconSet.Automatic) # Create a widget to contain the action buttons. widget = qt.QWidget(self) --- 536,540 ---- domain = self._domain collection = payload.collection ! iconSet = iconcache.iconset(domain, collection) # Create a widget to contain the action buttons. widget = qt.QWidget(self) *************** *** 555,564 **** buttons = widget._buttons = [] for label, action in domain.actions(collection): ! iconSet = qt.QIconSet() ! icon = domain.IIcon(action, None) ! if icon is not None: ! image = qt.QImage() ! image.loadFromData(icon) ! iconSet.setPixmap(qt.QPixmap(image), iconSet.Automatic) button = qt.QToolButton(widget) button.setAutoRaise(True) --- 546,550 ---- buttons = widget._buttons = [] for label, action in domain.actions(collection): ! iconSet = iconcache.iconset(domain, action) button = qt.QToolButton(widget) button.setAutoRaise(True) *************** *** 956,963 **** --- 942,952 ---- def refreshData(self, data=None): """Refresh data shown by self to be current with latest revision.""" + domain = self._domain + collection = self._collection if data is None: data = self.supplier().data listView = self.listView() values = self._values = [] + pixmaps = self._pixmaps = [] for name, label in listView._colnames: if name == 'sys.oid': *************** *** 966,969 **** --- 955,959 ---- value = getattr(data, name) values.append(value) + pixmaps.append(value) def supplier(self): *************** *** 974,980 **** """Return the text that should show for this column.""" listView = self.listView() ! value = self._values[col] ! value = self._domain.ILabel(value, value) ! return str(value) --- 964,977 ---- """Return the text that should show for this column.""" listView = self.listView() ! if col == 0: ! # Don't actually show the OID. ! # ! # XXX: Make sure that this can be overridden in the case ! # of someone wanting to debug. Or not. :-) ! return '' ! else: ! value = self._values[col] ! value = self._domain.ILabel(value, value) ! return str(value) |