|
7 | 7 | """
|
8 | 8 |
|
9 | 9 | import wx
|
| 10 | +import os |
| 11 | + |
| 12 | +#--------------------------------------------------------------------------- |
| 13 | + |
| 14 | +# This is how you pre-establish a file filter so that the dialog |
| 15 | +# only shows the extension(s) you want it to. |
| 16 | +wildcard = "Python source (*.py)|*.py|" \ |
| 17 | + "Compiled Python (*.pyc)|*.pyc|" \ |
| 18 | + "SPAM files (*.spam)|*.spam|" \ |
| 19 | + "Egg file (*.egg)|*.egg|" \ |
| 20 | + "All files (*.*)|*.*" |
| 21 | + |
| 22 | +#--------------------------------------------------------------------------- |
10 | 23 |
|
11 | 24 |
|
12 | 25 | class AppLogic(object):
|
@@ -72,8 +85,41 @@ def __init__(self, app_logic, *args, **kwargs):
|
72 | 85 |
|
73 | 86 |
|
74 | 87 | def onOpen(self, evt=None):
|
75 |
| - print "open menu selected" |
76 |
| - self.app_logic.file_open() |
| 88 | + """This method opens an existing file""" |
| 89 | + print "Open a file: " |
| 90 | + # Create the dialog. In this case the current directory is forced as the starting |
| 91 | + # directory for the dialog, and no default file name is forced. This can easilly |
| 92 | + # be changed in your program. This is an 'open' dialog, and allows multitple |
| 93 | + # file selections as well. |
| 94 | + # |
| 95 | + # Finally, if the directory is changed in the process of getting files, this |
| 96 | + # dialog is set up to change the current working directory to the path chosen. |
| 97 | + dlg = wx.FileDialog( |
| 98 | + self, message="Choose a file", |
| 99 | + defaultDir=os.getcwd(), |
| 100 | + defaultFile="", |
| 101 | + wildcard=wildcard, |
| 102 | + style=wx.OPEN | wx.CHANGE_DIR |
| 103 | + ) |
| 104 | + |
| 105 | + # Show the dialog and retrieve the user response. If it is the OK response, |
| 106 | + # process the data. |
| 107 | + if dlg.ShowModal() == wx.ID_OK: |
| 108 | + # This returns a Python list of files that were selected. |
| 109 | + path = dlg.GetPath() |
| 110 | + print "I'd be opening file in onOpen ", path |
| 111 | + self.app_logic.file_open( path ) |
| 112 | + else : |
| 113 | + print "The file dialog was canceled before anything was selected" |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + # Destroy the dialog. Don't do this until you are done with it! |
| 119 | + # BAD things can happen otherwise! |
| 120 | + dlg.Destroy() |
| 121 | + |
| 122 | + |
77 | 123 |
|
78 | 124 | def onClose(self, evt=None):
|
79 | 125 | print "close menu selected"
|
|
0 commit comments