driscollis / applications_with_wxpython

Code examples for the book, Creating GUI Application with wxPython
https://www.blog.pythonlibrary.org
117 stars 26 forks source link

Chapter 7 - archive_gui2 code error #13

Closed cmcknight closed 5 years ago

cmcknight commented 5 years ago

In the book text the code reads:

 1 def on_add_file(self, event):
 2     dlg = wx.FileDialog(
 3     self, message="Choose a file",
 4         defaultDir=self.panel.current_directory,
 5         defaultFile="",
 6         wildcard=open_wildcard,
 7         style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_CHANGE_DIR
 8     )
 9     if dlg.ShowModal() == wx.ID_OK:
10         paths = dlg.GetPaths()
11         self.panel.update_display(paths)
12     dlg.Destroy()”

but line 6 has an undefined variable (open_wildcard). The correction would be to modify the code to put self in front of the variable (see below):

 1 def on_add_file(self, event):
 2     dlg = wx.FileDialog(
 3     self, message="Choose a file",
 4         defaultDir=self.panel.current_directory,
 5         defaultFile="",
 6         wildcard=self.open_wildcard,
 7         style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_CHANGE_DIR
 8     )
 9     if dlg.ShowModal() == wx.ID_OK:
10         paths = dlg.GetPaths()
11         self.panel.update_display(paths)
12     dlg.Destroy()”
driscollis commented 5 years ago

Actually open_wildcard is defined outside of the classes right after the imports at the top of the file. So self.open_wildcard would be undefined.

cmcknight commented 5 years ago

Hm, okay. It's a bit unclear where to put it in the text then. (see excerpt below):

“Copy the code from the previous example and paste it into a new a file called archiver_gui2.py. Instead of reproducing the entire file here again, in this section you will focus on what has changed. You will be only editing the MainFrame class to add a menu.

Let’s start by modifying the constructor:

 1 open_wildcard = "All files (*.*)|*.*"
 2 ”
driscollis commented 5 years ago

You are quite right. That is confusing. I will get that fixed ASAP