source: SHX/trunk/sandbox/GraphicsContext.py @ 378

Revision 378, 1.6 KB checked in by marcus, 11 years ago (diff)

GC tests. Old wxpython version issues.

  • Property svn:eol-style set to native
Line 
1# -*- coding: utf-8 -*-
2
3import wx
4import wx.lib.scrolledpanel as SP
5
6class MyPanel(SP.ScrolledPanel):
7    def __init__(self, parent):
8        SP.ScrolledPanel.__init__(self, parent, style=wx.BORDER_SIMPLE)
9        self.Bind(wx.EVT_PAINT, self.OnPaint)
10        self.Bind(wx.EVT_IDLE, self.OnIdle)
11        self.refresh = False
12        self.OnPaint(None)
13
14    def OnIdle(self, evt):
15        if self.refresh:
16            self.Paint()
17            self.refresh = False
18
19    def OnPaint(self, evt):
20        self.refresh = True
21
22    def Paint(self):
23        width, height = self.GetClientSize()
24        print width, height
25
26        bitmap = wx.EmptyBitmap(width, height)
27        buffer = wx.MemoryDC(bitmap)
28#        buffer = wx.PaintDC(self)
29        buffer.Clear()
30       
31
32#        printer = wx.PrintData()
33#        dc = wx.PostScriptDC(printer)
34        # only for screen, not for print nor postscript
35#        dc = wx.GraphicsContext.Create(buffer)
36#        dc = wx.GCDC(buffer)
37        dc = buffer
38
39        dc.SetDeviceOrigin(10, 240)
40        dc.SetAxisOrientation(True, True)
41
42        dc.BeginDrawing()
43        dc.DrawLines([[10,10],[100,200]])
44        dc.CrossHair(150,100)
45        dc.EndDrawing()
46
47        dc2 = wx.AutoBufferedPaintDCFactory(self)
48        dc2.Blit(0, 0, width, height, buffer, -10, 240, wx.COPY)
49
50class MyFrame(wx.Frame):
51    def __init__(self, parent, title):
52        wx.Frame.__init__(self, parent, title=title, size=(640,480))
53        self.canvas = MyPanel(self)
54        self.Show()
55
56def main():
57    app = wx.App(False)
58    frame = MyFrame(None, 'GC test')
59    app.MainLoop()
60
61if __name__ == "__main__":
62    main()
Note: See TracBrowser for help on using the repository browser.