From 77649c4a89d2ec28a742d0d1bd61f10c1c91de0f Mon Sep 17 00:00:00 2001 From: David Brenn Date: Wed, 6 Aug 2025 18:34:55 +0200 Subject: [PATCH] chore: get preferences into ts files --- qt/aqt/preferences.py | 3 +++ qt/aqt/stats.py | 8 +++++++- ts/routes/graphs/future-due.ts | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/qt/aqt/preferences.py b/qt/aqt/preferences.py index 2f12e7f4b..a9dd53c25 100644 --- a/qt/aqt/preferences.py +++ b/qt/aqt/preferences.py @@ -370,9 +370,12 @@ class Preferences(QDialog): ) self.form.styleLabel.setVisible(not is_win) self.form.styleComboBox.setVisible(not is_win) + qconnect(self.form.resetWindowSizes.clicked, self.on_reset_window_sizes) self.form.color_blind.setChecked(self.mw.pm.color_blind()) + js_code = f"window.colorBlindMode = true;" + self.mw.web.eval(js_code) qconnect(self.form.color_blind.stateChanged, self.on_my_checkbox_changed) diff --git a/qt/aqt/stats.py b/qt/aqt/stats.py index 0b8a8a3ee..45b227e1c 100644 --- a/qt/aqt/stats.py +++ b/qt/aqt/stats.py @@ -132,11 +132,17 @@ class NewDeckStats(QDialog): pass def _on_bridge_cmd(self, cmd: str) -> bool: + print("Bridge command called:") if cmd.startswith("browserSearch"): _, query = cmd.split(":", 1) browser = aqt.dialogs.open("Browser", self.mw) browser.search_for(query) - + if cmd.startswith("getColorBlindSetting"): + print("getColorBlindSetting called") + is_color_blind = self.mw.pm.color_blind() + js_code = f"window.__setColorBlindSetting({str(is_color_blind).lower()});" + self.mw.web.eval(js_code) + return True return False def refresh(self) -> None: diff --git a/ts/routes/graphs/future-due.ts b/ts/routes/graphs/future-due.ts index 5b927a2f2..5a18cadfd 100644 --- a/ts/routes/graphs/future-due.ts +++ b/ts/routes/graphs/future-due.ts @@ -4,6 +4,7 @@ /* eslint @typescript-eslint/no-explicit-any: "off", */ +declare function pycmd(command: string): void; import type { GraphsResponse } from "@generated/anki/stats_pb"; import * as tr from "@generated/ftl"; @@ -112,8 +113,30 @@ export function buildHistogram( const adjustedRange = scaleLinear().range([0.0, 1]); const colourScale = scaleSequential((n) => interpolateViridis(adjustedRange(n)!)).domain([xMin!, xMax!]); + + getColorBlindSetting().then((setting) => { + console.log("Color Blind Setting:", setting); + }); + + + + const total = sum(bins as any, getNumericMapBinValue); + function getColorBlindSetting(): Promise { + return new Promise((resolve) => { + // Define the global callback first + (window as any).__setColorBlindSetting = (val: boolean) => { + delete (window as any).__setColorBlindSetting; // optional cleanup + resolve(val); + }; + + // Then trigger the Python call + pycmd("getColorBlindSetting"); + }); + } + + function hoverText( bin: Bin, cumulative: number, @@ -128,6 +151,9 @@ export function buildHistogram( return `${days}:
${cards}
${totalLabel}: ${localizedNumber(cumulative)}`; } + + + function onClick(bin: Bin): void { const start = bin.x0!; // x1 in last bin is inclusive