2 #----------------------------------------------------------------------------
4 # Purpose: Testing menus and status lines
10 # Copyright: (c) 1998 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------------
15 from wxPython
.wx
import *
18 #---------------------------------------------------------------------------
20 class MyCanvas(wxWindow
):
21 def __init__(self
, parent
, ID
):
22 wxWindow
.__init
__(self
, parent
, ID
)
23 self
.SetBackgroundColour(wxNamedColor("WHITE"))
25 def OnPaint(self
, event
):
28 size
= self
.GetClientSize()
29 font
= wxFont(42, wxSWISS
, wxNORMAL
, wxNORMAL
)
32 tw
,th
= dc
.GetTextExtent(st
)
33 dc
.DrawText(st
, (size
.width
-tw
)/2, (size
.height
-th
)/2)
36 #---------------------------------------------------------------------------
38 #if wxPlatform == '__WXMSW__':
39 class 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)
44 button
= wxButton(panel
, ID
, "Close Me")
45 button
.SetPosition(wxPoint(15, 15))
46 self
.Connect(ID
, -1, wxEVT_COMMAND_BUTTON_CLICKED
, self
.OnCloseMe
)
48 def OnCloseMe(self
, event
):
51 def OnCloseWindow(self
, event
):
53 #---------------------------------------------------------------------------
55 class MyFrame(wxFrame
):
56 def __init__(self
, parent
, id, title
):
57 wxFrame
.__init
__(self
, parent
, id, title
, wxPyDefaultPosition
,
59 self
.canvas
= MyCanvas(self
, -1)
60 self
.CreateStatusBar(2)
61 mainmenu
= wxMenuBar()
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
)
69 if wxPlatform
== '__WXMSW__':
70 print menu
.GetHelpString(100)
71 print mainmenu
.GetHelpString(101)
72 print mainmenu
.GetHelpString(200)
73 self
.DragAcceptFiles(true
)
75 self
.Connect(-1, -1, wxEVT_COMMAND_MENU_SELECTED
, self
.OnMenuCommand
)
76 self
.Connect(-1, -1, wxEVT_DROP_FILES
, self
.OnDropFiles
)
80 def OnCloseWindow(self
, event
):
85 def OnSize(self
, event
):
86 size
= self
.GetClientSize()
87 self
.canvas
.SetSize(size
)
88 self
.SetStatusText("hello, this is a test: (%d, %d)" % (size
.width
, size
.height
), 1)
90 ## def OnMenuHighlight(self, event):
91 ## mainmenu = self.GetMenuBar()
92 ## st = mainmenu.GetHelpString(event.GetMenuId())
93 ## self.SetStatusText('['+st+']', 0)
95 def OnMenuCommand(self
, event
):
96 # why isn't this a wxMenuEvent???
97 print event
, event
.GetInt()
98 if event
.GetInt() == 200:
100 elif event
.GetInt() == 101:
101 #if wxPlatform == '__WXMSW__':
102 win
= MyMiniFrame(self
, -1, "This is a Mini...",
103 wxPoint(-1, -1), #wxPyDefaultPosition,
105 wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
106 wxTHICK_FRAME | wxSYSTEM_MENU |
107 wxTINY_CAPTION_HORIZ
)
110 # print 'Sorry, can\'t do mini\'s...'
114 def OnDropFiles(self
, event
):
115 fileList
= event
.GetFiles()
116 for file in fileList
:
120 #---------------------------------------------------------------------------
125 frame
= MyFrame(NULL
, -1, "Test 3")
127 self
.SetTopWindow(frame
)
130 #---------------------------------------------------------------------------
142 if __name__
== '__main__':
146 #----------------------------------------------------------------------------
149 # Revision 1.6 1999/04/30 03:29:53 RD
150 # wxPython 2.0b9, first phase (win32)
151 # Added gobs of stuff, see wxPython/README.txt for details
153 # Revision 1.5 1999/02/20 09:04:43 RD
154 # Added wxWindow_FromHWND(hWnd) for wxMSW to construct a wxWindow from a
155 # window handle. If you can get the window handle into the python code,
156 # it should just work... More news on this later.
158 # Added wxImageList, wxToolTip.
160 # Re-enabled wxConfig.DeleteAll() since it is reportedly fixed for the
163 # As usual, some bug fixes, tweaks, etc.
165 # Revision 1.4 1998/12/16 22:12:46 RD
167 # Tweaks needed to be able to build wxPython with wxGTK.
169 # Revision 1.3 1998/12/15 20:44:35 RD
170 # Changed the import semantics from "from wxPython import *" to "from
171 # wxPython.wx import *" This is for people who are worried about
172 # namespace pollution, they can use "from wxPython import wx" and then
173 # prefix all the wxPython identifiers with "wx."
175 # Added wxTaskbarIcon for wxMSW.
177 # Made the events work for wxGrid.
181 # Added wxMiniFrame for wxGTK, (untested.)
183 # Changed many of the args and return values that were pointers to gdi
184 # objects to references to reflect changes in the wxWindows API.
186 # Other assorted fixes and additions.
188 # Revision 1.2 1998/08/22 19:51:17 RD
189 # some tweaks for wxGTK
191 # Revision 1.1 1998/08/09 08:28:05 RD