wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.33k stars 515 forks source link

documentation fix in wx.FileDialog python snippet #451

Closed itsayellow closed 7 years ago

itsayellow commented 7 years ago

I think I found an errata in: Phoenix/docs/sphinx/rest_substitutions/snippets/python/converted/wx.FileDialog.1.py

For the wx.FileDialog documentation

I believe the snippet wx.FileDialog1.py above should read:

def OnOpen(self, event):

            if self.contentNotSaved:

                if wx.MessageBox("Current content has not been saved! Proceed?", "Please confirm",
                                 wx.ICON_QUESTION | wx.YES_NO, self) == wx.NO:
                    return

                # else: proceed asking to the user the new file to open

            openFileDialog = wx.FileDialog(self, "Open XYZ file", "", "",
                                           "XYZ files (*.xyz)|*.xyz", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)

            if openFileDialog.ShowModal() == wx.ID_CANCEL:
                return     # the user changed idea...

            # proceed loading the file chosen by the user
            # this can be done with e.g. wxPython input streams:
            input_stream = wx.FileInputStream(openFileDialog.GetPath())

            if not input_stream.IsOk():

                wx.LogError("Cannot open file '%s'."%openFileDialog.GetPath())
                return

The difference is deleting a level of tabbing after the line # else: proceed asking to the user the new file to open

In its current state, the code would never open an open file dialog UNLESS there is contentNotSaved.

wx.Python 4.0.0b1 MacOS Sierra python3.6

RobinD42 commented 7 years ago

Please submit a PR with your change implemented.