]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/art/img2pyartprov.py
Patch from Andrea that fixes the following problems/issues:
[wxWidgets.git] / wxPython / wx / lib / art / img2pyartprov.py
1 #-----------------------------------------------------------------------------
2 # Name: img2pyartprov.py
3 # Purpose:
4 #
5 # Author: Riaan Booysen
6 #
7 # RCS-ID: $Id$
8 # Copyright: (c) 2006
9 # Licence: wxPython
10 #-----------------------------------------------------------------------------
11 """ ArtProvider class that publishes images from modules generated by img2py.
12
13 Image modules must be generated with the -u and -n <name> parameters.
14
15 Typical usage:
16 >>> import wx, wx.lib.art.img2pyartprov, myimagemodule
17 >>> wx.ArtProvider.PushProvider(wx.lib.art.img2pyartprov.Img2PyArtProvider(myimagemodule))
18
19 If myimagemodule.catalog['MYIMAGE'] is defined, it can be accessed as:
20 >>> wx.ArtProvider.GetBitmap('wxART_MYIMAGE')
21
22 """
23
24 import wx
25
26 _NULL_BMP = wx.NullBitmap
27 class Img2PyArtProvider(wx.ArtProvider):
28 def __init__(self, imageModule, artIdPrefix='wxART_'):
29 self.catalog = {}
30 self.index = []
31 self.UpdateFromImageModule(imageModule)
32 self.artIdPrefix = artIdPrefix
33
34 wx.ArtProvider.__init__(self)
35
36 def UpdateFromImageModule(self, imageModule):
37 try:
38 self.catalog.update(imageModule.catalog)
39 except AttributeError:
40 raise Exception, 'No catalog dictionary defined for the image module'
41
42 try:
43 self.index.extend(imageModule.index)
44 except AttributeError:
45 raise Exception, 'No index list defined for the image module'
46
47 def GenerateArtIdList(self):
48 return [self.artIdPrefix+name for name in self.index]
49
50 def CreateBitmap(self, artId, artClient, size):
51 if artId.startswith(self.artIdPrefix):
52 name = artId[len(self.artIdPrefix):]
53 if name in self.catalog:
54 return self.catalog[name].getBitmap()
55
56 return _NULL_BMP
57
58