]>
git.saurik.com Git - wxWidgets.git/blob - utils/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(wxWindow
):
23 def __init__(self
, parent
):
24 wxWindow
.__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
)
33 print 'bmp OK:', bmp
.Ok()
34 print 'bmp: (%dx%dx%d)' % (bmp
.GetWidth(), bmp
.GetHeight(), bmp
.GetDepth())
41 def OnPaint(self
, event
):
47 def DoDrawing(self
, dc
):
50 pen1
= wxPen(wxNamedColour('RED'))
52 dc
.DrawRectangle(5, 5, 50, 50)
54 dc
.SetBrush(wxLIGHT_GREY_BRUSH
)
55 dc
.SetPen(wxPen(wxNamedColour('BLUE'), 4))
56 dc
.DrawRectangle(15, 15, 50, 50)
58 font
= wxFont(14, wxSWISS
, wxNORMAL
, wxNORMAL
)
60 dc
.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
61 te
= dc
.GetTextExtent("Hello World")
62 dc
.DrawText("Hello World", 60, 65)
64 dc
.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
65 dc
.DrawLine(5, 65+te
[1], 60+te
[0], 65+te
[1])
67 lst
= [(100,110), (150,110), (150,160), (100,160)]
68 dc
.DrawLines(lst
, -60)
70 dc
.DrawPolygon(lst
, 75)
71 dc
.SetPen(wxGREEN_PEN
)
72 dc
.DrawSpline(lst
+[(100,100)])
74 dc
.DrawBitmap(self
.bmp
, 200, 20)
75 dc
.SetTextForeground(wxColour(0, 0xFF, 0x80))
76 dc
.DrawText("a bitmap", 200, 80)
78 self
.DrawSavedLines(dc
)
82 def DrawSavedLines(self
, dc
):
83 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
84 for line
in self
.lines
:
86 apply(dc
.DrawLine
, coords
)
90 def OnLeftButtonEvent(self
, event
):
92 self
.x
, self
.y
= event
.GetX(), event
.GetY()
94 elif event
.Dragging():
97 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
98 coords
= (self
.x
, self
.y
, event
.GetX(), event
.GetY())
99 self
.curLine
.append(coords
)
100 apply(dc
.DrawLine
, coords
)
101 self
.x
, self
.y
= event
.GetX(), event
.GetY()
104 self
.lines
.append(self
.curLine
)
111 #---------------------------------------------------------------------------
113 class MyFrame(wxFrame
):
114 def __init__(self
, parent
, id, title
):
115 wxFrame
.__init
__(self
, parent
, id, title
, wxPyDefaultPosition
, wxSize(320, 200))
116 self
.canvas
= MyCanvas(self
)
118 def OnCloseWindow(self
, event
):
121 def OnSize(self
, event
):
122 size
= self
.GetClientSize()
123 self
.canvas
.SetDimensions(5, 5, size
.width
-10, size
.height
-10)
126 #---------------------------------------------------------------------------
131 frame
= MyFrame(NULL
, -1, "Test 2")
133 self
.SetTopWindow(frame
)
136 #---------------------------------------------------------------------------
148 if __name__
== '__main__':
152 #----------------------------------------------------------------------------
155 # Revision 1.2 1998/12/15 20:44:34 RD
156 # Changed the import semantics from "from wxPython import *" to "from
157 # wxPython.wx import *" This is for people who are worried about
158 # namespace pollution, they can use "from wxPython import wx" and then
159 # prefix all the wxPython identifiers with "wx."
161 # Added wxTaskbarIcon for wxMSW.
163 # Made the events work for wxGrid.
167 # Added wxMiniFrame for wxGTK, (untested.)
169 # Changed many of the args and return values that were pointers to gdi
170 # objects to references to reflect changes in the wxWindows API.
172 # Other assorted fixes and additions.
174 # Revision 1.1 1998/08/09 08:28:05 RD