mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-13 13:52:13 +03:00
Re-instate the non-tkinter file dialog.
* This will be gated behind win32 *and* not a UTF-8 encoding. This way where we should be able to use tkinter.filedialog, we do.
This commit is contained in:
parent
b235684dd6
commit
2b65bbd768
56
prefs.py
56
prefs.py
@ -183,7 +183,7 @@ if platform == 'darwin':
|
|||||||
elif platform == 'win32':
|
elif platform == 'win32':
|
||||||
import ctypes
|
import ctypes
|
||||||
import winreg
|
import winreg
|
||||||
from ctypes.wintypes import HINSTANCE, HWND, LPCWSTR, LPWSTR, MAX_PATH, POINT, RECT, SIZE, UINT
|
from ctypes.wintypes import HINSTANCE, HWND, LPARAM, LPCWSTR, LPVOID, LPWSTR, MAX_PATH, POINT, RECT, SIZE, UINT
|
||||||
is_wine = False
|
is_wine = False
|
||||||
try:
|
try:
|
||||||
WINE_REGISTRY_KEY = r'HKEY_LOCAL_MACHINE\Software\Wine'
|
WINE_REGISTRY_KEY = r'HKEY_LOCAL_MACHINE\Software\Wine'
|
||||||
@ -194,6 +194,16 @@ elif platform == 'win32':
|
|||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# https://msdn.microsoft.com/en-us/library/windows/desktop/bb762115
|
||||||
|
BIF_RETURNONLYFSDIRS = 0x00000001
|
||||||
|
BIF_USENEWUI = 0x00000050
|
||||||
|
BFFM_INITIALIZED = 1
|
||||||
|
BFFM_SETSELECTION = 0x00000467
|
||||||
|
BrowseCallbackProc = ctypes.WINFUNCTYPE(ctypes.c_int, HWND, ctypes.c_uint, LPARAM, LPARAM)
|
||||||
|
|
||||||
|
class BROWSEINFO(ctypes.Structure):
|
||||||
|
_fields_ = [("hwndOwner", HWND), ("pidlRoot", LPVOID), ("pszDisplayName", LPWSTR), ("lpszTitle", LPCWSTR), ("ulFlags", UINT), ("lpfn", BrowseCallbackProc), ("lParam", LPCWSTR), ("iImage", ctypes.c_int)]
|
||||||
|
|
||||||
CalculatePopupWindowPosition = None
|
CalculatePopupWindowPosition = None
|
||||||
if not is_wine:
|
if not is_wine:
|
||||||
CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition
|
CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition
|
||||||
@ -868,13 +878,43 @@ class PreferencesDialog(tk.Toplevel):
|
|||||||
:param title: Title of the window
|
:param title: Title of the window
|
||||||
:param pathvar: the path to start the dialog on
|
:param pathvar: the path to start the dialog on
|
||||||
"""
|
"""
|
||||||
import tkinter.filedialog
|
import locale
|
||||||
directory = tkinter.filedialog.askdirectory(
|
|
||||||
parent=self,
|
# If encoding isn't UTF-8 we can't use the tkinter dialog
|
||||||
initialdir=expanduser(pathvar.get()),
|
current_locale = locale.getlocale(locale.LC_CTYPE)
|
||||||
title=title,
|
from sys import platform as sys_platform
|
||||||
mustexist=tk.TRUE
|
directory = None
|
||||||
)
|
if sys_platform == 'win32' and current_locale[1] not in ('utf8', 'UTF8', 'utf-8', 'UTF-8'):
|
||||||
|
def browsecallback(hwnd, uMsg, lParam, lpData):
|
||||||
|
# set initial folder
|
||||||
|
if uMsg == BFFM_INITIALIZED and lpData:
|
||||||
|
ctypes.windll.user32.SendMessageW(hwnd, BFFM_SETSELECTION, 1, lpData);
|
||||||
|
return 0
|
||||||
|
|
||||||
|
browseInfo = BROWSEINFO()
|
||||||
|
browseInfo.lpszTitle = title
|
||||||
|
browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI
|
||||||
|
browseInfo.lpfn = BrowseCallbackProc(browsecallback)
|
||||||
|
browseInfo.lParam = pathvar.get().startswith('~') and join(config.home,
|
||||||
|
pathvar.get()[2:]) or pathvar.get()
|
||||||
|
ctypes.windll.ole32.CoInitialize(None)
|
||||||
|
pidl = ctypes.windll.shell32.SHBrowseForFolderW(ctypes.byref(browseInfo))
|
||||||
|
if pidl:
|
||||||
|
path = ctypes.create_unicode_buffer(MAX_PATH)
|
||||||
|
ctypes.windll.shell32.SHGetPathFromIDListW(pidl, path)
|
||||||
|
ctypes.windll.ole32.CoTaskMemFree(pidl)
|
||||||
|
directory = path.value
|
||||||
|
else:
|
||||||
|
directory = None
|
||||||
|
|
||||||
|
else:
|
||||||
|
import tkinter.filedialog
|
||||||
|
directory = tkinter.filedialog.askdirectory(
|
||||||
|
parent=self,
|
||||||
|
initialdir=expanduser(pathvar.get()),
|
||||||
|
title=title,
|
||||||
|
mustexist=tk.TRUE
|
||||||
|
)
|
||||||
|
|
||||||
if directory:
|
if directory:
|
||||||
pathvar.set(directory)
|
pathvar.set(directory)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user