From 16c8c9cadc09841f811286dfb179d2f0520bcc1a Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 29 May 2023 13:35:45 +1000 Subject: [PATCH] Fix broken styling when path includes certain Latin1 chars https://forums.ankiweb.net/t/bug-2-1-64-the-updated-version-of-anki-is-causing-functionality-problems-with-autohotkey-and-goldendict/30575/5 --- qt/aqt/theme.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/qt/aqt/theme.py b/qt/aqt/theme.py index d820e0da6..b64b8b29b 100644 --- a/qt/aqt/theme.py +++ b/qt/aqt/theme.py @@ -108,12 +108,15 @@ class ThemeManager: return path filename = f"{name}-{'dark' if self.night_mode else 'light'}.svg" - - return ( - os.path.join(aqt_data_folder(), "qt", "icons", filename) - .replace("\\\\?\\", "") - .replace("\\", "/") - ) + path = os.path.join(aqt_data_folder(), "qt", "icons", filename) + path = path.replace("\\\\?\\", "").replace("\\", "/") + if is_win: + # Workaround for Qt bug. First attempt was percent-escaping the chars, + # but Qt can't handle that. No reports so far of this affecting + # other platforms, so it's limited to Windows for now. + # https://forum.qt.io/topic/55274/solved-qss-with-special-characters/11 + path = re.sub(r"([\u00A1-\u00FF])", r"\\\1", path) + return path def icon_from_resources(self, path: str | ColoredIcon) -> QIcon: "Fetch icon from Qt resources."