]>
Commit | Line | Data |
---|---|---|
cbfc9df6 RD |
1 | |
2 | import wx | |
3 | ||
4 | #---------------------------------------------------------------------- | |
5 | ||
6 | ||
7 | class TestPanel(wx.Panel): | |
8 | def __init__(self, parent): | |
9 | wx.Panel.__init__(self, parent, -1) | |
10 | self.Bind(wx.EVT_PAINT, self.OnPaint) | |
11 | ||
12 | ||
13 | def OnPaint(self, evt): | |
14 | dc = wx.PaintDC(self) | |
15 | try: | |
16 | gc = wx.GraphicsContext.Create(dc) | |
17 | except NotImplementedError: | |
18 | dc.DrawText("This build of wxPython does not support the wx.GraphicsContext " | |
19 | "family of classes.", | |
20 | 25, 25) | |
21 | return | |
22 | ||
23 | font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) | |
24 | font.SetWeight(wx.BOLD) | |
25 | gc.SetFont(font) | |
26 | ||
27 | gc.Translate(10, 10) | |
28 | self.DrawText(gc, 'normal') | |
29 | ||
30 | gc.Translate(0, 25) | |
31 | gc.PushState() | |
32 | gc.Scale(2, 2) | |
33 | self.DrawText(gc, 'scaled') | |
34 | gc.PopState() | |
35 | ||
36 | gc.Translate(0, 35) | |
37 | self.DrawText(gc, '\nnewline') | |
38 | ||
39 | def DrawText(self, gc, txt): | |
40 | txt = "This is a test: " + txt | |
41 | w,h,d,e = gc.GetFullTextExtent(txt) | |
42 | ##print w,h,d,e | |
43 | ||
44 | gc.DrawText(txt, 0, 0) | |
45 | ||
46 | pen = wx.Pen("red", 1) | |
47 | gc.SetPen(pen) | |
48 | ||
49 | path = gc.CreatePath() | |
50 | path.MoveToPoint(-1, -1) | |
51 | self.MakeCrosshair(path) | |
52 | gc.StrokePath(path) | |
53 | ||
54 | path = gc.CreatePath() | |
55 | path.MoveToPoint(w+1, h+1) | |
56 | self.MakeCrosshair(path) | |
57 | gc.StrokePath(path) | |
58 | ||
59 | ||
60 | ||
61 | ||
62 | def MakeCrosshair(self, path): | |
63 | x, y = path.GetCurrentPoint() | |
64 | path.MoveToPoint(x-5, y) | |
65 | path.AddLineToPoint(x+5,y) | |
66 | path.MoveToPoint(x, y-5) | |
67 | path.AddLineToPoint(x, y+5) | |
68 | path.MoveToPoint(x,y) | |
69 | ||
70 | ||
71 | ||
72 | ||
73 | app = wx.App(False) | |
74 | frm = wx.Frame(None, title="Testing GC Text") | |
75 | pnl = TestPanel(frm) | |
76 | frm.Show() | |
77 | app.MainLoop() |