在 FileDropTarget 上拖放文件时卡住预览图像

Stuck Preview Image on Dragging and Dropping a File on a FileDropTarget

我现在正在开发一个文档管理系统,并且正在尝试实现拖放功能,该功能允许用户将文件从 windows 资源管理器拖到我的程序中。

为此,我创建了自己的自定义放置目标:

class DocumentsDropTarget(wx.FileDropTarget):

    """Implements the ability to import a new document/file as a DB File
    by drag and drop.
    See for more info: http://wiki.wxpython.org/DragAndDrop"""

    def __init__(self, parent, import_as_db_file_method):
        wx.FileDropTarget.__init__(self)
        self.parent = parent
        self.import_as_db_file_method = import_as_db_file_method

    def OnDropFiles(self, dummy_x, dummy_y, files):
        """Makes sure that only one file is dropped. Then translates the
        dropped file into source_folder and filename and then calls the
        method for importing the file as a db file."""
        if len(files) != 1:
            show_error_message(self.parent,
                               "Documents", "MOnlyOneFilePerDBImport")
            return
        source_path = files[0]
        split_position = string.rfind(source_path, '\')
        source_folder = source_path[:split_position]
        filename = source_path[(split_position + 1):]
        self.import_as_db_file_method(source_folder=source_folder,
                                      filename=filename)

这非常有效。我的程序选择正确的 source_folder 和文件名并正确导入新文件。

问题只是在方法内部 self.import_as_db_file_method(...) 是一个对话框,它将在实际导入之前显示给用户,以便能够为导入设置一些选项。

当该对话框打开时,您无法使用 windows 资源管理器,并且拖动过程的预览图像卡在我的屏幕上。按下按钮 'Importieren' 后,方法 self.import_as_db_file_method(...) 完成,卡住的预览图像消失。

有什么方法可以告诉 windows 资源管理器我收集了我需要的所有数据并在调用 self.import_as_db_file_method(...)

之前完成拖动过程

我的对话框中卡住的预览图像示例:

我不是 100% 确定你的问题是什么,但在过去使用 wx.FileDropTarget 时,我将其编码为使用经过测试和清理的文件名设置全局变量,然后我使用 wx.Timer 每秒测试一次全局变量。
虽然这确实涉及开销,但它确实意味着在 wx.Timer 代码中,当我访问文件以进行任何我打算对其进行的操作时,拖放已经完成并且文件已经过类型等测试.