]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/art/img2pyartprov.py
   1 #----------------------------------------------------------------------------- 
   2 # Name:        img2pyartprov.py 
   5 # Author:      Riaan Booysen 
  10 #----------------------------------------------------------------------------- 
  11 """ ArtProvider class that publishes images from modules generated by img2py. 
  13 Image modules must be generated with the -u and -n <name> parameters. 
  16 >>> import wx, wx.lib.art.img2pyartprov, myimagemodule 
  17 >>> wx.ArtProvider.PushProvider(wx.lib.art.img2pyartprov.Img2PyArtProvider(myimagemodule)) 
  19 If myimagemodule.catalog['MYIMAGE'] is defined, it can be accessed as: 
  20 >>> wx.ArtProvider.GetBitmap('wxART_MYIMAGE') 
  26 _NULL_BMP 
= wx
.NullBitmap
 
  27 class Img2PyArtProvider(wx
.ArtProvider
): 
  28     def __init__(self
, imageModule
, artIdPrefix
='wxART_'): 
  31         self
.UpdateFromImageModule(imageModule
) 
  32         self
.artIdPrefix 
= artIdPrefix
 
  34         wx
.ArtProvider
.__init
__(self
) 
  36     def UpdateFromImageModule(self
, imageModule
): 
  38             self
.catalog
.update(imageModule
.catalog
) 
  39         except AttributeError: 
  40             raise Exception, 'No catalog dictionary defined for the image module' 
  43             self
.index
.extend(imageModule
.index
) 
  44         except AttributeError: 
  45             raise Exception, 'No index list defined for the image module' 
  47     def GenerateArtIdList(self
): 
  48         return [self
.artIdPrefix
+name 
for name 
in self
.index
] 
  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()