]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/tests/test2.py
nanosleep() detection works for Solaris
[wxWidgets.git] / utils / 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
22class MyCanvas(wxWindow):
23 def __init__(self, parent):
24 wxWindow.__init__(self, parent, -1, wxPoint(0, 0), wxPyDefaultSize, wxSUNKEN_BORDER)
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)
33 print 'bmp OK:', bmp.Ok()
34 print 'bmp: (%dx%dx%d)' % (bmp.GetWidth(), bmp.GetHeight(), bmp.GetDepth())
35 self.bmp = bmp
36
37 self.lines = []
38
39
40
41 def OnPaint(self, event):
42 dc = wxPaintDC(self)
43 self.DoDrawing(dc)
44
45
46
47 def DoDrawing(self, dc):
48 dc.BeginDrawing()
49 #dc.Clear()
50 pen1 = wxPen(wxNamedColour('RED'))
51 dc.SetPen(pen1)
52 dc.DrawRectangle(5, 5, 50, 50)
53
54 dc.SetBrush(wxLIGHT_GREY_BRUSH)
55 dc.SetPen(wxPen(wxNamedColour('BLUE'), 4))
56 dc.DrawRectangle(15, 15, 50, 50)
57
58 font = wxFont(14, wxSWISS, wxNORMAL, wxNORMAL)
59 dc.SetFont(font)
60 dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
61 te = dc.GetTextExtent("Hello World")
62 dc.DrawText("Hello World", 60, 65)
63
64 dc.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
65 dc.DrawLine(5, 65+te[1], 60+te[0], 65+te[1])
66
67 lst = [(100,110), (150,110), (150,160), (100,160)]
68 dc.DrawLines(lst, -60)
69 dc.SetPen(wxGREY_PEN)
70 dc.DrawPolygon(lst, 75)
71 dc.SetPen(wxGREEN_PEN)
72 dc.DrawSpline(lst+[(100,100)])
73
74 dc.DrawBitmap(self.bmp, 200, 20)
75 dc.SetTextForeground(wxColour(0, 0xFF, 0x80))
76 dc.DrawText("a bitmap", 200, 80)
77
78 self.DrawSavedLines(dc)
79 dc.EndDrawing()
80
81
82 def DrawSavedLines(self, dc):
83 dc.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
84 for line in self.lines:
85 for coords in line:
86 apply(dc.DrawLine, coords)
87
88
89
90 def OnLeftButtonEvent(self, event):
91 if event.LeftDown():
92 self.x, self.y = event.GetX(), event.GetY()
93 self.curLine = []
94 elif event.Dragging():
95 dc = wxClientDC(self)
96 dc.BeginDrawing()
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()
102 dc.EndDrawing()
103 elif event.LeftUp():
104 self.lines.append(self.curLine)
105 self.curLine = []
106
107
108
109
110
111#---------------------------------------------------------------------------
112
113class 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)
117
118 def OnCloseWindow(self, event):
119 self.Destroy()
120
121 def OnSize(self, event):
b8b8dda7
RD
122 size = self.GetClientSize()
123 self.canvas.SetDimensions(5, 5, size.width-10, size.height-10)
7bf85405
RD
124
125
126#---------------------------------------------------------------------------
127
128
129class MyApp(wxApp):
130 def OnInit(self):
131 frame = MyFrame(NULL, -1, "Test 2")
132 frame.Show(true)
133 self.SetTopWindow(frame)
134 return true
135
136#---------------------------------------------------------------------------
137
138
139def main():
140 app = MyApp(0)
141 app.MainLoop()
142
143
144def t():
145 import pdb
146 pdb.run('main()')
147
148if __name__ == '__main__':
149 main()
150
151
152#----------------------------------------------------------------------------
153#
154# $Log$
b8b8dda7
RD
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."
160#
161# Added wxTaskbarIcon for wxMSW.
162#
163# Made the events work for wxGrid.
164#
165# Added wxConfig.
166#
167# Added wxMiniFrame for wxGTK, (untested.)
168#
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.
171#
172# Other assorted fixes and additions.
173#
7bf85405
RD
174# Revision 1.1 1998/08/09 08:28:05 RD
175# Initial version
176#
177#