]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-12/draw_image.py
   1 # This one shows how to draw images on a DC. 
   7 class RandomImagePlacementWindow(wx
.Window
): 
   8     def __init__(self
, parent
, image
): 
   9         wx
.Window
.__init
__(self
, parent
) 
  10         self
.photo 
= image
.ConvertToBitmap() 
  12         # choose some random positions to draw the image at: 
  13         self
.positions 
= [(10,10)] 
  15             x 
= random
.randint(0, 1000) 
  16             y 
= random
.randint(0, 1000) 
  17             self
.positions
.append( (x
,y
) ) 
  19         # Bind the Paint event 
  20         self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
) 
  23     def OnPaint(self
, evt
): 
  24         # create and clear the DC 
  26         brush 
= wx
.Brush("sky blue") 
  27         dc
.SetBackground(brush
) 
  30         # draw the image in random locations 
  31         for x
,y 
in self
.positions
: 
  32             dc
.DrawBitmap(self
.photo
, x
, y
, True) 
  35 class TestFrame(wx
.Frame
): 
  37         wx
.Frame
.__init
__(self
, None, title
="Loading Images", 
  39         img 
= wx
.Image("masked-portrait.png") 
  40         win 
= RandomImagePlacementWindow(self
, img
) 
  43 app 
= wx
.PySimpleApp()