mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-01 08:01:22 +03:00
replaced wine check, final cleanups
This commit is contained in:
parent
74372b997d
commit
175d171924
84
prefs.py
84
prefs.py
@ -1,29 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""EDMC preferences library."""
|
||||
|
||||
import contextlib
|
||||
import logging
|
||||
import tkinter as tk
|
||||
from types import TracebackType
|
||||
import webbrowser
|
||||
from os.path import exists, expanduser, expandvars, join, normpath
|
||||
from sys import platform
|
||||
from tkinter import Variable, colorchooser as tkColorChooser # type: ignore
|
||||
from tkinter import colorchooser as tkColorChooser # type: ignore # noqa: N812
|
||||
from tkinter import ttk
|
||||
from types import TracebackType
|
||||
from typing import TYPE_CHECKING, Any, Callable, Optional, Type, Union
|
||||
|
||||
import myNotebook as nb
|
||||
from myNotebook import Notebook
|
||||
import myNotebook as nb # noqa: N813
|
||||
import plug
|
||||
from config import applongname, appname, appversion, config
|
||||
from EDMCLogging import edmclogger
|
||||
from hotkey import hotkeymgr
|
||||
from l10n import Translations
|
||||
from monitor import monitor
|
||||
from myNotebook import Notebook
|
||||
from theme import theme
|
||||
from ttkHyperlinkLabel import HyperlinkLabel
|
||||
|
||||
import contextlib
|
||||
|
||||
logger = logging.getLogger(appname)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -116,6 +115,7 @@ class PrefsVersion:
|
||||
return False
|
||||
###########################################################################
|
||||
|
||||
|
||||
prefsVersion = PrefsVersion() # noqa: N816 # Cannot rename as used in plugins
|
||||
|
||||
|
||||
@ -160,6 +160,7 @@ class AutoInc(contextlib.AbstractContextManager):
|
||||
|
||||
###########################################################################
|
||||
|
||||
|
||||
if platform == 'darwin':
|
||||
import objc # type: ignore
|
||||
from Foundation import NSFileManager # type: ignore
|
||||
@ -186,44 +187,21 @@ if platform == 'darwin':
|
||||
was_accessible_at_launch = AXIsProcessTrusted() # type: ignore
|
||||
|
||||
elif platform == 'win32':
|
||||
# sigh tkFileDialog.askdirectory doesn't support unicode on Windows
|
||||
# TODO: Remove this
|
||||
import ctypes
|
||||
from ctypes.wintypes import HINSTANCE, HWND, LPARAM, LPCWSTR, LPVOID, LPWSTR, MAX_PATH, POINT, RECT, SIZE, UINT
|
||||
|
||||
SHGetLocalizedName = ctypes.windll.shell32.SHGetLocalizedName
|
||||
SHGetLocalizedName.argtypes = [LPCWSTR, LPWSTR, UINT, ctypes.POINTER(ctypes.c_int)]
|
||||
|
||||
LoadString = ctypes.windll.user32.LoadStringW
|
||||
LoadString.argtypes = [HINSTANCE, UINT, LPWSTR, ctypes.c_int]
|
||||
|
||||
# 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):
|
||||
"""
|
||||
BROWSEINFO class for use in calls to win32 file browser invocation.
|
||||
|
||||
See https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/ns-shlobj_core-browseinfoa for more
|
||||
information regarding this structure
|
||||
"""
|
||||
|
||||
_fields_ = [
|
||||
("hwndOwner", HWND),
|
||||
("pidlRoot", LPVOID),
|
||||
("pszDisplayName", LPWSTR),
|
||||
("lpszTitle", LPCWSTR),
|
||||
("ulFlags", UINT),
|
||||
("lpfn", BrowseCallbackProc),
|
||||
("lParam", LPCWSTR),
|
||||
("iImage", ctypes.c_int)
|
||||
]
|
||||
|
||||
import winreg
|
||||
from ctypes.wintypes import HINSTANCE, HWND, LPCWSTR, LPWSTR, MAX_PATH, POINT, RECT, SIZE, UINT
|
||||
is_wine = False
|
||||
try:
|
||||
WINE_REGISTRY_KEY = r'HKEY_LOCAL_MACHINE\Software\Wine'
|
||||
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
|
||||
winreg.OpenKey(reg, WINE_REGISTRY_KEY)
|
||||
is_wine = True
|
||||
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
CalculatePopupWindowPosition = None
|
||||
if not is_wine:
|
||||
CalculatePopupWindowPosition = ctypes.windll.user32.CalculatePopupWindowPosition
|
||||
CalculatePopupWindowPosition.argtypes = [
|
||||
ctypes.POINTER(POINT),
|
||||
@ -238,8 +216,11 @@ elif platform == 'win32':
|
||||
GetWindowRect = ctypes.windll.user32.GetWindowRect
|
||||
GetWindowRect.argtypes = [HWND, ctypes.POINTER(RECT)]
|
||||
|
||||
except Exception: # Not supported under Wine 4.0
|
||||
CalculatePopupWindowPosition = None
|
||||
SHGetLocalizedName = ctypes.windll.shell32.SHGetLocalizedName
|
||||
SHGetLocalizedName.argtypes = [LPCWSTR, LPWSTR, UINT, ctypes.POINTER(ctypes.c_int)]
|
||||
|
||||
LoadString = ctypes.windll.user32.LoadStringW
|
||||
LoadString.argtypes = [HINSTANCE, UINT, LPWSTR, ctypes.c_int]
|
||||
|
||||
|
||||
class PreferencesDialog(tk.Toplevel):
|
||||
@ -664,13 +645,14 @@ class PreferencesDialog(tk.Toplevel):
|
||||
nb.Label(appearance_frame, text=_('Theme')).grid(columnspan=3, padx=self.PADX, sticky=tk.W, row=row.get())
|
||||
|
||||
# Appearance theme and language setting
|
||||
nb.Radiobutton(appearance_frame, text=_('Default'), variable=self.theme, value=0, command=self.themevarchanged).grid(
|
||||
columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get()
|
||||
)
|
||||
nb.Radiobutton(
|
||||
appearance_frame, text=_('Default'), variable=self.theme, value=0, command=self.themevarchanged
|
||||
).grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get())
|
||||
|
||||
# Appearance theme setting
|
||||
nb.Radiobutton(appearance_frame, text=_('Dark'), variable=self.theme, value=1, command=self.themevarchanged).grid(
|
||||
columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get())
|
||||
nb.Radiobutton(
|
||||
appearance_frame, text=_('Dark'), variable=self.theme, value=1, command=self.themevarchanged
|
||||
).grid(columnspan=3, padx=self.BUTTONX, sticky=tk.W, row=row.get())
|
||||
|
||||
if platform == 'win32':
|
||||
nb.Radiobutton(
|
||||
@ -789,7 +771,9 @@ class PreferencesDialog(tk.Toplevel):
|
||||
|
||||
enabled_plugins = list(filter(lambda x: x.folder and x.module, plug.PLUGINS))
|
||||
if len(enabled_plugins):
|
||||
ttk.Separator(plugins_frame, orient=tk.HORIZONTAL).grid(columnspan=3, padx=self.PADX, pady=self.PADY * 8, sticky=tk.EW)
|
||||
ttk.Separator(plugins_frame, orient=tk.HORIZONTAL).grid(
|
||||
columnspan=3, padx=self.PADX, pady=self.PADY * 8, sticky=tk.EW
|
||||
)
|
||||
nb.Label(
|
||||
plugins_frame,
|
||||
text=_('Enabled Plugins')+':' # List of plugins in settings
|
||||
|
Loading…
x
Reference in New Issue
Block a user