我正在使用PyGTK的GtkFileChooserButton,它正在运行 - 但在Windows环境中看起来很奇怪。是否可以使用本机Windows文件选择器对话框?
请参阅评论以了解可能的方向。但是,如果你决定(比如我......)它不值得付出努力,这将使Gtk FileChooser更容易忍受:
def get_win_my_documents():
# based on http://stackoverflow.com/questions/3858851/python-get-windows-special-folders-for-currently-logged-in-user
# and http://stackoverflow.com/questions/6227590/finding-the-users-my-documents-path
CSIDL_PERSONAL = 5 # My Documents
# the 2 stackoverflow answers use different values for this constant!
SHGFP_TYPE_CURRENT = 0 # Get current, not default value
buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
ctypes.windll.shell32.SHGetFolderPathW(None, CSIDL_PERSONAL, None, SHGFP_TYPE_CURRENT, buf)
if os.path.isdir(buf.value):
return buf.value
else:
# fall back to simple "home" notion
return(os.path.expanduser("~"))
...
my_documents = get_win_my_documents()
chooser.set_current_folder(my_documents)
chooser.add_shortcut_folder(my_documents)
# I'm not sure if it's a general solution, but works for me...
downloads = os.path.join(os.path.expanduser("~"), "Downloads")
if os.path.isdir(downloads):
chooser.add_shortcut_folder(downloads)