]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/tests/test3.py
Added SetFont to most controls and controls sample
[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
15from wxPython import *
16
17
18#---------------------------------------------------------------------------
19
20class MyCanvas(wxWindow):
21 def OnPaint(self, event):
22 dc = wxPaintDC(self)
23 dc.BeginDrawing()
24 w, h = self.GetClientSize()
25 font = wxFont(42, wxSWISS, wxNORMAL, wxNORMAL)
26 dc.SetFont(font)
27 st = "Python Rules!"
28 tw,th, d,e = dc.GetTextExtent(st)
29 dc.DrawText(st, (w-tw)/2, (h-th)/2)
30 dc.EndDrawing()
31
32#---------------------------------------------------------------------------
33
f57d7932
RD
34if wxPlatform == '__WXMSW__':
35 class MyMiniFrame(wxMiniFrame):
36 def __init__(self, parent, ID, title, pos, size, style):
37 wxMiniFrame.__init__(self, parent, ID, title, pos, size, style)
38 panel = wxPanel(self, -1)
39 ID = NewId()
40 button = wxButton(panel, ID, "Close Me")
41 button.SetPosition(wxPoint(15, 15))
42 self.Connect(ID, -1, wxEVT_COMMAND_BUTTON_CLICKED, self.OnCloseMe)
43
44 def OnCloseMe(self, event):
45 self.Close(true)
46
47 def OnCloseWindow(self, event):
48 self.Destroy()
7bf85405
RD
49
50#---------------------------------------------------------------------------
51
52class MyFrame(wxFrame):
53 def __init__(self, parent, id, title):
54 wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition,
55 wxSize(420, 200))
56 self.canvas = MyCanvas(self, -1)
57 self.CreateStatusBar(3)
58 mainmenu = wxMenuBar()
59 menu = wxMenu()
60 menu.Append(100, 'A &Menu Item', 'the help text')
61 menu.Append(101, '&Another', 'Grok!')
62 menu.AppendSeparator()
63 menu.Append(200, 'E&xit', 'Get the heck outta here!')
64 mainmenu.Append(menu, "&It's a menu!")
65 self.SetMenuBar(mainmenu)
f57d7932
RD
66 if wxPlatform == '__WXMSW__':
67 print menu.GetHelpString(100)
68 print mainmenu.GetHelpString(101)
69 print mainmenu.GetHelpString(200)
70 self.DragAcceptFiles(true)
7bf85405
RD
71
72 self.Connect(-1, -1, wxEVT_COMMAND_MENU_SELECTED, self.OnMenuCommand)
73 self.Connect(-1, -1, wxEVT_DROP_FILES, self.OnDropFiles)
74
75
76
77 def OnCloseWindow(self, event):
78 print 'OnCloseWindow'
79 self.Destroy()
80
81
82 def OnSize(self, event):
83 w,h = self.GetClientSize()
84 self.canvas.SetSize(wxSize(w, h))
85 self.SetStatusText("hello, this is a test: (%d, %d)" % (w,h))
86
87## def OnMenuHighlight(self, event):
88## mainmenu = self.GetMenuBar()
89## st = mainmenu.GetHelpString(event.GetMenuId())
90## self.SetStatusText('['+st+']', 0)
91
92 def OnMenuCommand(self, event):
93 # why isn't this a wxMenuEvent???
94 print event, event.GetInt()
95 if event.GetInt() == 200:
96 self.Close()
97 elif event.GetInt() == 101:
f57d7932
RD
98 if wxPlatform == '__WXMSW__':
99 win = MyMiniFrame(self, -1, "This is a Mini...",
7bf85405
RD
100 wxPoint(-1, -1), #wxPyDefaultPosition,
101 wxSize(150, 150),
102 wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
103 wxTHICK_FRAME | wxSYSTEM_MENU |
104 wxTINY_CAPTION_HORIZ)
f57d7932
RD
105 win.Show(true)
106 else:
107 print 'Sorry, can\'t do mini\'s...'
7bf85405
RD
108
109
110
111 def OnDropFiles(self, event):
112 fileList = event.GetFiles()
113 for file in fileList:
114 print file
115
116
117#---------------------------------------------------------------------------
118
119
120class MyApp(wxApp):
121 def OnInit(self):
122 frame = MyFrame(NULL, -1, "Test 3")
123 frame.Show(true)
124 self.SetTopWindow(frame)
125 return true
126
127#---------------------------------------------------------------------------
128
129
130def main():
131 app = MyApp(0)
132 app.MainLoop()
133
134
135def t():
136 import pdb
137 pdb.run('main()')
138
139if __name__ == '__main__':
140 main()
141
142
143#----------------------------------------------------------------------------
144#
145# $Log$
f57d7932
RD
146# Revision 1.2 1998/08/22 19:51:17 RD
147# some tweaks for wxGTK
148#
7bf85405
RD
149# Revision 1.1 1998/08/09 08:28:05 RD
150# Initial version
151#
152#