]> git.saurik.com Git - wxWidgets.git/blame - wxPython/tests/test3.py
digital mars updated
[wxWidgets.git] / 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
55class MyFrame(wxFrame):
56 def __init__(self, parent, id, title):
57 wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
58 wxSize(420, 200))
59 self.canvas = MyCanvas(self, -1)
b8b8dda7 60 self.CreateStatusBar(2)
7bf85405
RD
61 mainmenu = wxMenuBar()
62 menu = wxMenu()
63 menu.Append(100, 'A &Menu Item', 'the help text')
64 menu.Append(101, '&Another', 'Grok!')
65 menu.AppendSeparator()
66 menu.Append(200, 'E&xit', 'Get the heck outta here!')
67 mainmenu.Append(menu, "&It's a menu!")
68 self.SetMenuBar(mainmenu)
f57d7932
RD
69 if wxPlatform == '__WXMSW__':
70 print menu.GetHelpString(100)
71 print mainmenu.GetHelpString(101)
72 print mainmenu.GetHelpString(200)
73 self.DragAcceptFiles(true)
7bf85405
RD
74
75 self.Connect(-1, -1, wxEVT_COMMAND_MENU_SELECTED, self.OnMenuCommand)
76 self.Connect(-1, -1, wxEVT_DROP_FILES, self.OnDropFiles)
77
78
79
80 def OnCloseWindow(self, event):
81 print 'OnCloseWindow'
82 self.Destroy()
83
84
85 def OnSize(self, event):
b8b8dda7
RD
86 size = self.GetClientSize()
87 self.canvas.SetSize(size)
88 self.SetStatusText("hello, this is a test: (%d, %d)" % (size.width, size.height), 1)
7bf85405
RD
89
90## def OnMenuHighlight(self, event):
91## mainmenu = self.GetMenuBar()
92## st = mainmenu.GetHelpString(event.GetMenuId())
93## self.SetStatusText('['+st+']', 0)
94
95 def OnMenuCommand(self, event):
96 # why isn't this a wxMenuEvent???
97 print event, event.GetInt()
98 if event.GetInt() == 200:
99 self.Close()
100 elif event.GetInt() == 101:
105e45b9 101 #if wxPlatform == '__WXMSW__':
f57d7932 102 win = MyMiniFrame(self, -1, "This is a Mini...",
7bf85405
RD
103 wxPoint(-1, -1), #wxPyDefaultPosition,
104 wxSize(150, 150),
105 wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
106 wxTHICK_FRAME | wxSYSTEM_MENU |
107 wxTINY_CAPTION_HORIZ)
f57d7932 108 win.Show(true)
105e45b9
RD
109 #else:
110 # print 'Sorry, can\'t do mini\'s...'
7bf85405
RD
111
112
113
114 def OnDropFiles(self, event):
115 fileList = event.GetFiles()
116 for file in fileList:
117 print file
118
119
120#---------------------------------------------------------------------------
121
122
123class MyApp(wxApp):
124 def OnInit(self):
125 frame = MyFrame(NULL, -1, "Test 3")
126 frame.Show(true)
127 self.SetTopWindow(frame)
128 return true
129
130#---------------------------------------------------------------------------
131
132
133def main():
134 app = MyApp(0)
135 app.MainLoop()
136
137
138def t():
139 import pdb
140 pdb.run('main()')
141
142if __name__ == '__main__':
143 main()
144
145
146#----------------------------------------------------------------------------
147#
148# $Log$
1b62f00d
RD
149# Revision 1.4 2001/02/16 08:19:38 robind
150# Copied/merged from the 2.2 branch.
151#
152# Changes needed to build with new event system
153#
154# Revision 1.1.2.2 2001/01/30 20:54:16 robind
155#
156# Gobs of changes move from the main trunk to the 2.2 branch in
157# preparataion for 2.2.5 release. See CHANGES.txt for details.
158#
c368d904 159# Revision 1.3 2000/10/30 21:05:22 robind
1b62f00d 160#
c368d904 161# Merged wxPython 2.2.2 over to the main branch
f6bcfd97
BP
162#
163# Revision 1.1.2.1 2000/05/16 02:07:01 RD
164#
165# Moved and reorganized wxPython directories
166#
167# Now builds into an intermediate wxPython package directory before
168# installing
169#
cf694132 170# Revision 1.6 1999/04/30 03:29:53 RD
f6bcfd97 171#
cf694132
RD
172# wxPython 2.0b9, first phase (win32)
173# Added gobs of stuff, see wxPython/README.txt for details
174#
af309447
RD
175# Revision 1.5 1999/02/20 09:04:43 RD
176# Added wxWindow_FromHWND(hWnd) for wxMSW to construct a wxWindow from a
177# window handle. If you can get the window handle into the python code,
178# it should just work... More news on this later.
179#
180# Added wxImageList, wxToolTip.
181#
182# Re-enabled wxConfig.DeleteAll() since it is reportedly fixed for the
183# wxRegConfig class.
184#
185# As usual, some bug fixes, tweaks, etc.
186#
105e45b9 187# Revision 1.4 1998/12/16 22:12:46 RD
af309447 188#
105e45b9
RD
189# Tweaks needed to be able to build wxPython with wxGTK.
190#
b8b8dda7
RD
191# Revision 1.3 1998/12/15 20:44:35 RD
192# Changed the import semantics from "from wxPython import *" to "from
193# wxPython.wx import *" This is for people who are worried about
194# namespace pollution, they can use "from wxPython import wx" and then
195# prefix all the wxPython identifiers with "wx."
196#
197# Added wxTaskbarIcon for wxMSW.
198#
199# Made the events work for wxGrid.
200#
201# Added wxConfig.
202#
203# Added wxMiniFrame for wxGTK, (untested.)
204#
205# Changed many of the args and return values that were pointers to gdi
206# objects to references to reflect changes in the wxWindows API.
207#
208# Other assorted fixes and additions.
209#
f57d7932
RD
210# Revision 1.2 1998/08/22 19:51:17 RD
211# some tweaks for wxGTK
212#
7bf85405
RD
213# Revision 1.1 1998/08/09 08:28:05 RD
214# Initial version
215#
216#