]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-12/draw_image.py
don't use strlen() to verify the length of the string as it can contain embedded...
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-12 / draw_image.py
1 # This one shows how to draw images on a DC.
2
3 import wx
4 import random
5 random.seed()
6
7 class RandomImagePlacementWindow(wx.Window):
8 def __init__(self, parent, image):
9 wx.Window.__init__(self, parent)
10 self.photo = image.ConvertToBitmap()
11
12 # choose some random positions to draw the image at:
13 self.positions = [(10,10)]
14 for x in range(50):
15 x = random.randint(0, 1000)
16 y = random.randint(0, 1000)
17 self.positions.append( (x,y) )
18
19 # Bind the Paint event
20 self.Bind(wx.EVT_PAINT, self.OnPaint)
21
22
23 def OnPaint(self, evt):
24 # create and clear the DC
25 dc = wx.PaintDC(self)
26 brush = wx.Brush("sky blue")
27 dc.SetBackground(brush)
28 dc.Clear()
29
30 # draw the image in random locations
31 for x,y in self.positions:
32 dc.DrawBitmap(self.photo, x, y, True)
33
34
35 class TestFrame(wx.Frame):
36 def __init__(self):
37 wx.Frame.__init__(self, None, title="Loading Images",
38 size=(640,480))
39 img = wx.Image("masked-portrait.png")
40 win = RandomImagePlacementWindow(self, img)
41
42
43 app = wx.PySimpleApp()
44 frm = TestFrame()
45 frm.Show()
46 app.MainLoop()