Search code examples
gtkwxpythonwarningsfiledialog

wxpython save file dialog gives a gtk-warning


the code here below:

#!/usr/bin/env python

import wx

class MyForm(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY,
                          "File and Folder Dialogs Tutorial")
        panel = wx.Panel(self, wx.ID_ANY)

        saveFileDlgBtn = wx.Button(panel, label="Show SAVE FileDialog")
        saveFileDlgBtn.Bind(wx.EVT_BUTTON, self.onSaveFile)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(saveFileDlgBtn, 0, wx.ALL|wx.CENTER, 5)
        panel.SetSizer(sizer)



    def onSaveFile(self, event):
        """
        Create and show the Save FileDialog
        """
        dlg = wx.FileDialog(
            self, message="Save file as ...",
            defaultDir=".",
            defaultFile="", wildcard="*.*", style=wx.SAVE
            )
        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            print path
            fp = open(path, 'w')
            fp.write("bau bau")
            fp.close()

        dlg.Destroy()


if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm()
    frame.Show()
    app.MainLoop()

gives the following message on my terminal when I try to save the file by giving a new name test.txt through the file dialog widget:

(python:16795): Gtk-WARNING **: Unable to retrieve the file info for `file:///home/roberto/python/test.txt': Error stating file '/home/roberto/python/test.txt': No such file or directory

Despite this message, the file is saved correctly, but I would like to understand why the message occurs and how to avoid it. Is this something which depends on gtk libraries installed in my system? I am running a debian testing with gtk version 2.24 and python-wxgtk2.8.

Thank you very much.

Roberto


Solution

  • I've read that some of the wxPython distros on Linux have debugging turned on, which is great for knowing why something goes wrong, but it also shows all the gtk warnings. It sounds like it's saving the file correctly, so you probably don't need to worry about it. You can ask on the wxPython mailing list for a more technical explanation.