pygtk 拖放问题:文件到 GtkFileChooserButton

发布于 2024-12-29 19:24:11 字数 1300 浏览 1 评论 0原文

我的应用程序有一个 GtkFileChooserButton,您可以使用它来打开选择器小部件并选择单个文件..,然后对该文件执行操作。这有效。

我添加了拖拽将功能也放到按钮上。它可以工作,但是有问题。

简而言之,FileChooserButton 的第一个 dnd 会触发文件集信号,并且似乎已起作用, - 名称从“( None )”更改为文件名,然后如果您单击按钮,它会弹出一个选择器小部件,显示所选的正确文件; 但是,正如您从下面的调试输出中看到的那样,get_filename() 不会返回文件名! 无论如何,这不是第一次。

第二次将文件拖到按钮上(无论是不同的文件还是同一个文件),一切顺利,get_filename() 返回文件的姓名。为什么?

这是当我将三个文件一次一个拖到按钮上时程序的调试输出:

[on_file-set] FileChooserButton.get_filename() output:
None

[on_file-set] FileChooserButton.get_filename() output:
'/home/ryran/Desktop/priv.txt'

[on_file-set] FileChooserButton.get_filename() output:
'/home/ryran/Desktop/kinamppost'

PS:当我这样做时,第一个和第二个 dnd 实际上是同一个文件。

如果您想查看完整的应用程序,请访问 http://github.com/ryran/pyrite,我很想发布代码,但实际上没有什么可发布的!我没有执行 Drag_dest_set() 因为 FileChooserButton 已经支持 dnd。所以我所做的就是为 FileChooserButton 的文件集信号定义一个 cb 。所以呃..就是这样:

def action_chooserbtn_file_set(self, widget):
    print "[on_file-set] FileChooserButton.get_filename() output:\n{!r}\n".format(widget.get_filename())

根据记录,我也尝试与定义drag_dest_set一起执行所有这些操作,但得到了相同的结果。

还有什么可说的呢?我开始认为这是一个错误。

My app has a GtkFileChooserButton that you can use to open a chooser widget and pick a single file .. and then perform operations on that file. This works.

I've added drag & drop functionality to the button as well. It works, but it's buggy.

In short, the first dnd to the FileChooserButton triggers the file-set signal and appears to have worked, -- the name changes from "( None )" to the file's name and if you then click on the button, it pops up a chooser widget showing the proper file selected; HOWEVER, as you can see from the debug output below, get_filename() does not return the filename! Not the first time, anyway.

The second time we dnd a file onto the button (whether it's a different file or the same file again), all goes well and get_filename() returns the file's name. Why?

Here's the debug output from my program when I drag three files on to the button, one at a time:

[on_file-set] FileChooserButton.get_filename() output:
None

[on_file-set] FileChooserButton.get_filename() output:
'/home/ryran/Desktop/priv.txt'

[on_file-set] FileChooserButton.get_filename() output:
'/home/ryran/Desktop/kinamppost'

PS: When I did this, the 1st and 2nd dnd were actually the same file.

If you want to see the full app in action, it's at http://github.com/ryran/pyrite, and I'd love to post code, but there's not really anything to post!! I'm not doing drag_dest_set() because FileChooserButton already supports dnd. So ALL I'm doing is defining a cb for the FileChooserButton's file-set signal. So uhh.. here's that:

def action_chooserbtn_file_set(self, widget):
    print "[on_file-set] FileChooserButton.get_filename() output:\n{!r}\n".format(widget.get_filename())

For the record I also tried doing all this in concert with defining drag_dest_set, but came up with the same results.

What else to say? I'm starting to think this is a bug.

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

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

发布评论

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

评论(1

燕归巢 2025-01-05 19:24:11

事实证明这确实是一个 GTK+ 错误。在 IRC 上与一位开发人员交谈。他帮助我认识到了这一点,然后鼓励我发布错误报告,我照做了 -- https ://bugzilla.gnome.org/show_bug.cgi?id=669718

Turns out this really is a GTK+ bug. Talked to a developer on IRC. He helped me realize that and then encouraged me to post a bug report, which I did -- https://bugzilla.gnome.org/show_bug.cgi?id=669718

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