]> git.saurik.com Git - wxWidgets.git/blame - wxPython/samples/wxPIA_book/Chapter-12/draw_image.py
fix building/running of tex2rtf
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-12 / draw_image.py
CommitLineData
be05b434
RD
1# This one shows how to draw images on a DC.
2
3import wx
4import random
5random.seed()
6
7class 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
35class 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
43app = wx.PySimpleApp()
44frm = TestFrame()
45frm.Show()
46app.MainLoop()