]> git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/test_bufDcBlit.py
fixed deadlock when calling wxPostEvent() from worker thread
[wxWidgets.git] / wxPython / tests / test_bufDcBlit.py
1 import wx
2 import os
3 print "PID:", os.getpid()
4
5 count = 0
6
7 class ResultsFrame(wx.Frame):
8 def __init__(self, parent, bmp):
9 global count
10 count += 1
11 wx.Frame.__init__(self, parent, title=str(count), size=(100,100))
12 p = wx.Panel(self)
13 sb = wx.StaticBitmap(p, -1, bmp, (20,20))
14 self.Show()
15
16
17
18 class TestPanel(wx.Panel):
19 def __init__(self, parent):
20 wx.Panel.__init__(self, parent)
21 b = wx.Button(self, -1, "Test", (50,50))
22 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
23
24 def RunTest(self, bdc, bg, fg):
25 # draw to the buffered dc
26 bdc.SetBackground(wx.Brush(bg))
27 bdc.Clear()
28 bdc.SetPen(wx.Pen(fg, 2))
29 bdc.DrawLine(0,0, 30,30)
30 bdc.DrawLine(0,30, 30,0)
31
32 # now bilt it to a bitmap
33 bmp = wx.EmptyBitmap(30,30)
34 mdc = wx.MemoryDC()
35 mdc.SelectObject(bmp)
36 mdc.Blit(0,0, 30,30, bdc, 0,0)
37 del mdc
38
39 # display the results
40 ResultsFrame(self, bmp)
41
42
43
44 def OnButton(self, evt):
45
46 # 1. test a buffered dc not using a buffer bitmap
47 bdc = wx.BufferedDC(wx.ClientDC(self), self.GetSize())
48 self.RunTest(bdc, "yellow", "red")
49 del bdc
50
51 # 2. now do one that does have a buffer bitmap
52 buf = wx.EmptyBitmap(100,100)
53 bdc = wx.BufferedDC(wx.ClientDC(self), buf)
54 self.RunTest(bdc, "red", "blue")
55 del bdc
56
57 # 3. now one without a real DC
58 buf = wx.EmptyBitmap(100,100)
59 bdc = wx.BufferedDC(None, buf)
60 self.RunTest(bdc, "purple", "yellow")
61 del bdc
62
63 # 4. finally test a real unbuffered DC
64 dc = wx.ClientDC(self)
65 self.RunTest(dc, "red", "white")
66
67
68 # blit from the last buffer back to the main window
69 buf.SetMaskColour("yellow")
70 mdc = wx.MemoryDC()
71 mdc.SelectObject(buf)
72 dc.Blit(100,100,30,30, mdc, 0,0, useMask=True)
73
74
75
76 app = wx.App(0)
77 frm = wx.Frame(None)
78 pnl = TestPanel(frm)
79 frm.Show()
80 app.MainLoop()
81
82
83
84
85