]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/mixins/imagelist.py
1 #----------------------------------------------------------------------------
2 # Name: wxPython.lib.mixins.listctrl
3 # Purpose: Helpful mix-in classes for using a wxImageList
9 # Copyright: (c) 2001 by Total Control Software
10 # Licence: wxWindows license
11 #----------------------------------------------------------------------------
13 from wxPython
.wx
import *
15 #----------------------------------------------------------------------------
19 Mix-in to provide "magic" growing image lists
23 ### LAZYTREE and LISTCONTROL Methods
26 def SetupIcons(self
, images
=(), size
=None):
27 self
.__size
= size
or self
.DEFAULTICONSIZE
28 self
.__magicImageList
= wxImageList (self
.__size
,self
.__size
)
29 self
.__magicImageListMapping
= {}
31 self
.__magicImageList
, {
32 16:wxIMAGE_LIST_SMALL
,
33 32:wxIMAGE_LIST_NORMAL
,
39 def GetIcons (self
, node
):
40 '''Get icon indexes for a given node, or None if no associated icon'''
41 icon
= self
.GetIcon( node
)
43 index
= self
.AddIcon (icon
)
49 def AddIcon(self
, icon
, mask
= wxNullBitmap
):
50 '''Add an icon to the image list, or get the index if already there'''
51 index
= self
.__magicImageListMapping
.get (id (icon
))
53 if isinstance( icon
, wxIconPtr
):
54 index
= self
.__magicImageList
.AddIcon( icon
)
55 elif isinstance( icon
, wxBitmapPtr
):
56 if isinstance( mask
, wxColour
):
57 index
= self
.__magicImageList
.AddWithColourMask( icon
, mask
)
59 index
= self
.__magicImageList
.Add( icon
, mask
)
61 raise ValueError("Unexpected icon object %s, "
62 "expected wxIcon or wxBitmap" % (icon
))
63 self
.__magicImageListMapping
[id (icon
)] = index
66 ### Customisation point...
67 def GetIcon( self
, node
):
68 '''Get the actual icon object for a node'''
69 if hasattr (node
,"DIAGRAMICON"):
70 return node
.DIAGRAMICON