]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/lib/mixins/imagelist.py
Fix "warning: operation on 'y' may be undefined".
[wxWidgets.git] / wxPython / wx / lib / mixins / imagelist.py
CommitLineData
d14a1e28 1#----------------------------------------------------------------------------
b881fc78 2# Name: wx.lib.mixins.imagelist
d14a1e28
RD
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#----------------------------------------------------------------------------
b881fc78
RD
12# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
13#
14# o 2.5 compatability update.
15# o Untested.
16#
d14a1e28 17
b881fc78 18import wx
d14a1e28
RD
19
20#----------------------------------------------------------------------------
21
22class 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
b881fc78 33 self.__magicImageList = wx.ImageList (self.__size,self.__size)
d14a1e28
RD
34 self.__magicImageListMapping = {}
35 self.SetImageList (
36 self.__magicImageList, {
b881fc78
RD
37 16:wx.IMAGE_LIST_SMALL,
38 32:wx.IMAGE_LIST_NORMAL,
d14a1e28
RD
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...
b881fc78 54 def AddIcon(self, icon, mask = wx.NullBitmap):
d14a1e28
RD
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 )
b881fc78
RD
60 elif isinstance( icon, wx.BitmapPtr ):
61 if isinstance( mask, wx.Colour ):
d14a1e28
RD
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, "
b881fc78 67 "expected wx.Icon or wx.Bitmap" % (icon))
d14a1e28
RD
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
1fded56b 77
1fded56b 78