2003-11-12 16:34:20 -05:00
|
|
|
#----------------------------------------------------------------------------
|
2003-12-16 19:34:40 -05:00
|
|
|
# Name: wx.lib.mixins.imagelist
|
2003-11-12 16:34:20 -05:00
|
|
|
# Purpose: Helpful mix-in classes for using a wxImageList
|
|
|
|
#
|
|
|
|
# Author: Robin Dunn
|
|
|
|
#
|
|
|
|
# Created: 15-May-2001
|
|
|
|
# RCS-ID: $Id$
|
|
|
|
# Copyright: (c) 2001 by Total Control Software
|
|
|
|
# Licence: wxWindows license
|
|
|
|
#----------------------------------------------------------------------------
|
2003-12-16 19:34:40 -05:00
|
|
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o 2.5 compatability update.
|
|
|
|
# o Untested.
|
|
|
|
#
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
import wx
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class MagicImageList:
|
|
|
|
'''
|
|
|
|
Mix-in to provide "magic" growing image lists
|
|
|
|
By Mike Fletcher
|
|
|
|
'''
|
|
|
|
|
|
|
|
### LAZYTREE and LISTCONTROL Methods
|
|
|
|
DEFAULTICONSIZE = 16
|
|
|
|
|
|
|
|
def SetupIcons(self, images=(), size=None):
|
|
|
|
self.__size = size or self.DEFAULTICONSIZE
|
2003-12-16 19:34:40 -05:00
|
|
|
self.__magicImageList = wx.ImageList (self.__size,self.__size)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.__magicImageListMapping = {}
|
|
|
|
self.SetImageList (
|
|
|
|
self.__magicImageList, {
|
2003-12-16 19:34:40 -05:00
|
|
|
16:wx.IMAGE_LIST_SMALL,
|
|
|
|
32:wx.IMAGE_LIST_NORMAL,
|
2003-11-12 16:34:20 -05:00
|
|
|
}[self.__size]
|
|
|
|
)
|
|
|
|
for image in images:
|
|
|
|
self.AddIcon (image)
|
|
|
|
|
|
|
|
def GetIcons (self, node):
|
|
|
|
'''Get icon indexes for a given node, or None if no associated icon'''
|
|
|
|
icon = self.GetIcon( node )
|
|
|
|
if icon:
|
|
|
|
index = self.AddIcon (icon)
|
|
|
|
return index, index
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
### Local methods...
|
2003-12-16 19:34:40 -05:00
|
|
|
def AddIcon(self, icon, mask = wx.NullBitmap):
|
2003-11-12 16:34:20 -05:00
|
|
|
'''Add an icon to the image list, or get the index if already there'''
|
|
|
|
index = self.__magicImageListMapping.get (id (icon))
|
|
|
|
if index is None:
|
|
|
|
if isinstance( icon, wxIconPtr ):
|
|
|
|
index = self.__magicImageList.AddIcon( icon )
|
2003-12-16 19:34:40 -05:00
|
|
|
elif isinstance( icon, wx.BitmapPtr ):
|
|
|
|
if isinstance( mask, wx.Colour ):
|
2003-11-12 16:34:20 -05:00
|
|
|
index = self.__magicImageList.AddWithColourMask( icon, mask )
|
|
|
|
else:
|
|
|
|
index = self.__magicImageList.Add( icon, mask )
|
|
|
|
else:
|
|
|
|
raise ValueError("Unexpected icon object %s, "
|
2003-12-16 19:34:40 -05:00
|
|
|
"expected wx.Icon or wx.Bitmap" % (icon))
|
2003-11-12 16:34:20 -05:00
|
|
|
self.__magicImageListMapping [id (icon)] = index
|
|
|
|
return index
|
|
|
|
|
|
|
|
### Customisation point...
|
|
|
|
def GetIcon( self, node ):
|
|
|
|
'''Get the actual icon object for a node'''
|
|
|
|
if hasattr (node,"DIAGRAMICON"):
|
|
|
|
return node.DIAGRAMICON
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
|