我现在正在开发一个文档管理系统,并尝试实现一个拖放功能,它允许用户将一个文件从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)
这很管用。我的程序选取正确的源文件夹和文件名并正确导入新文件。你知道吗
问题只是在方法self.import_as_db_file_method(...)
中有一个对话框,它将在实际导入之前显示给用户,以便为导入设置一些选项。你知道吗
当该对话框打开时,您不能使用windows资源管理器,拖动过程的预览图像会卡在我的屏幕上。按下“Importieren”按钮后,方法self.import_as_db_file_method(...)
完成,卡住的预览图像消失。你知道吗
在调用self.import_as_db_file_method(...)
之前,有没有办法告诉windows资源管理器我收集了所有需要的数据并完成了拖动过程
我不是100%确定您的问题是什么,但在过去使用
wx.FileDropTarget
时,我将其编码为使用已测试和清理的文件名设置全局变量,然后每秒使用wx.Timer
一次来测试全局变量。虽然这确实会带来开销,但这确实意味着在
wx.Timer
代码中,当我访问该文件时,拖放已经完成,并且该文件已经过类型测试等。你知道吗相关问题 更多 >
编程相关推荐