]>
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.2 2000/07/15 19:51:32 cvsuser
160 # Revision 1.1.2.1 2000/05/16 02:07:01 RD
162 # Moved and reorganized wxPython directories
164 # Now builds into an intermediate wxPython package directory before
167 # Revision 1.3 1999/04/30 03:29:53 RD
169 # wxPython 2.0b9, first phase (win32)
170 # Added gobs of stuff, see wxPython/README.txt for details
172 # Revision 1.2.4.1 1999/03/27 23:30:00 RD
175 # Python thread support
176 # various minor additions
177 # various minor fixes
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."
185 # Added wxTaskbarIcon for wxMSW.
187 # Made the events work for wxGrid.
191 # Added wxMiniFrame for wxGTK, (untested.)
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.
196 # Other assorted fixes and additions.
198 # Revision 1.1 1998/08/09 08:28:05 RD