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