wxpython 保存文件对话框给出 gtk 警告

发布于 2024-12-14 15:03:47 字数 1547 浏览 0 评论 0原文

下面的代码:

#!/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()

当我尝试通过文件对话框小部件提供新名称 test.txt 来保存文件时,在我的终端上显示以下消息:

(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

尽管有此消息,但文件已正确保存,但我想了解原因该消息的出现以及如何避免它。这是否取决于我的系统中安装的 gtk 库?我正在使用 gtk 版本 2.24 和 python-wxgtk2.8 运行 debian 测试。

非常感谢。

罗伯托

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多情癖 2024-12-21 15:03:47

我读到,Linux 上的一些 wxPython 发行版打开了调试功能,这对于了解为什么会出现问题非常有用,但它也显示了所有 gtk 警告。听起来它正确保存了文件,所以您可能不需要担心它。您可以在 wxPython 邮件列表上询问更多技术解释。

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.

三月梨花 2024-12-21 15:03:47

也许 Gtk 默认会验证文件是否已经存在,这样它就不会被直接覆盖。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文