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
, d
,e
= 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
):
54 #---------------------------------------------------------------------------
56 class MyFrame(wxFrame
):
57 def __init__(self
, parent
, id, title
):
58 wxFrame
.__init
__(self
, parent
, id, title
, wxPyDefaultPosition
,
60 self
.canvas
= MyCanvas(self
, -1)
61 self
.CreateStatusBar(2)
62 mainmenu
= wxMenuBar()
64 menu
.Append(100, 'A &Menu Item', 'the help text')
65 menu
.Append(101, '&Another', 'Grok!')
66 menu
.AppendSeparator()
67 menu
.Append(200, 'E&xit', 'Get the heck outta here!')
68 mainmenu
.Append(menu
, "&It's a menu!")
69 self
.SetMenuBar(mainmenu
)
70 if wxPlatform
== '__WXMSW__':
71 print menu
.GetHelpString(100)
72 print mainmenu
.GetHelpString(101)
73 print mainmenu
.GetHelpString(200)
74 self
.DragAcceptFiles(true
)
76 self
.Connect(-1, -1, wxEVT_COMMAND_MENU_SELECTED
, self
.OnMenuCommand
)
77 self
.Connect(-1, -1, wxEVT_DROP_FILES
, self
.OnDropFiles
)
81 def OnCloseWindow(self
, event
):
86 def OnSize(self
, event
):
87 size
= self
.GetClientSize()
88 self
.canvas
.SetSize(size
)
89 self
.SetStatusText("hello, this is a test: (%d, %d)" % (size
.width
, size
.height
), 1)
91 ## def OnMenuHighlight(self, event):
92 ## mainmenu = self.GetMenuBar()
93 ## st = mainmenu.GetHelpString(event.GetMenuId())
94 ## self.SetStatusText('['+st+']', 0)
96 def OnMenuCommand(self
, event
):
97 # why isn't this a wxMenuEvent???
98 print event
, event
.GetInt()
99 if event
.GetInt() == 200:
101 elif event
.GetInt() == 101:
102 if wxPlatform
== '__WXMSW__':
103 win
= MyMiniFrame(self
, -1, "This is a Mini...",
104 wxPoint(-1, -1), #wxPyDefaultPosition,
106 wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
107 wxTHICK_FRAME | wxSYSTEM_MENU |
108 wxTINY_CAPTION_HORIZ
)
111 print 'Sorry, can\'t do mini\'s...'
115 def OnDropFiles(self
, event
):
116 fileList
= event
.GetFiles()
117 for file in fileList
:
121 #---------------------------------------------------------------------------
126 frame
= MyFrame(NULL
, -1, "Test 3")
128 self
.SetTopWindow(frame
)
131 #---------------------------------------------------------------------------
143 if __name__
== '__main__':
147 #----------------------------------------------------------------------------
150 # Revision 1.3 1998/12/15 20:44:35 RD
151 # Changed the import semantics from "from wxPython import *" to "from
152 # wxPython.wx import *" This is for people who are worried about
153 # namespace pollution, they can use "from wxPython import wx" and then
154 # prefix all the wxPython identifiers with "wx."
156 # Added wxTaskbarIcon for wxMSW.
158 # Made the events work for wxGrid.
162 # Added wxMiniFrame for wxGTK, (untested.)
164 # Changed many of the args and return values that were pointers to gdi
165 # objects to references to reflect changes in the wxWindows API.
167 # Other assorted fixes and additions.
169 # Revision 1.2 1998/08/22 19:51:17 RD
170 # some tweaks for wxGTK
172 # Revision 1.1 1998/08/09 08:28:05 RD