]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/mixins/imagelist.py
   1 #---------------------------------------------------------------------------- 
   2 # Name:        wx.lib.mixins.imagelist 
   3 # Purpose:     Helpful mix-in classes for using a wxImageList 
   9 # Copyright:   (c) 2001 by Total Control Software 
  10 # Licence:     wxWindows license 
  11 #---------------------------------------------------------------------------- 
  12 # 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net) 
  14 # o 2.5 compatability update. 
  20 #---------------------------------------------------------------------------- 
  24     Mix-in to provide "magic" growing image lists 
  28     ### LAZYTREE and LISTCONTROL Methods 
  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 
= {} 
  36             self
.__magicImageList
, { 
  37                 16:wx
.IMAGE_LIST_SMALL
, 
  38                 32:wx
.IMAGE_LIST_NORMAL
, 
  44     def GetIcons (self
, node
): 
  45         '''Get icon indexes for a given node, or None if no associated icon''' 
  46         icon 
= self
.GetIcon( node 
) 
  48             index 
= self
.AddIcon (icon
) 
  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
)) 
  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 
) 
  64                     index 
= self
.__magicImageList
.Add( icon
, mask 
) 
  66                 raise ValueError("Unexpected icon object %s, " 
  67                                  "expected wx.Icon or wx.Bitmap" % (icon
)) 
  68             self
.__magicImageListMapping 
[id (icon
)] = index
 
  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