Skip to content

Commit 0e5c8c3

Browse files
committed
Added error checking to the file dialogs
1 parent 4a34a85 commit 0e5c8c3

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

week-09/code/basic_app_3.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, app_logic, *args, **kwargs):
6161

6262
fileMenu = wx.Menu()
6363

64-
newMenuItem = fileMenu.Append(wx.ID_ANY, "&New", "Create a new file")
64+
newMenuItem = fileMenu.Append(wx.ID_ANY, "&Save As...", "Create a new file")
6565
self.Bind(wx.EVT_MENU, self.onNew, newMenuItem )
6666

6767
openMenuItem = fileMenu.Append(wx.ID_ANY, "&Open", "Open an existing file" )
@@ -80,12 +80,6 @@ def __init__(self, app_logic, *args, **kwargs):
8080

8181
self.SetMenuBar(menuBar)
8282

83-
# def onNew (self, evt=None):
84-
# print "Create menu selected"
85-
# self.file_create()
86-
87-
# def onOpen(self, evt=None):
88-
# print "open menu selected"
8983

9084
def onClose(self, evt=None):
9185
print "close menu selected"
@@ -118,7 +112,7 @@ def onNew ( self, evt=None ):
118112
# process the data.
119113
if dlg.ShowModal() == wx.ID_OK:
120114
path = dlg.GetPath()
121-
115+
print "In onNew, the path is %s" % path
122116
# Normally, at this point you would save your data using the file and path
123117
# data that the user provided to you, but since we didn't actually start
124118
# with any data to work with, that would be difficult.
@@ -132,6 +126,8 @@ def onNew ( self, evt=None ):
132126
#
133127
# You might want to add some error checking :-)
134128
#
129+
else :
130+
print "The file dialog was canceled before anything was selected"
135131

136132
# Note that the current working dir didn't change. This is good since
137133
# that's the way we set it up.
@@ -166,16 +162,18 @@ def onOpen(self, evt=None):
166162
if dlg.ShowModal() == wx.ID_OK:
167163
# This returns a Python list of files that were selected.
168164
path = dlg.GetPath()
169-
165+
print "I'd be opening file in onOpen ", path
166+
self.app_logic.file_open( path )
167+
else :
168+
print "The file dialog was canceled before anything was selected"
169+
170170

171171

172172

173173
# Destroy the dialog. Don't do this until you are done with it!
174174
# BAD things can happen otherwise!
175175
dlg.Destroy()
176176

177-
print "I'd be opening file in onOpen ", path
178-
self.app_logic.file_open( path )
179177

180178
def file_close(self):
181179
"""This method closes a file"""

0 commit comments

Comments
 (0)