]> git.saurik.com Git - wxWidgets.git/blame - wxPython/tests/test2.py
Doc mods
[wxWidgets.git] / wxPython / tests / test2.py
CommitLineData
7bf85405
RD
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
b8b8dda7 15from wxPython.wx import *
7bf85405
RD
16
17
18#---------------------------------------------------------------------------
19
20
21
cf694132 22class MyCanvas(wxScrolledWindow):
7bf85405 23 def __init__(self, parent):
cf694132 24 wxScrolledWindow.__init__(self, parent, -1, wxPoint(0, 0), wxPyDefaultSize, wxSUNKEN_BORDER)
7bf85405 25
b8b8dda7 26 self.SetBackgroundColour(wxNamedColor("WHITE"))
7bf85405
RD
27 self.Connect(-1, -1, wxEVT_LEFT_DOWN, self.OnLeftButtonEvent)
28 self.Connect(-1, -1, wxEVT_LEFT_UP, self.OnLeftButtonEvent)
29 self.Connect(-1, -1, wxEVT_MOTION, self.OnLeftButtonEvent)
30
31 self.SetCursor(wxStockCursor(wxCURSOR_PENCIL))
32 bmp = wxBitmap('bitmaps/test2.bmp', wxBITMAP_TYPE_BMP)
7bf85405
RD
33 self.bmp = bmp
34
cf694132
RD
35 self.SetScrollbars(20, 20, 50, 50)
36
7bf85405
RD
37 self.lines = []
38
39
40
41 def OnPaint(self, event):
42 dc = wxPaintDC(self)
cf694132 43 self.PrepareDC(dc)
7bf85405
RD
44 self.DoDrawing(dc)
45
46
47
48 def DoDrawing(self, dc):
49 dc.BeginDrawing()
50 #dc.Clear()
51 pen1 = wxPen(wxNamedColour('RED'))
52 dc.SetPen(pen1)
53 dc.DrawRectangle(5, 5, 50, 50)
54
55 dc.SetBrush(wxLIGHT_GREY_BRUSH)
56 dc.SetPen(wxPen(wxNamedColour('BLUE'), 4))
57 dc.DrawRectangle(15, 15, 50, 50)
58
59 font = wxFont(14, wxSWISS, wxNORMAL, wxNORMAL)
60 dc.SetFont(font)
61 dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
62 te = dc.GetTextExtent("Hello World")
63 dc.DrawText("Hello World", 60, 65)
64
65 dc.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
66 dc.DrawLine(5, 65+te[1], 60+te[0], 65+te[1])
67
68 lst = [(100,110), (150,110), (150,160), (100,160)]
69 dc.DrawLines(lst, -60)
70 dc.SetPen(wxGREY_PEN)
71 dc.DrawPolygon(lst, 75)
72 dc.SetPen(wxGREEN_PEN)
73 dc.DrawSpline(lst+[(100,100)])
74
75 dc.DrawBitmap(self.bmp, 200, 20)
76 dc.SetTextForeground(wxColour(0, 0xFF, 0x80))
77 dc.DrawText("a bitmap", 200, 80)
78
79 self.DrawSavedLines(dc)
80 dc.EndDrawing()
81
82
83 def DrawSavedLines(self, dc):
84 dc.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
85 for line in self.lines:
86 for coords in line:
87 apply(dc.DrawLine, coords)
88
89
90
91 def OnLeftButtonEvent(self, event):
92 if event.LeftDown():
93 self.x, self.y = event.GetX(), event.GetY()
94 self.curLine = []
95 elif event.Dragging():
96 dc = wxClientDC(self)
97 dc.BeginDrawing()
98 dc.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
99 coords = (self.x, self.y, event.GetX(), event.GetY())
100 self.curLine.append(coords)
101 apply(dc.DrawLine, coords)
102 self.x, self.y = event.GetX(), event.GetY()
103 dc.EndDrawing()
104 elif event.LeftUp():
105 self.lines.append(self.curLine)
106 self.curLine = []
107
108
109
110
111
112#---------------------------------------------------------------------------
113
114class MyFrame(wxFrame):
115 def __init__(self, parent, id, title):
116 wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition, wxSize(320, 200))
117 self.canvas = MyCanvas(self)
118
119 def OnCloseWindow(self, event):
120 self.Destroy()
121
122 def OnSize(self, event):
b8b8dda7
RD
123 size = self.GetClientSize()
124 self.canvas.SetDimensions(5, 5, size.width-10, size.height-10)
7bf85405
RD
125
126
127#---------------------------------------------------------------------------
128
129
130class MyApp(wxApp):
131 def OnInit(self):
132 frame = MyFrame(NULL, -1, "Test 2")
133 frame.Show(true)
134 self.SetTopWindow(frame)
135 return true
136
cf694132 137
7bf85405
RD
138#---------------------------------------------------------------------------
139
140
141def main():
142 app = MyApp(0)
143 app.MainLoop()
144
145
146def t():
147 import pdb
148 pdb.run('main()')
149
150if __name__ == '__main__':
151 main()
152
153
154#----------------------------------------------------------------------------
155#
156# $Log$
f6bcfd97
BP
157# Revision 1.2 2000/07/15 19:51:32 cvsuser
158# merged 2.2 branch
159#
160# Revision 1.1.2.1 2000/05/16 02:07:01 RD
161#
162# Moved and reorganized wxPython directories
163#
164# Now builds into an intermediate wxPython package directory before
165# installing
166#
cf694132 167# Revision 1.3 1999/04/30 03:29:53 RD
f6bcfd97 168#
cf694132
RD
169# wxPython 2.0b9, first phase (win32)
170# Added gobs of stuff, see wxPython/README.txt for details
171#
172# Revision 1.2.4.1 1999/03/27 23:30:00 RD
173#
174# wxPython 2.0b8
175# Python thread support
176# various minor additions
177# various minor fixes
178#
b8b8dda7
RD
179# Revision 1.2 1998/12/15 20:44:34 RD
180# Changed the import semantics from "from wxPython import *" to "from
181# wxPython.wx import *" This is for people who are worried about
182# namespace pollution, they can use "from wxPython import wx" and then
183# prefix all the wxPython identifiers with "wx."
184#
185# Added wxTaskbarIcon for wxMSW.
186#
187# Made the events work for wxGrid.
188#
189# Added wxConfig.
190#
191# Added wxMiniFrame for wxGTK, (untested.)
192#
193# Changed many of the args and return values that were pointers to gdi
194# objects to references to reflect changes in the wxWindows API.
195#
196# Other assorted fixes and additions.
197#
7bf85405
RD
198# Revision 1.1 1998/08/09 08:28:05 RD
199# Initial version
200#
201#