3

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

robelix
  • 33
  • 4

2 Answers2

2

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.

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • You are probably right, I tried the same code on a different system (ubuntu machine) and no warnings appear... my only doubt is that I am developing a GUI software which will be used by end-users, so I would like to prevent any possible confusing message when they will run the application... Thanks! r. – robelix Nov 16 '11 at 10:46
  • Well, when you package it up, don't use the debug version of wx – Mike Driscoll Nov 16 '11 at 14:34
  • Is there a switch we can set somewhere to avoid this, or does this mean rebuilding the library? – Michael Clerx Mar 05 '12 at 15:57
  • I think you want the debug messages on when you're developing as it's a lot easier to track down bugs. When you actually build wxPython, you have to pass a "debug" flag to enable it though. I recall Robin Dunn mentioning that some package maintainers aren't doing that (or the reverse) so some people see the debug messages and others don't. – Mike Driscoll Mar 05 '12 at 16:08
0

Maybe Gtk is verifying by default if the file already exists, so that it doesn't get overwritten directly.