]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/tests/test2.py
Additions for wxTreeCtrl
[wxWidgets.git] / utils / wxPython / tests / test2.py
1 #!/bin/env python
2 #----------------------------------------------------------------------------
3 # Name: test2.py
4 # Purpose: Testing GDI stuff and events.
5 #
6 # Author: Robin Dunn
7 #
8 # Created:
9 # RCS-ID: $Id$
10 # Copyright: (c) 1998 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
13
14
15 from wxPython import *
16
17
18 #---------------------------------------------------------------------------
19
20
21
22 class MyCanvas(wxWindow):
23 def __init__(self, parent):
24 wxWindow.__init__(self, parent, -1, wxPoint(0, 0), wxPyDefaultSize, wxSUNKEN_BORDER)
25
26 self.Connect(-1, -1, wxEVT_LEFT_DOWN, self.OnLeftButtonEvent)
27 self.Connect(-1, -1, wxEVT_LEFT_UP, self.OnLeftButtonEvent)
28 self.Connect(-1, -1, wxEVT_MOTION, self.OnLeftButtonEvent)
29
30 self.SetCursor(wxStockCursor(wxCURSOR_PENCIL))
31 bmp = wxBitmap('bitmaps/test2.bmp', wxBITMAP_TYPE_BMP)
32 print 'bmp OK:', bmp.Ok()
33 print 'bmp: (%dx%dx%d)' % (bmp.GetWidth(), bmp.GetHeight(), bmp.GetDepth())
34 self.bmp = bmp
35
36 self.lines = []
37
38
39
40 def OnPaint(self, event):
41 dc = wxPaintDC(self)
42 self.DoDrawing(dc)
43
44
45
46 def DoDrawing(self, dc):
47 dc.BeginDrawing()
48 #dc.Clear()
49 pen1 = wxPen(wxNamedColour('RED'))
50 dc.SetPen(pen1)
51 dc.DrawRectangle(5, 5, 50, 50)
52
53 dc.SetBrush(wxLIGHT_GREY_BRUSH)
54 dc.SetPen(wxPen(wxNamedColour('BLUE'), 4))
55 dc.DrawRectangle(15, 15, 50, 50)
56
57 font = wxFont(14, wxSWISS, wxNORMAL, wxNORMAL)
58 dc.SetFont(font)
59 dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
60 te = dc.GetTextExtent("Hello World")
61 dc.DrawText("Hello World", 60, 65)
62
63 dc.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
64 dc.DrawLine(5, 65+te[1], 60+te[0], 65+te[1])
65
66 lst = [(100,110), (150,110), (150,160), (100,160)]
67 dc.DrawLines(lst, -60)
68 dc.SetPen(wxGREY_PEN)
69 dc.DrawPolygon(lst, 75)
70 dc.SetPen(wxGREEN_PEN)
71 dc.DrawSpline(lst+[(100,100)])
72
73 dc.DrawBitmap(self.bmp, 200, 20)
74 dc.SetTextForeground(wxColour(0, 0xFF, 0x80))
75 dc.DrawText("a bitmap", 200, 80)
76
77 self.DrawSavedLines(dc)
78 dc.EndDrawing()
79
80
81 def DrawSavedLines(self, dc):
82 dc.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
83 for line in self.lines:
84 for coords in line:
85 apply(dc.DrawLine, coords)
86
87
88
89 def OnLeftButtonEvent(self, event):
90 if event.LeftDown():
91 self.x, self.y = event.GetX(), event.GetY()
92 self.curLine = []
93 elif event.Dragging():
94 dc = wxClientDC(self)
95 dc.BeginDrawing()
96 dc.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
97 coords = (self.x, self.y, event.GetX(), event.GetY())
98 self.curLine.append(coords)
99 apply(dc.DrawLine, coords)
100 self.x, self.y = event.GetX(), event.GetY()
101 dc.EndDrawing()
102 elif event.LeftUp():
103 self.lines.append(self.curLine)
104 self.curLine = []
105
106
107
108
109
110 #---------------------------------------------------------------------------
111
112 class MyFrame(wxFrame):
113 def __init__(self, parent, id, title):
114 wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition, wxSize(320, 200))
115 self.canvas = MyCanvas(self)
116
117 def OnCloseWindow(self, event):
118 self.Destroy()
119
120 def OnSize(self, event):
121 w,h = self.GetClientSize()
122 #self.canvas.SetSize(5, 5, w-10, h-10)
123 self.canvas.SetDimensions(0, 0, w, h)
124
125
126 #---------------------------------------------------------------------------
127
128
129 class MyApp(wxApp):
130 def OnInit(self):
131 frame = MyFrame(NULL, -1, "Test 2")
132 frame.Show(true)
133 self.SetTopWindow(frame)
134 return true
135
136 #---------------------------------------------------------------------------
137
138
139 def main():
140 app = MyApp(0)
141 app.MainLoop()
142
143
144 def t():
145 import pdb
146 pdb.run('main()')
147
148 if __name__ == '__main__':
149 main()
150
151
152 #----------------------------------------------------------------------------
153 #
154 # $Log$
155 # Revision 1.1 1998/08/09 08:28:05 RD
156 # Initial version
157 #
158 #