]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/tests/test3.py
nanosleep() detection works for Solaris
[wxWidgets.git] / utils / wxPython / tests / test3.py
CommitLineData
7bf85405
RD
1#!/bin/env python
2#----------------------------------------------------------------------------
3# Name: test3.py
4# Purpose: Testing menus and status lines
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
20class MyCanvas(wxWindow):
b8b8dda7
RD
21 def __init__(self, parent, ID):
22 wxWindow.__init__(self, parent, ID)
23 self.SetBackgroundColour(wxNamedColor("WHITE"))
24
7bf85405
RD
25 def OnPaint(self, event):
26 dc = wxPaintDC(self)
27 dc.BeginDrawing()
b8b8dda7 28 size = self.GetClientSize()
7bf85405
RD
29 font = wxFont(42, wxSWISS, wxNORMAL, wxNORMAL)
30 dc.SetFont(font)
31 st = "Python Rules!"
af309447 32 tw,th = dc.GetTextExtent(st)
b8b8dda7 33 dc.DrawText(st, (size.width-tw)/2, (size.height-th)/2)
7bf85405
RD
34 dc.EndDrawing()
35
36#---------------------------------------------------------------------------
37
105e45b9
RD
38#if wxPlatform == '__WXMSW__':
39class MyMiniFrame(wxMiniFrame):
40 def __init__(self, parent, ID, title, pos, size, style):
41 wxMiniFrame.__init__(self, parent, ID, title, pos, size, style)
42 panel = wxPanel(self, -1)
43 ID = NewId()
44 button = wxButton(panel, ID, "Close Me")
45 button.SetPosition(wxPoint(15, 15))
46 self.Connect(ID, -1, wxEVT_COMMAND_BUTTON_CLICKED, self.OnCloseMe)
47
48 def OnCloseMe(self, event):
49 self.Close(true)
50
51 def OnCloseWindow(self, event):
52 self.Destroy()
7bf85405
RD
53
54#---------------------------------------------------------------------------
55
56class MyFrame(wxFrame):
57 def __init__(self, parent, id, title):
58 wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
59 wxSize(420, 200))
60 self.canvas = MyCanvas(self, -1)
b8b8dda7 61 self.CreateStatusBar(2)
7bf85405
RD
62 mainmenu = wxMenuBar()
63 menu = wxMenu()
64 menu.Append(100, 'A &Menu Item', 'the help text')
65 menu.Append(101, '&Another', 'Grok!')
66 menu.AppendSeparator()
67 menu.Append(200, 'E&xit', 'Get the heck outta here!')
68 mainmenu.Append(menu, "&It's a menu!")
69 self.SetMenuBar(mainmenu)
f57d7932
RD
70 if wxPlatform == '__WXMSW__':
71 print menu.GetHelpString(100)
72 print mainmenu.GetHelpString(101)
73 print mainmenu.GetHelpString(200)
74 self.DragAcceptFiles(true)
7bf85405
RD
75
76 self.Connect(-1, -1, wxEVT_COMMAND_MENU_SELECTED, self.OnMenuCommand)
77 self.Connect(-1, -1, wxEVT_DROP_FILES, self.OnDropFiles)
78
79
80
81 def OnCloseWindow(self, event):
82 print 'OnCloseWindow'
83 self.Destroy()
84
85
86 def OnSize(self, event):
b8b8dda7
RD
87 size = self.GetClientSize()
88 self.canvas.SetSize(size)
89 self.SetStatusText("hello, this is a test: (%d, %d)" % (size.width, size.height), 1)
7bf85405
RD
90
91## def OnMenuHighlight(self, event):
92## mainmenu = self.GetMenuBar()
93## st = mainmenu.GetHelpString(event.GetMenuId())
94## self.SetStatusText('['+st+']', 0)
95
96 def OnMenuCommand(self, event):
97 # why isn't this a wxMenuEvent???
98 print event, event.GetInt()
99 if event.GetInt() == 200:
100 self.Close()
101 elif event.GetInt() == 101:
105e45b9 102 #if wxPlatform == '__WXMSW__':
f57d7932 103 win = MyMiniFrame(self, -1, "This is a Mini...",
7bf85405
RD
104 wxPoint(-1, -1), #wxPyDefaultPosition,
105 wxSize(150, 150),
106 wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
107 wxTHICK_FRAME | wxSYSTEM_MENU |
108 wxTINY_CAPTION_HORIZ)
f57d7932 109 win.Show(true)
105e45b9
RD
110 #else:
111 # print 'Sorry, can\'t do mini\'s...'
7bf85405
RD
112
113
114
115 def OnDropFiles(self, event):
116 fileList = event.GetFiles()
117 for file in fileList:
118 print file
119
120
121#---------------------------------------------------------------------------
122
123
124class MyApp(wxApp):
125 def OnInit(self):
126 frame = MyFrame(NULL, -1, "Test 3")
127 frame.Show(true)
128 self.SetTopWindow(frame)
129 return true
130
131#---------------------------------------------------------------------------
132
133
134def main():
135 app = MyApp(0)
136 app.MainLoop()
137
138
139def t():
140 import pdb
141 pdb.run('main()')
142
143if __name__ == '__main__':
144 main()
145
146
147#----------------------------------------------------------------------------
148#
149# $Log$
af309447
RD
150# Revision 1.5 1999/02/20 09:04:43 RD
151# Added wxWindow_FromHWND(hWnd) for wxMSW to construct a wxWindow from a
152# window handle. If you can get the window handle into the python code,
153# it should just work... More news on this later.
154#
155# Added wxImageList, wxToolTip.
156#
157# Re-enabled wxConfig.DeleteAll() since it is reportedly fixed for the
158# wxRegConfig class.
159#
160# As usual, some bug fixes, tweaks, etc.
161#
105e45b9 162# Revision 1.4 1998/12/16 22:12:46 RD
af309447 163#
105e45b9
RD
164# Tweaks needed to be able to build wxPython with wxGTK.
165#
b8b8dda7
RD
166# Revision 1.3 1998/12/15 20:44:35 RD
167# Changed the import semantics from "from wxPython import *" to "from
168# wxPython.wx import *" This is for people who are worried about
169# namespace pollution, they can use "from wxPython import wx" and then
170# prefix all the wxPython identifiers with "wx."
171#
172# Added wxTaskbarIcon for wxMSW.
173#
174# Made the events work for wxGrid.
175#
176# Added wxConfig.
177#
178# Added wxMiniFrame for wxGTK, (untested.)
179#
180# Changed many of the args and return values that were pointers to gdi
181# objects to references to reflect changes in the wxWindows API.
182#
183# Other assorted fixes and additions.
184#
f57d7932
RD
185# Revision 1.2 1998/08/22 19:51:17 RD
186# some tweaks for wxGTK
187#
7bf85405
RD
188# Revision 1.1 1998/08/09 08:28:05 RD
189# Initial version
190#
191#