]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/test2.py
2 #----------------------------------------------------------------------------
4 # Purpose: Testing GDI stuff and events.
10 # Copyright: (c) 1998 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
15 from wxPython
.wx
import *
18 #---------------------------------------------------------------------------
22 class MyCanvas(wxScrolledWindow
):
23 def __init__(self
, parent
):
24 wxScrolledWindow
.__init
__(self
, parent
, -1, wxPoint(0, 0), wxPyDefaultSize
, wxSUNKEN_BORDER
)
26 self
.SetBackgroundColour(wxNamedColor("WHITE"))
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
)
31 self
.SetCursor(wxStockCursor(wxCURSOR_PENCIL
))
32 bmp
= wxBitmap('bitmaps/test2.bmp', wxBITMAP_TYPE_BMP
)
35 self
.SetScrollbars(20, 20, 50, 50)
41 def OnPaint(self
, event
):
48 def DoDrawing(self
, dc
):
51 pen1
= wxPen(wxNamedColour('RED'))
53 dc
.DrawRectangle(5, 5, 50, 50)
55 dc
.SetBrush(wxLIGHT_GREY_BRUSH
)
56 dc
.SetPen(wxPen(wxNamedColour('BLUE'), 4))
57 dc
.DrawRectangle(15, 15, 50, 50)
59 font
= wxFont(14, wxSWISS
, wxNORMAL
, wxNORMAL
)
61 dc
.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
62 te
= dc
.GetTextExtent("Hello World")
63 dc
.DrawText("Hello World", 60, 65)
65 dc
.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
66 dc
.DrawLine(5, 65+te
[1], 60+te
[0], 65+te
[1])
68 lst
= [(100,110), (150,110), (150,160), (100,160)]
69 dc
.DrawLines(lst
, -60)
71 dc
.DrawPolygon(lst
, 75)
72 dc
.SetPen(wxGREEN_PEN
)
73 dc
.DrawSpline(lst
+[(100,100)])
75 dc
.DrawBitmap(self
.bmp
, 200, 20)
76 dc
.SetTextForeground(wxColour(0, 0xFF, 0x80))
77 dc
.DrawText("a bitmap", 200, 80)
79 self
.DrawSavedLines(dc
)
83 def DrawSavedLines(self
, dc
):
84 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
85 for line
in self
.lines
:
87 apply(dc
.DrawLine
, coords
)
91 def OnLeftButtonEvent(self
, event
):
93 self
.x
, self
.y
= event
.GetX(), event
.GetY()
95 elif event
.Dragging():
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()
105 self
.lines
.append(self
.curLine
)
112 #---------------------------------------------------------------------------
114 class 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
)
119 def OnCloseWindow(self
, event
):
122 def OnSize(self
, event
):
123 size
= self
.GetClientSize()
124 self
.canvas
.SetDimensions(5, 5, size
.width
-10, size
.height
-10)
127 #---------------------------------------------------------------------------
132 frame
= MyFrame(NULL
, -1, "Test 2")
134 self
.SetTopWindow(frame
)
138 #---------------------------------------------------------------------------
150 if __name__
== '__main__':
154 #----------------------------------------------------------------------------
157 # Revision 1.4 2001/02/16 08:19:38 robind
158 # Copied/merged from the 2.2 branch.
160 # Changes needed to build with new event system
162 # Revision 1.1.2.2 2001/01/30 20:54:16 robind
164 # Gobs of changes move from the main trunk to the 2.2 branch in
165 # preparataion for 2.2.5 release. See CHANGES.txt for details.
167 # Revision 1.3 2000/10/30 21:05:22 robind
169 # Merged wxPython 2.2.2 over to the main branch
171 # Revision 1.1.2.1 2000/05/16 02:07:01 RD
173 # Moved and reorganized wxPython directories
175 # Now builds into an intermediate wxPython package directory before
178 # Revision 1.3 1999/04/30 03:29:53 RD
180 # wxPython 2.0b9, first phase (win32)
181 # Added gobs of stuff, see wxPython/README.txt for details
183 # Revision 1.2.4.1 1999/03/27 23:30:00 RD
186 # Python thread support
187 # various minor additions
188 # various minor fixes
190 # Revision 1.2 1998/12/15 20:44:34 RD
191 # Changed the import semantics from "from wxPython import *" to "from
192 # wxPython.wx import *" This is for people who are worried about
193 # namespace pollution, they can use "from wxPython import wx" and then
194 # prefix all the wxPython identifiers with "wx."
196 # Added wxTaskbarIcon for wxMSW.
198 # Made the events work for wxGrid.
202 # Added wxMiniFrame for wxGTK, (untested.)
204 # Changed many of the args and return values that were pointers to gdi
205 # objects to references to reflect changes in the wxWindows API.
207 # Other assorted fixes and additions.
209 # Revision 1.1 1998/08/09 08:28:05 RD