简体   繁体   English

pygtk的拖放麻烦:文件到GtkFileChooserButton

[英]pygtk troubles with drag and drop: file to GtkFileChooserButton

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. 我的应用程序具有一个GtkFileChooserButton,您可以使用它打开选择器小部件并选择一个文件..然后对该文件执行操作。 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; 简而言之,FileChooserButton的第一个dnd触发文件设置信号并似乎起作用了 -名称从“(None)”更改为文件名,如果您单击按钮,它将弹出一个选择器显示选择的正确文件的小部件; HOWEVER, as you can see from the debug output below, get_filename() does not return the filename! 但是,从下面的调试输出中可以看到, get_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. 第二次将文件查找到按钮上 (无论是其他文件还是相同文件), 一切顺利, get_filename()返回文件名。 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. PS:执行此操作时,第一和第二dnd实际上是同一文件。

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!! 如果您想查看完整的应用程序,请访问http://github.com/ryran/pyrite ,我很想发布代码,但实际上没有任何内容可发布! I'm not doing drag_dest_set() because FileChooserButton already supports dnd. 我没有执行drag_dest_set(),因为FileChooserButton已经支持dnd。 So ALL I'm doing is defining a cb for the FileChooserButton's file-set signal. 所以我要做的就是为FileChooserButton的文件设置信号定义一个cb。 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. 为了记录,我还尝试通过定义drag_dest_set来完成所有这些操作,但是得出了相同的结果。

What else to say? 还有什么要说的? I'm starting to think this is a bug. 我开始认为这是一个错误。

Turns out this really is a GTK+ bug. 事实证明,这确实是GTK +错误。 Talked to a developer on IRC. 在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 他帮助我意识到了这一点,然后鼓励我发布一个错误报告,我做到了-https://bugzilla.gnome.org/show_bug.cgi?id=669718

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM