2 #----------------------------------------------------------------------------
4 # Purpose: Testing menus and status lines
10 # Copyright: (c) 1998 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
15 from wxPython
import *
18 #---------------------------------------------------------------------------
20 class MyCanvas(wxWindow
):
21 def OnPaint(self
, event
):
24 w
, h
= self
.GetClientSize()
25 font
= wxFont(42, wxSWISS
, wxNORMAL
, wxNORMAL
)
28 tw
,th
, d
,e
= dc
.GetTextExtent(st
)
29 dc
.DrawText(st
, (w
-tw
)/2, (h
-th
)/2)
32 #---------------------------------------------------------------------------
34 if 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)
40 button
= wxButton(panel
, ID
, "Close Me")
41 button
.SetPosition(wxPoint(15, 15))
42 self
.Connect(ID
, -1, wxEVT_COMMAND_BUTTON_CLICKED
, self
.OnCloseMe
)
44 def OnCloseMe(self
, event
):
47 def OnCloseWindow(self
, event
):
50 #---------------------------------------------------------------------------
52 class MyFrame(wxFrame
):
53 def __init__(self
, parent
, id, title
):
54 wxFrame
.__init
__(self
, parent
, id, title
, wxPyDefaultPosition
,
56 self
.canvas
= MyCanvas(self
, -1)
57 self
.CreateStatusBar(3)
58 mainmenu
= wxMenuBar()
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
)
66 if wxPlatform
== '__WXMSW__':
67 print menu
.GetHelpString(100)
68 print mainmenu
.GetHelpString(101)
69 print mainmenu
.GetHelpString(200)
70 self
.DragAcceptFiles(true
)
72 self
.Connect(-1, -1, wxEVT_COMMAND_MENU_SELECTED
, self
.OnMenuCommand
)
73 self
.Connect(-1, -1, wxEVT_DROP_FILES
, self
.OnDropFiles
)
77 def OnCloseWindow(self
, event
):
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
))
87 ## def OnMenuHighlight(self, event):
88 ## mainmenu = self.GetMenuBar()
89 ## st = mainmenu.GetHelpString(event.GetMenuId())
90 ## self.SetStatusText('['+st+']', 0)
92 def OnMenuCommand(self
, event
):
93 # why isn't this a wxMenuEvent???
94 print event
, event
.GetInt()
95 if event
.GetInt() == 200:
97 elif event
.GetInt() == 101:
98 if wxPlatform
== '__WXMSW__':
99 win
= MyMiniFrame(self
, -1, "This is a Mini...",
100 wxPoint(-1, -1), #wxPyDefaultPosition,
102 wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
103 wxTHICK_FRAME | wxSYSTEM_MENU |
104 wxTINY_CAPTION_HORIZ
)
107 print 'Sorry, can\'t do mini\'s...'
111 def OnDropFiles(self
, event
):
112 fileList
= event
.GetFiles()
113 for file in fileList
:
117 #---------------------------------------------------------------------------
122 frame
= MyFrame(NULL
, -1, "Test 3")
124 self
.SetTopWindow(frame
)
127 #---------------------------------------------------------------------------
139 if __name__
== '__main__':
143 #----------------------------------------------------------------------------
146 # Revision 1.2 1998/08/22 19:51:17 RD
147 # some tweaks for wxGTK
149 # Revision 1.1 1998/08/09 08:28:05 RD