]>
Commit | Line | Data |
---|---|---|
1 | #---------------------------------------------------------------------------- | |
2 | # Name: wxPython.lib.mixins.listctrl | |
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 | ||
13 | from wxPython.wx import * | |
14 | ||
15 | #---------------------------------------------------------------------------- | |
16 | ||
17 | class MagicImageList: | |
18 | ''' | |
19 | Mix-in to provide "magic" growing image lists | |
20 | By Mike Fletcher | |
21 | ''' | |
22 | ||
23 | ### LAZYTREE and LISTCONTROL Methods | |
24 | DEFAULTICONSIZE = 16 | |
25 | ||
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 = {} | |
30 | self.SetImageList ( | |
31 | self.__magicImageList, { | |
32 | 16:wxIMAGE_LIST_SMALL, | |
33 | 32:wxIMAGE_LIST_NORMAL, | |
34 | }[self.__size] | |
35 | ) | |
36 | for image in images: | |
37 | self.AddIcon (image) | |
38 | ||
39 | def GetIcons (self, node): | |
40 | '''Get icon indexes for a given node, or None if no associated icon''' | |
41 | icon = self.GetIcon( node ) | |
42 | if icon: | |
43 | index = self.AddIcon (icon) | |
44 | return index, index | |
45 | return None | |
46 | ||
47 | ||
48 | ### Local methods... | |
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)) | |
52 | if index is None: | |
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 ) | |
58 | else: | |
59 | index = self.__magicImageList.Add( icon, mask ) | |
60 | else: | |
61 | raise ValueError("Unexpected icon object %s, " | |
62 | "expected wxIcon or wxBitmap" % (icon)) | |
63 | self.__magicImageListMapping [id (icon)] = index | |
64 | return index | |
65 | ||
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 | |
71 | ||
72 | ||
73 |