11#!/usr/bin/env python
22
33"""
4- Example of the very basic, minimal farmework for a wxPython application
4+ Example of the very basic, minimal framework for a wxPython application
55
6- This version adds a basic menu bar with a file menu
6+ This version adds a single button
77"""
88
99import wx
1010import os
1111
12- #---------------------------------------------------------------------------
12+ #--------------------------------------------------------------
1313
1414# This is how you pre-establish a file filter so that the dialog
1515# only shows the extension(s) you want it to.
1919 "Egg file (*.egg)|*.egg|" \
2020 "All files (*.*)|*.*"
2121
22- #---------------------------------------------------------------------------
23-
22+ #--------------------------------------------------------------
2423
2524class AppLogic (object ):
2625 """
@@ -44,9 +43,6 @@ def file_close(self):
4443 print "I'd be closing a file now"
4544
4645
47-
48-
49-
5046class TestFrame (wx .Frame ):
5147 def __init__ (self , app_logic , * args , ** kwargs ):
5248 kwargs .setdefault ('title' , "Simple test App" )
@@ -56,55 +52,44 @@ def __init__(self, app_logic, *args, **kwargs):
5652
5753 # Build up the menu bar:
5854 menuBar = wx .MenuBar ()
59-
60- # Creating a file menu
55+
6156 fileMenu = wx .Menu ()
62-
63- # Creating an Open option on the file menu.
64- openMenuItem = fileMenu .Append (wx .ID_ANY , "&Open" , "Open a file" )
57+
58+ newMenuItem = fileMenu .Append (wx .ID_ANY , "&Save As..." , "Create a new file" )
59+ self .Bind (wx .EVT_MENU , self .onNew , newMenuItem )
60+
61+ openMenuItem = fileMenu .Append (wx .ID_ANY , "&Open" , "Open an existing file" )
6562 self .Bind (wx .EVT_MENU , self .onOpen , openMenuItem )
6663
67- # Creating a Close option on the file menu
6864 closeMenuItem = fileMenu .Append (wx .ID_ANY , "&Close" , "Close a file" )
6965 self .Bind (wx .EVT_MENU , self .onClose , closeMenuItem )
7066
71- # Creating an Exit option on the file menu
7267 exitMenuItem = fileMenu .Append (wx .ID_EXIT , "Exit" , "Exit the application" )
7368 self .Bind (wx .EVT_MENU , self .onExit , exitMenuItem )
74-
75- # The file menu goes on the menuBar
7669 menuBar .Append (fileMenu , "&File" )
77-
78- # Create a help menu
70+
7971 helpMenu = wx .Menu ()
80-
81- # The help menu has a single option, help.
8272 helpMenuItem = helpMenu .Append (wx .ID_HELP , "Help" , "Get help" )
83-
84- # The help menu goes on the menuBar
8573 menuBar .Append (helpMenu , "&Help" )
8674
87- # The menuBar goes on the frame.
8875 self .SetMenuBar (menuBar )
89-
76+
9077 ## add just a single button:
9178 self .theButton = wx .Button (self , label = "Push Me" )
9279 self .theButton .Bind (wx .EVT_BUTTON , self .onButton )
9380
9481 def onButton (self , evt = None ):
9582 print "You pushed the button!"
9683
84+ def onClose (self , evt = None ):
85+ print "close menu selected"
86+ self .file_close ()
9787
9888 def onExit (self , evt = None ):
9989 print "Exit the program here"
10090 print "The event passed to onExit is type " , type (evt ),
10191 self .Close ()
10292
103- def onClose (self , evt = None ):
104- print "close menu selected"
105- self .app_logic .file_close ()
106-
107-
10893 def onNew ( self , evt = None ):
10994 """This method creates a new file"""
11095
@@ -115,9 +100,12 @@ def onNew ( self, evt=None ):
115100 # Unlike the 'open dialog' example found elsewhere, this example does NOT
116101 # force the current working directory to change if the user chooses a different
117102 # directory than the one initially set.
118- dlg = wx .FileDialog (
119- self , message = "Save file as ..." , defaultDir = os .getcwd (),
120- defaultFile = "" , wildcard = wildcard , style = wx .SAVE )
103+ dlg = wx .FileDialog (self ,
104+ message = "Save file as ..." ,
105+ defaultDir = os .getcwd (),
106+ defaultFile = "" ,
107+ wildcard = wildcard ,
108+ style = wx .SAVE )
121109
122110 # This sets the default filter that the user will initially see. Otherwise,
123111 # the first filter in the list will be used by default.
@@ -150,9 +138,7 @@ def onNew ( self, evt=None ):
150138 # Destroy the dialog. Don't do this until you are done with it!
151139 # BAD things can happen otherwise!
152140 dlg .Destroy ()
153-
154141
155-
156142
157143 def onOpen (self , evt = None ):
158144 """This method opens an existing file"""
@@ -164,13 +150,13 @@ def onOpen(self, evt=None):
164150 #
165151 # Finally, if the directory is changed in the process of getting files, this
166152 # dialog is set up to change the current working directory to the path chosen.
167- dlg = wx .FileDialog (
168- self , message = "Choose a file" ,
169- defaultDir = os .getcwd (),
170- defaultFile = "" ,
171- wildcard = wildcard ,
172- style = wx .OPEN | wx .CHANGE_DIR
173- )
153+ dlg = wx .FileDialog ( self ,
154+ message = "Choose a file" ,
155+ defaultDir = os .getcwd (),
156+ defaultFile = "" ,
157+ wildcard = wildcard ,
158+ style = wx .OPEN | wx .CHANGE_DIR
159+ )
174160
175161 # Show the dialog and retrieve the user response. If it is the OK response,
176162 # process the data.
@@ -181,16 +167,17 @@ def onOpen(self, evt=None):
181167 self .app_logic .file_open ( path )
182168 else :
183169 print "The file dialog was canceled before anything was selected"
184-
185-
186-
187170
188171 # Destroy the dialog. Don't do this until you are done with it!
189172 # BAD things can happen otherwise!
190173 dlg .Destroy ()
191174
192175
193-
176+ def file_close (self ):
177+ """This method closes a file"""
178+ print "Close a file: "
179+ print "I'd be closing a file now"
180+
194181
195182class TestApp (wx .App ):
196183 def OnInit (self ):
0 commit comments