]>
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
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
.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
)
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())
40 def OnPaint(self
, event
):
46 def DoDrawing(self
, dc
):
49 pen1
= wxPen(wxNamedColour('RED'))
51 dc
.DrawRectangle(5, 5, 50, 50)
53 dc
.SetBrush(wxLIGHT_GREY_BRUSH
)
54 dc
.SetPen(wxPen(wxNamedColour('BLUE'), 4))
55 dc
.DrawRectangle(15, 15, 50, 50)
57 font
= wxFont(14, wxSWISS
, wxNORMAL
, wxNORMAL
)
59 dc
.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
60 te
= dc
.GetTextExtent("Hello World")
61 dc
.DrawText("Hello World", 60, 65)
63 dc
.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
64 dc
.DrawLine(5, 65+te
[1], 60+te
[0], 65+te
[1])
66 lst
= [(100,110), (150,110), (150,160), (100,160)]
67 dc
.DrawLines(lst
, -60)
69 dc
.DrawPolygon(lst
, 75)
70 dc
.SetPen(wxGREEN_PEN
)
71 dc
.DrawSpline(lst
+[(100,100)])
73 dc
.DrawBitmap(self
.bmp
, 200, 20)
74 dc
.SetTextForeground(wxColour(0, 0xFF, 0x80))
75 dc
.DrawText("a bitmap", 200, 80)
77 self
.DrawSavedLines(dc
)
81 def DrawSavedLines(self
, dc
):
82 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
83 for line
in self
.lines
:
85 apply(dc
.DrawLine
, coords
)
89 def OnLeftButtonEvent(self
, event
):
91 self
.x
, self
.y
= event
.GetX(), event
.GetY()
93 elif event
.Dragging():
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()
103 self
.lines
.append(self
.curLine
)
110 #---------------------------------------------------------------------------
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
)
117 def OnCloseWindow(self
, event
):
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
)
126 #---------------------------------------------------------------------------
131 frame
= MyFrame(NULL
, -1, "Test 2")
133 self
.SetTopWindow(frame
)
136 #---------------------------------------------------------------------------
148 if __name__
== '__main__':
152 #----------------------------------------------------------------------------
155 # Revision 1.1 1998/08/09 08:28:05 RD