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 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)
39 button
= wxButton(panel
, ID
, "Close Me")
40 button
.SetPosition(wxPoint(15, 15))
41 self
.Connect(ID
, -1, wxEVT_COMMAND_BUTTON_CLICKED
, self
.OnCloseMe
)
43 def OnCloseMe(self
, event
):
46 def OnCloseWindow(self
, event
):
49 #---------------------------------------------------------------------------
51 class MyFrame(wxFrame
):
52 def __init__(self
, parent
, id, title
):
53 wxFrame
.__init
__(self
, parent
, id, title
, wxPyDefaultPosition
,
55 self
.canvas
= MyCanvas(self
, -1)
56 self
.CreateStatusBar(3)
57 mainmenu
= wxMenuBar()
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
)
70 self
.Connect(-1, -1, wxEVT_COMMAND_MENU_SELECTED
, self
.OnMenuCommand
)
71 self
.Connect(-1, -1, wxEVT_DROP_FILES
, self
.OnDropFiles
)
75 def OnCloseWindow(self
, event
):
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
))
85 ## def OnMenuHighlight(self, event):
86 ## mainmenu = self.GetMenuBar()
87 ## st = mainmenu.GetHelpString(event.GetMenuId())
88 ## self.SetStatusText('['+st+']', 0)
90 def OnMenuCommand(self
, event
):
91 # why isn't this a wxMenuEvent???
92 print event
, event
.GetInt()
93 if event
.GetInt() == 200:
95 elif event
.GetInt() == 101:
96 win
= MyMiniFrame(self
, -1, "This is a Mini...",
97 wxPoint(-1, -1), #wxPyDefaultPosition,
99 wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
100 wxTHICK_FRAME | wxSYSTEM_MENU |
101 wxTINY_CAPTION_HORIZ
)
106 def OnDropFiles(self
, event
):
107 fileList
= event
.GetFiles()
108 for file in fileList
:
112 #---------------------------------------------------------------------------
117 frame
= MyFrame(NULL
, -1, "Test 3")
119 self
.SetTopWindow(frame
)
122 #---------------------------------------------------------------------------
134 if __name__
== '__main__':
138 #----------------------------------------------------------------------------
141 # Revision 1.1 1998/08/09 08:28:05 RD