]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/mixins/imagelist.py
src/common/wxchar.cpps/wxConvLocal/wxConvLibs/g as otherwise we may fail to convert...
[wxWidgets.git] / wxPython / wx / lib / mixins / imagelist.py
1 #----------------------------------------------------------------------------
2 # Name: wx.lib.mixins.imagelist
3 # Purpose: Helpful mix-in classes for using a wxImageList
4 #
5 # Author: Robin Dunn
6 #
7 # Created: 15-May-2001
8 # RCS-ID: $Id$
9 # Copyright: (c) 2001 by Total Control Software
10 # Licence: wxWindows license
11 #----------------------------------------------------------------------------
12 # 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
13 #
14 # o 2.5 compatability update.
15 # o Untested.
16 #
17
18 import wx
19
20 #----------------------------------------------------------------------------
21
22 class MagicImageList:
23 '''
24 Mix-in to provide "magic" growing image lists
25 By Mike Fletcher
26 '''
27
28 ### LAZYTREE and LISTCONTROL Methods
29 DEFAULTICONSIZE = 16
30
31 def SetupIcons(self, images=(), size=None):
32 self.__size = size or self.DEFAULTICONSIZE
33 self.__magicImageList = wx.ImageList (self.__size,self.__size)
34 self.__magicImageListMapping = {}
35 self.SetImageList (
36 self.__magicImageList, {
37 16:wx.IMAGE_LIST_SMALL,
38 32:wx.IMAGE_LIST_NORMAL,
39 }[self.__size]
40 )
41 for image in images:
42 self.AddIcon (image)
43
44 def GetIcons (self, node):
45 '''Get icon indexes for a given node, or None if no associated icon'''
46 icon = self.GetIcon( node )
47 if icon:
48 index = self.AddIcon (icon)
49 return index, index
50 return None
51
52
53 ### Local methods...
54 def AddIcon(self, icon, mask = wx.NullBitmap):
55 '''Add an icon to the image list, or get the index if already there'''
56 index = self.__magicImageListMapping.get (id (icon))
57 if index is None:
58 if isinstance( icon, wxIconPtr ):
59 index = self.__magicImageList.AddIcon( icon )
60 elif isinstance( icon, wx.BitmapPtr ):
61 if isinstance( mask, wx.Colour ):
62 index = self.__magicImageList.AddWithColourMask( icon, mask )
63 else:
64 index = self.__magicImageList.Add( icon, mask )
65 else:
66 raise ValueError("Unexpected icon object %s, "
67 "expected wx.Icon or wx.Bitmap" % (icon))
68 self.__magicImageListMapping [id (icon)] = index
69 return index
70
71 ### Customisation point...
72 def GetIcon( self, node ):
73 '''Get the actual icon object for a node'''
74 if hasattr (node,"DIAGRAMICON"):
75 return node.DIAGRAMICON
76
77
78