-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathconfig.py
More file actions
1302 lines (1194 loc) · 51.6 KB
/
Copy pathconfig.py
File metadata and controls
1302 lines (1194 loc) · 51.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import copy
import json
import os
from aqt import mw
from . import safe_storage
def get_collection_config(key, default=None, col=None):
"""Read add-on collection state without Anki's legacy-conf warnings."""
collection = col or getattr(mw, "col", None)
if collection is None:
return default
try:
value = collection.get_config(key)
return default if value is None else value
except (AttributeError, TypeError):
# Compatibility only for Anki versions predating Collection.get_config.
try:
return collection.conf.get(key, default)
except Exception:
return default
def set_collection_config(key, value, col=None):
"""Write add-on collection state through Anki's supported API."""
collection = col or getattr(mw, "col", None)
if collection is None:
return
try:
collection.set_config(key, value)
return
except (AttributeError, TypeError):
pass
try:
collection.conf[key] = value
collection.setMod()
except Exception:
pass
def effective_night_mode(conf=None):
"""
Return the active dark/light mode for Onigiri previews and rendered UI.
The add-on can force a theme via ``onigiriThemeMode``; when it is set to
``system`` we follow Anki's current night-mode state.
"""
if not isinstance(conf, dict):
try:
conf = get_config_readonly()
except Exception:
conf = {}
mode = str(conf.get("onigiriThemeMode", "system")).lower() if isinstance(conf, dict) else "system"
if mode in {"dark", "night", "night_mode"}:
return True
if mode in {"light", "day", "day_mode"}:
return False
try:
from aqt.theme import theme_manager
return bool(theme_manager.night_mode)
except Exception:
pass
try:
return bool(mw and mw.pm and mw.pm.night_mode())
except Exception:
return False
def themed_asset(get, base_key, is_dark, dynamic_key=None, default=""):
"""Filename for an image stored as a base key plus an optional _light/_dark pair.
"Use the same picture for both themes" is not a separate flag: it is simply
the light and dark keys being empty, so the base key answers for both. That
keeps a setting saved before the split — and a theme that only knows the
base key — working untouched, and it means the settings UI can offer a
per-asset "same for both" switch without a migration.
`get` is the caller's own config accessor (``mw.col.conf.get``,
``conf.get``, ``_col_conf_get``) so this works against a live collection, a
plain dict, or a deprecation-safe wrapper without caring which.
"""
dynamic = bool(get(dynamic_key, True)) if dynamic_key else True
if dynamic:
themed = get(f"{base_key}_{'dark' if is_dark else 'light'}", "")
if themed:
return themed
return get(base_key, default) or default
# Default settings for the add-on
DEFAULTS = {
"userName": "USER",
"statsTitle": "Welcome to Onigiri!",
"studyNowText": "Study Now",
"hideWelcomeMessage": False,
"hideAllDeckCounts": False,
"hideDeckCounts": True,
"hideNativeHeaderAndBottomBar": True,
"proHide": False,
"maxHide": False,
"flowMode": False,
"ankiweb_sync_enabled": False,
"fullHideMode": False,
"hideMacTitleBar": False,
"hideSynapseProSidebar": False,
"sidebarCollapsed": False,
"sidebarPosition": "left",
"showCongratsProfileBar": True,
"showOverviewProfileBar": True,
# Match Anki's congratulations notice: the next learning card's ready time
# plus the number of learning cards still due before the next day cutoff.
"showOverviewDueLaterNotice": True,
# Kept separately so a user can choose where the next-learning notice
# appears. The older showOverviewDueLaterNotice key is migrated below.
"showNextLearningCardNoticeOnCongrats": True,
"showNextLearningCardNoticeOnOverview": True,
"congratsMessage": "Congratulations! You have finished this deck for now.",
"showWelcomePopup": True,
"onigiriThemeMode": "system",
"prep_station": {
"plans": [],
},
"hashi_notes": {
"retention_default": 30,
"custom_css": "",
"default_sort": "age",
"trash_grace_days": 7,
"show_in_reviewer_header": True,
},
"onigiri_pomodoro_show_in_reviewer_header": True,
"userBirthday": "", # Format: YYYY-MM-DD, empty = not set
"lastBirthdayShown": "", # Year when birthday popup was last shown
"hideRetentionStars": False,
"showHeatmapOnProfile": True,
"onigiriProfile": {
"bio": "",
"status": "",
"musicLink": "",
"spotifyLink": ""
},
"achievements": {
"enabled": False,
"earned": {},
"history": [],
"last_refresh": None,
"snapshot": {},
"custom_goals": {
"last_modified_at": None,
"daily": {
"enabled": False,
"target": 100,
"last_notified_day": None,
"completion_count": 0,
},
"weekly": {
"enabled": False,
"target": 700,
"last_notified_week": None,
"completion_count": 0,
},
},
# --- ADDED: focusDango nested inside achievements ---
"focusDango": {
"enabled": False,
"message": "Focus Dango wants you to focus!",
"messages": ["Focus Dango wants you to focus!"],
"self_sabotage": False,
"unlock_pin": "000000",
},
# --- END ADDITION ---
},
"restaurant_level": {
"enabled": False,
"name": "Nook Level",
"total_xp": 0,
"level": 0,
"difficulty": "Apprendice",
"notifications_enabled": True,
"show_profile_bar_progress": True,
"show_profile_page_progress": True,
"show_reviewer_header": True,
},
"daily_special": {
"enabled": True,
"current_progress": 0,
"target": 100, # Default target of 100 reviews for the daily special
"last_updated": None,
"last_notified_milestone": 0
},
"mochi_messages": {
"enabled": False,
"cards_interval": 15,
"icon_choice": "mochi",
"custom_icon": "",
"text_color": "",
"font": "system",
"messages": [
"Mochi is rooting for you — keep going!",
"Great pace! Mochi loves your dedication.",
"Deep breath. Mochi knows you've got this!",
"Mochi is cheering for you! Keep it up!",
"Wow, look at you go! A true review master.",
"Mochi is so proud of you! Keep it going!",
"Each review is a step closer to your goal. You've got this!",
],
},
"onigimon": {
"enabled": False,
"difficulty": "pikachu",
"reward_interval": 4,
"reward_generosity": "normal",
"sprite_source": "ankimon_then_pokesprite",
"sprite_motion": "static",
"scene_background_color": "#6ea96a",
"scene_background_image": "",
"scene_background_blur": 9,
"scene_background_opacity": 90,
# Empty = use the widget's own light/dark stats-panel shade.
"scene_bottom_color": "",
"allow_ankimon_updates": True,
# How gently Onigimon words its notifications: "lillipup" (kind),
# "herdier" (serious) or "stoutland" (blunt). See gamification/onigimon.py.
"notification_tone": "herdier",
},
"hexagon_land": {
"enabled": False,
"theme": "island",
"sounds_enabled": True,
},
"heatmapShape": "square.svg",
"heatmapStreakIcon": "system:fire.svg",
"heatmapStreakIconColor": "#ff6b35",
"heatmapStreakIconZeroColor": "#8f8f8f",
"heatmapShowStreak": True,
"heatmapShowMonths": True,
"heatmapShowWeekdays": True,
"heatmapShowWeekHeader": True,
"heatmapDefaultView": "year",
"heatmapWeekStart": "monday",
"markerColors": {
"red": "#FF4B4B",
"blue": "#4488FF",
"green": "#44BB66",
"yellow": "#FFB800",
},
"onigiriWidgetLayout": {
"grid": {
"stats_title": {"pos": 0, "row": 1, "col": 4},
"studied": {"pos": 4, "row": 1, "col": 1},
"time": {"pos": 5, "row": 1, "col": 1},
"pace": {"pos": 6, "row": 1, "col": 1},
"retention": {"pos": 7, "row": 1, "col": 1},
"heatmap": {"pos": 8, "row": 2, "col": 4}
},
"archive": ["favorites", "onigimon", "hexagon_land", "deck_stats", "prep_station", "hashi_notes"],
"grid_width": 230,
"grid_alignment": "center",
"widget_height": 120,
},
"externalWidgetLayout": {},
"onigiriDecklineAutoEmbed": True,
# --- NEW: Sidebar Action Buttons Mode ---
# "list" (default), "collapsed" (toolbar icons), "archived" (hidden)
"sidebarActionsMode": "list",
# Dashed call-to-action outline around the sidebar "Add" button (list mode).
"sidebarAddDashed": False,
# --- ADDED: Sidebar Button Layout ---
"sidebarButtonLayout": {
"visible": [
"profile",
"add",
"browse",
"stats",
"sync",
"settings",
"gamification",
"more"
],
"archived": []
},
# --- NEW: Reviewer Background Settings ---
"onigiri_reviewer_bg_mode": "main", # "main", "color", "image_color"
# --- Fonts ---
"onigiri_font_main": "system",
"onigiri_font_subtle": "system",
"onigiri_font_small_title": "system",
"onigiri_font_size_main": 14,
"onigiri_font_size_subtle": 20,
"onigiri_font_size_small_title": 15,
# -------------
"onigiri_reviewer_bg_main_blur": 0, # Blur when using main background
"onigiri_reviewer_bg_main_opacity": 100, # Opacity when using main background
"onigiri_reviewer_bg_light_color": "#f2f2f2",
"onigiri_reviewer_bg_dark_color": "#2C2C2C",
"onigiri_reviewer_bg_image": "",
"onigiri_reviewer_bg_image_light": "",
"onigiri_reviewer_bg_image_dark": "",
"onigiri_reviewer_bg_image_mode": "single", # "single" or "separate"
"onigiri_reviewer_bg_color_theme_mode": "separate",
"onigiri_reviewer_bg_image_theme_mode": "separate",
"onigiri_reviewer_bg_blur": 0,
"onigiri_reviewer_bg_opacity": 100,
"onigiri_reviewer_slideshow_images": [],
"onigiri_reviewer_slideshow_interval": 10,
# --- Reviewer Notification Position ---
"onigiri_reviewer_notification_mode": "classic", # "classic" or "mini"
"onigiri_reviewer_notification_position": "top-center", # top-left, top-center, top-right, bottom-left, bottom-center, bottom-right
"onigiri_reviewer_silent_notifications": False,
"onigiri_notification_duration_ms": 5200,
# --- Reviewer Bottom Bar Settings ---
"onigiri_reviewer_bottom_bar_bg_mode": "match_reviewer_bg", # "main", "color", "image", "image_color", "match_overview_bg", "match_reviewer_bg"
"onigiri_reviewer_bottom_bar_bg_light_color": "#f2f2f2",
"onigiri_reviewer_bottom_bar_bg_dark_color": "#2C2C2C",
"onigiri_reviewer_bottom_bar_bg_image": "",
"onigiri_reviewer_bottom_bar_bg_blur": 0,
"onigiri_reviewer_bottom_bar_bg_opacity": 100,
"onigiri_reviewer_bottom_bar_match_main_blur": 0,
"onigiri_reviewer_bottom_bar_match_main_opacity": 100,
"onigiri_reviewer_bottom_bar_match_reviewer_bg_blur": 0,
"onigiri_reviewer_bottom_bar_match_reviewer_bg_opacity": 100,
"onigiri_reviewer_bottom_bar_match_overview_bg_blur": 0,
"onigiri_reviewer_bottom_bar_match_overview_bg_opacity": 100,
"restaurant_countdown_hour": 4, # Default to 4 AM
"restaurant_countdown_minute": 0, # Default to 0 minutes
# --- NEW: Overviewer Background Settings ---
"onigiri_overview_bg_mode": "main", # "main", "color", "image_color"
"onigiri_overview_bg_main_blur": 0,
"onigiri_overview_bg_main_opacity": 100,
"onigiri_overview_bg_light_color": "#f2f2f2",
# The following lines appear to be UI setup code and cannot be directly inserted into a dictionary.
# Assuming the intent was to add a default for 'onigiri_reviewer_btn_custom_enabled' if not already present.
# The other lines are likely from a different context (e.g., a settings dialog setup).
"onigiri_reviewer_btn_border_size": 0,
"onigiri_reviewer_btn_custom_enabled": True, # Global toggle (Default OFF)
"language": "English (Default)",
"deck_indentation_mode": "default", # default, smaller, bigger, custom
"deck_indentation_custom_px": 20, # px per level
"onigiri_reviewer_btn_radius": 12, # px
"onigiri_reviewer_btn_padding": 5, # px (affects size)
"onigiri_reviewer_btn_height": 40, # px (button height)
"onigiri_reviewer_bar_height": 60, # px (default height)
# --- Reviewer header progress bar ---
# The "end of the tunnel" gauge in the reviewer header. `left` mirrors the
# bottom bar's new/learning/review counts; `done` is either this session's
# answers or today's whole revlog for the deck (see progress_scope).
"onigiri_reviewer_progress_enabled": True,
"onigiri_reviewer_progress_style": "bar", # bar | segments | ring | text
"onigiri_reviewer_progress_label": "fraction", # fraction | percent | remaining | done | none
"onigiri_reviewer_progress_scope": "session", # session | today
"onigiri_reviewer_progress_position": "right", # right | left
"onigiri_reviewer_progress_width": 96, # px, bar/segments only
"onigiri_reviewer_progress_thickness": 6, # px
"onigiri_reviewer_progress_radius": 999, # px
"onigiri_reviewer_progress_ring_size": 16, # px, ring only
"onigiri_reviewer_progress_chrome": True, # draw the button-style chip behind it
"onigiri_reviewer_progress_animate": True,
"onigiri_reviewer_progress_gradient": True,
"onigiri_reviewer_progress_hide_when_done": False,
"onigiri_reviewer_progress_fill_light": "#19c96b",
"onigiri_reviewer_progress_fill_dark": "#12b765",
"onigiri_reviewer_progress_fill_end_light": "#5ad6f0",
"onigiri_reviewer_progress_fill_end_dark": "#4bc4de",
"onigiri_reviewer_progress_track_light": "rgba(0, 0, 0, 0.12)",
"onigiri_reviewer_progress_track_dark": "rgba(255, 255, 255, 0.16)",
"onigiri_reviewer_progress_text_light": "#2c2c2c",
"onigiri_reviewer_progress_text_dark": "#e8e8e8",
# "counts" borrows the very colours the count bubbles use, so the segmented
# gauge and the bottom bar agree on what blue/red/green mean.
"onigiri_reviewer_progress_segment_source": "counts", # counts | custom
"onigiri_reviewer_progress_seg_new_light": "#1e8cff",
"onigiri_reviewer_progress_seg_new_dark": "#0a84ff",
"onigiri_reviewer_progress_seg_learn_light": "#ff5757",
"onigiri_reviewer_progress_seg_learn_dark": "#ff453a",
"onigiri_reviewer_progress_seg_review_light": "#19c96b",
"onigiri_reviewer_progress_seg_review_dark": "#12b765",
"onigiri_reviewer_btn_interval_color_light": "#555555",
"onigiri_reviewer_btn_interval_color_dark": "#dddddd",
"onigiri_reviewer_btn_border_color_light": "#DBDBDB",
"onigiri_reviewer_btn_border_color_dark": "#444444",
"onigiri_reviewer_btn_again_bg_light": "#ffb3b3",
"onigiri_reviewer_btn_again_text_light": "#4d0000",
"onigiri_reviewer_btn_again_bg_dark": "#ffcccb",
"onigiri_reviewer_btn_again_text_dark": "#4a0000",
"onigiri_reviewer_btn_hard_bg_light": "#ffe0b3",
"onigiri_reviewer_btn_hard_text_light": "#4d2600",
"onigiri_reviewer_btn_hard_bg_dark": "#ffd699",
"onigiri_reviewer_btn_hard_text_dark": "#4d1d00",
"onigiri_reviewer_btn_good_bg_light": "#b3ffb3",
"onigiri_reviewer_btn_good_text_light": "#004d00",
"onigiri_reviewer_btn_good_bg_dark": "#90ee90",
"onigiri_reviewer_btn_good_text_dark": "#004000",
"onigiri_reviewer_btn_easy_bg_light": "#b3d9ff",
"onigiri_reviewer_btn_easy_text_light": "#00264d",
"onigiri_reviewer_btn_easy_bg_dark": "#add8e6",
"onigiri_reviewer_btn_easy_text_dark": "#002952",
# --- Other Bottom Bar Buttons (Show Answer, Edit, More, etc.) ---
"onigiri_reviewer_other_btn_bg_light": "#ffffff",
"onigiri_reviewer_other_btn_text_light": "#2c2c2c",
"onigiri_reviewer_other_btn_bg_dark": "#3a3a3a",
"onigiri_reviewer_other_btn_text_dark": "#e0e0e0",
"onigiri_reviewer_other_btn_hover_bg_light": "#2c2c2c",
"onigiri_reviewer_other_btn_hover_text_light": "#f0f0f0",
"onigiri_reviewer_other_btn_hover_bg_dark": "#e0e0e0",
"onigiri_reviewer_other_btn_hover_text_dark": "#3a3a3a",
# --- Stats Bar Background (timer + New/Learn/Review pills panel behind the
# Show Answer button). Independent color, unless synced with the "Other"
# hover background above. ---
"onigiri_reviewer_show_answer_bar_bg_sync": True,
"onigiri_reviewer_show_answer_bar_bg_light": "#2c2c2c",
"onigiri_reviewer_show_answer_bar_bg_dark": "#e0e0e0",
# --- Stat Text (.stattxt) Colors (intervals like "10m", "4d" and "+" signs) ---
"onigiri_reviewer_stattxt_mode": "hover", # "hover" | "inverted" | "fixed" | "off"
"onigiri_reviewer_stattxt_color_light": "#666666",
"onigiri_reviewer_stattxt_color_dark": "#aaaaaa",
# --- Timer (deck options "Show answer timer") adaptation ---
"onigiri_reviewer_timer_position": "right", # "right" | "left" | "out" | "off"
"onigiri_reviewer_timer_bg_light": "#e5e5e5",
"onigiri_reviewer_timer_text_light": "#2c2c2c",
"onigiri_reviewer_timer_bg_dark": "#3a3a3a",
"onigiri_reviewer_timer_text_dark": "#e0e0e0",
"onigiri_overview_bg_dark_color": "#2C2C2C",
"onigiri_overview_bg_image_light": "",
"onigiri_overview_bg_image_dark": "",
"onigiri_overview_bg_image": "",
"onigiri_overview_bg_image_mode": "single",
"onigiri_overview_bg_blur": 0,
"onigiri_overview_bg_opacity": 100,
"onigiri_overview_bg_color_theme_mode": "separate",
"onigiri_overview_bg_image_theme_mode": "separate",
"onigiri_overview_slideshow_images": [],
"onigiri_overview_slideshow_interval": 10,
"overview_style": {
"sync_box_effect": False,
"dynamic": True,
"blur": 0,
"opacity": 100,
"radius": 20,
"stroke": 1,
"study_button_opacity": 100,
"study_button_stroke": 0,
"study_button_dashed": False,
"study_button_animated": True,
"colors": {
"light": {
"box_bg": "#f3f3f3",
"box_border": "#e0e0e0",
"study_button": "#0077C8",
"study_button_stroke": "#e0e0e0",
"options_button": "#f5f5f5",
"custom_study_button": "#f5f5f5",
"description_button": "#f5f5f5",
"reveal_button": "#0077C8",
"new_bubble": "#1e8cff",
"new_text": "#ffffff",
"learn_bubble": "#ff5757",
"learn_text": "#ffffff",
"review_bubble": "#19c96b",
"review_text": "#ffffff",
},
"dark": {
"box_bg": "#2c2c2c",
"box_border": "#565656",
"study_button": "#0077C8",
"study_button_stroke": "#565656",
"options_button": "#2a2a2a",
"custom_study_button": "#2a2a2a",
"description_button": "#2a2a2a",
"reveal_button": "#0a84ff",
"new_bubble": "#0077C8",
"new_text": "#f7fbff",
"learn_bubble": "#ff453a",
"learn_text": "#fff5f5",
"review_bubble": "#12b765",
"review_text": "#f4fff8",
},
},
},
# Today's Stats widgets (Studied / Time / Pace / Retention) look & colors.
#
# "design" picks the card layout:
# "minimal" - label + value only, left aligned, tight. Closest to the
# original cards but better distributed.
# "expressive" - icon chip, oversized value, unit suffix and an optional
# 7-day sparkline; each widget carries its own accent.
"stats_widgets_style": {
"design": "minimal",
"sync_box_effect": True,
"dynamic": True,
"blur": 0,
"opacity": 100,
"radius": 20,
"stroke": 1,
# Font key from fonts.py, or "sync" to keep inheriting the Small Titles
# / Titles fonts like every other widget.
"font": "sync",
"show_icons": True,
"show_units": True,
"show_sparkline": True,
# Expressive only: the tinted linear-gradient wash behind each card.
"show_wash": True,
# Expressive only: how the 7-day trend line is drawn.
# "sharp" - straight segments between days, angular corners.
# "smooth" - a Catmull-Rom curve through the same points.
"chart_shape": "sharp",
"show_retention_stars": True,
# Value type scale, in percent of the design's base size.
"value_scale": 100,
"icons": {
"studied": "system:check.svg",
"time": "system:pomodoro.svg",
"pace": "system:bolt.svg",
"retention": "system:star.svg",
},
"colors": {
"light": {
"box_bg": "#ffffff",
"box_border": "#e0e0e0",
"label": "#757575",
"value": "#212121",
"studied": "#5eaadf",
"time": "#8b7bd8",
"pace": "#f5a05a",
"retention": "#26a641",
"retention_star": "#FFD700",
"retention_star_empty": "#e0e0e0",
},
"dark": {
"box_bg": "#2c2c2c",
"box_border": "#424242",
"label": "#9c9c9c",
"value": "#f0f0f0",
"studied": "#6bb6ec",
"time": "#a294ea",
"pace": "#f7ad6b",
"retention": "#35b850",
"retention_star": "#FFD700",
"retention_star_empty": "#4a4a4a",
},
},
},
# Hashi Notes dashboard widget. "gallery" shows a small card grid of recent
# notes; "single" pins one note and shows a longer excerpt.
"hashi_widget_style": {
"mode": "gallery",
"note_id": "",
"limit": 4,
"show_excerpt": True,
"show_icon": True,
"show_date": True,
"sync_box_effect": True,
"dynamic": True,
"blur": 0,
"opacity": 100,
"radius": 20,
"stroke": 1,
"colors": {
"light": {
"box_bg": "#ffffff",
"box_border": "#e0e0e0",
"card_bg": "#f5f5f5",
"title": "#212121",
"excerpt": "#757575",
"accent": "#0077C8",
},
"dark": {
"box_bg": "#2c2c2c",
"box_border": "#424242",
"card_bg": "#363636",
"title": "#f0f0f0",
"excerpt": "#9c9c9c",
"accent": "#4da3e8",
},
},
},
# Deck Stats widget (learner_stats_widget) look & colors. The category
# colors default to Anki's own Card Counts palette so an untouched install
# matches the native graph.
"deck_stats_style": {
# "minimal" keeps the In Progress / Mastered grouping; "full" drops it
# and charts every card category on its own.
"chart_type": "minimal",
"sync_box_effect": True,
"dynamic": True,
"blur": 0,
"opacity": 100,
"radius": 20,
"stroke": 1,
"colors": {
"light": {
"box_bg": "#ffffff",
"box_border": "#e0e0e0",
"in_progress": "#5eaadf",
"mastered": "#26a641",
"new": "#5eaadf",
"learning": "#f5a05a",
"relearning": "#f4685f",
"young": "#7cc87c",
"mature": "#26a641",
"unseen": "#b0b4b9",
"suspended": "#ffdc41",
"buried": "#9e9e9e",
"total": "#6f7177",
},
"dark": {
"box_bg": "#2c2c2c",
"box_border": "#424242",
"in_progress": "#6bb6ec",
"mastered": "#35b850",
"new": "#6bb6ec",
"learning": "#f7ad6b",
"relearning": "#f8776e",
"young": "#8ad48a",
"mature": "#35b850",
"unseen": "#7a7f85",
"suspended": "#ffe066",
"buried": "#a8a8a8",
"total": "#c4c4c4",
},
},
},
# -----------------------------------------
# --- REMOVED: Top-level focusDango was here ---
"colors": {
"light": {
"--accent-color": "#0077C8",
"--bg": "#f3f3f3",
"--fg": "#212121",
"--icon-color": "#333333",
"--icon-color-filtered": "#0077C8",
"--fg-subtle": "#757575",
"--font-small-title-color": "#212121",
"--border": "#e0e0e0",
"--highlight-bg": "#eeeeee",
"--canvas-inset": "#ffffff",
"--button-primary-bg": "#0077C8",
"--button-primary-gradient-start": "#00C49A",
"--button-primary-gradient-end": "#008E72",
"--new-count-bubble-bg": "#a3c5e8",
"--new-count-bubble-fg": "#13375b",
"--learn-count-bubble-bg": "#e8a3a3",
"--learn-count-bubble-fg": "#731717",
"--review-count-bubble-bg": "#a3e8b8",
"--review-count-bubble-fg": "#1b7a38",
"--heatmap-color": "#0077C8",
"--heatmap-color-zero": "#f0f0f0",
"--star-color": "#FFD700",
"--empty-star-color": "#e0e0e0",
"--stats-fg": "#212121",
# Shadow and overlay colors
"--shadow-sm": "rgba(0, 0, 0, 0.1)",
"--shadow-md": "rgba(0, 0, 0, 0.1)",
"--shadow-lg": "rgba(0, 0, 0, 0.1)",
"--overlay-dark": "rgba(0, 0, 0, 0.4)",
"--overlay-light": "rgba(0, 0, 0, 0.4)",
# Profile page specific colors
"--profile-page-bg": "#d9d9d9",
"--profile-card-bg": "#FFFFFF",
"--profile-pill-placeholder-bg": "rgba(0, 0, 0, 0.2)",
"--profile-export-btn-bg": "rgba(255, 255, 255, 1)",
"--profile-export-btn-fg": "#374151",
"--profile-export-btn-border": "rgba(0, 0, 0, 0.1)",
"--overlay-close-btn-bg": "#e0e0e0",
"--overlay-close-btn-fg": "#333333",
# Deck list specific colors
"--deck-hover-bg": "rgba(128, 128, 128, 0.1)",
"--deck-dragging-bg": "#cde4f9",
"--deck-edit-mode-bg": "rgba(128, 128, 128, 0.05)",
# Text shadow colors
"--text-shadow-light": "rgba(0, 0, 0, 0.5)",
"--profile-pic-border": "rgba(255, 255, 255, 0.8)",
},
"dark": {
"--accent-color": "#0077C8",
"--bg": "#2c2c2c",
"--fg": "#e0e0e0",
"--icon-color": "#E0E0E0",
"--icon-color-filtered": "#0077C8",
"--fg-subtle": "#9e9e9e",
"--font-small-title-color": "#e0e0e0",
"--border": "#424242",
"--highlight-bg": "#3c3c3c",
"--canvas-inset": "#2c2c2c",
"--button-primary-bg": "#0077C8",
"--button-primary-gradient-start": "#00C49A",
"--button-primary-gradient-end": "#008E72",
"--new-count-bubble-bg": "#68a0d9",
"--new-count-bubble-fg": "#13375b",
"--learn-count-bubble-bg": "#d96868",
"--learn-count-bubble-fg": "#731717",
"--review-count-bubble-bg": "#68d98a",
"--review-count-bubble-fg": "#1b7a38",
"--heatmap-color": "#0077C8",
"--heatmap-color-zero": "#3a3a3a",
"--star-color": "#FFD700",
"--empty-star-color": "#4a4a4a",
"--stats-fg": "#e0e0e0",
# Shadow and overlay colors
"--shadow-sm": "rgba(0, 0, 0, 0.1)",
"--shadow-md": "rgba(0, 0, 0, 0.15)",
"--shadow-lg": "rgba(0, 0, 0, 0.4)",
"--overlay-dark": "rgba(0, 0, 0, 0.7)",
"--overlay-light": "rgba(0, 0, 0, 0.4)",
# Profile page specific colors
"--profile-page-bg": "#1f1f1f",
"--profile-card-bg": "#1e1e1e",
"--profile-pill-placeholder-bg": "rgba(0, 0, 0, 0.2)",
"--profile-export-btn-bg": "rgba(255, 255, 255, 1)",
"--profile-export-btn-fg": "#374151",
"--profile-export-btn-border": "rgba(0, 0, 0, 0.1)",
"--overlay-close-btn-bg": "#e0e0e0",
"--overlay-close-btn-fg": "#333333",
# Deck list specific colors
"--deck-hover-bg": "rgba(128, 128, 128, 0.1)",
"--deck-dragging-bg": "#3a3a3a",
"--deck-edit-mode-bg": "rgba(128, 128, 128, 0.05)",
# Text shadow colors
"--text-shadow-light": "rgba(0, 0, 0, 0.5)",
"--profile-pic-border": "rgba(255, 255, 255, 0.8)",
}
}
}
def normalize_overview_style_defaults(conf):
"""Migrate legacy dynamic Overviewer colors whose dark defaults matched light."""
overview_style = conf.get("overview_style")
if not isinstance(overview_style, dict):
return conf
colors = overview_style.get("colors")
if not isinstance(colors, dict):
return conf
light_colors = colors.get("light")
dark_colors = colors.get("dark")
if not isinstance(light_colors, dict) or not isinstance(dark_colors, dict):
return conf
defaults = DEFAULTS.get("overview_style", {}).get("colors", {})
default_light = defaults.get("light", {})
default_dark = defaults.get("dark", {})
legacy_light_values = {
key: {str(value).lower()}
for key, value in default_light.items()
if isinstance(value, str)
}
legacy_light_values.setdefault("box_bg", set()).add("#e0e0e0")
for key, dark_default in default_dark.items():
light_value = light_colors.get(key)
dark_value = dark_colors.get(key)
if not isinstance(light_value, str) or not isinstance(dark_value, str):
continue
if dark_value.lower() != light_value.lower():
continue
if light_value.lower() not in legacy_light_values.get(key, set()):
continue
if dark_value.lower() != str(dark_default).lower():
dark_colors[key] = dark_default
return conf
def normalize_learning_review_color_roles(conf):
"""Swap the former default Learning/Review color roles once.
Only the exact old default pair is migrated. If either bubble was changed
by the user, both values are preserved as an intentional custom palette.
"""
colors = conf.get("overview_style", {}).get("colors", {})
if not isinstance(colors, dict):
return conf
legacy = {
"light": {
"learn_bubble": "#19c96b",
"learn_text": "#ffffff",
"review_bubble": "#ff5757",
"review_text": "#ffffff",
},
"dark": {
"learn_bubble": "#12b765",
"learn_text": "#f4fff8",
"review_bubble": "#ff453a",
"review_text": "#fff5f5",
},
}
defaults = DEFAULTS.get("overview_style", {}).get("colors", {})
for mode, old in legacy.items():
palette = colors.get(mode)
new = defaults.get(mode, {})
if not isinstance(palette, dict) or not isinstance(new, dict):
continue
if (
str(palette.get("learn_bubble", "")).lower() == old["learn_bubble"].lower()
and str(palette.get("review_bubble", "")).lower() == old["review_bubble"].lower()
):
for key in ("learn_bubble", "learn_text", "review_bubble", "review_text"):
if key in new:
palette[key] = new[key]
return conf
def normalize_accent_color_defaults(conf):
"""Move saved legacy blue defaults to the current default accent."""
legacy_color_defaults = {
"light": {
"--accent-color": "#007aff",
"--icon-color-filtered": "#007aff",
"--button-primary-bg": "#007aff",
"--button-primary-gradient-start": "#0088ff",
"--button-primary-gradient-end": "#0065c7",
"--heatmap-color": "#007aff",
},
"dark": {
"--accent-color": "#0a84ff",
"--icon-color-filtered": "#0a84ff",
"--button-primary-bg": "#0a84ff",
"--button-primary-gradient-start": "#0a94ff",
"--button-primary-gradient-end": "#0a74d9",
"--heatmap-color": "#0a84ff",
},
}
colors = conf.get("colors")
if isinstance(colors, dict):
for mode, legacy_values in legacy_color_defaults.items():
palette = colors.get(mode)
defaults = DEFAULTS.get("colors", {}).get(mode, {})
if not isinstance(palette, dict):
continue
for key, legacy_value in legacy_values.items():
value = palette.get(key)
default_value = defaults.get(key)
if (
isinstance(value, str)
and isinstance(default_value, str)
and value.lower() == legacy_value.lower()
):
palette[key] = default_value
legacy_overview_defaults = {
("light", "study_button"): "#007aff",
("dark", "study_button"): "#0a84ff",
("dark", "new_bubble"): "#0a84ff",
}
overview_colors = conf.get("overview_style", {}).get("colors", {})
if isinstance(overview_colors, dict):
overview_defaults = DEFAULTS.get("overview_style", {}).get("colors", {})
for (mode, key), legacy_value in legacy_overview_defaults.items():
palette = overview_colors.get(mode)
default_value = overview_defaults.get(mode, {}).get(key)
if not isinstance(palette, dict) or not isinstance(default_value, str):
continue
value = palette.get(key)
if isinstance(value, str) and value.lower() == legacy_value.lower():
palette[key] = default_value
return conf
def _widget_layout_occupied_cells(grid_conf, col_count, skip_id=None):
"""Every (row, col) cell the grid's widgets currently cover."""
cells = set()
for widget_id, widget_conf in grid_conf.items():
if widget_id == skip_id or not isinstance(widget_conf, dict):
continue
try:
pos = int(widget_conf.get("pos", 0))
row_span = max(1, int(widget_conf.get("row", 1)))
col_span = max(1, int(widget_conf.get("col", 1)))
except (TypeError, ValueError):
continue
row, col = divmod(max(0, pos), col_count)
for r in range(row, row + row_span):
for c in range(col, min(col + col_span, col_count)):
cells.add((r, c))
return cells
def _place_stats_title_widget(layout_conf):
"""Keep the Stats Title widget on a free slot.
It used to render above the grid, so layouts saved before it became a
widget have nothing reserved for it and the default position collides with
whatever already sits there. CSS grid would silently stack them, so move it
to the first free run of cells instead.
"""
grid_conf = layout_conf.get("grid")
if not isinstance(grid_conf, dict):
return
title_conf = grid_conf.get("stats_title")
if not isinstance(title_conf, dict):
return
try:
col_count = int(layout_conf.get("column_count", 4))
except (TypeError, ValueError):
col_count = 4
if col_count < 1:
# Sidebar-only mode renders no grid at all; leave the config untouched.
return
title_conf["row"] = 1
try:
col_span = int(title_conf.get("col", 4))
except (TypeError, ValueError):
col_span = 4
col_span = max(1, min(col_count, col_span))
title_conf["col"] = col_span
occupied = _widget_layout_occupied_cells(grid_conf, col_count, skip_id="stats_title")
def fits(candidate):
row, col = divmod(candidate, col_count)
if col + col_span > col_count:
return False
return all((row, c) not in occupied for c in range(col, col + col_span))
try:
current_pos = int(title_conf.get("pos", 0))
except (TypeError, ValueError):
current_pos = 0
if current_pos >= 0 and fits(current_pos):
title_conf["pos"] = current_pos
return
for candidate in range(col_count * 200):
if fits(candidate):
title_conf["pos"] = candidate
return
# A unique ID for our add-on's configuration
config_id = None
def get_config_id():
global config_id
if config_id is None:
config_id = mw.addonManager.addonFromModule(__name__)
return config_id
def _get_settings_path() -> str:
"""Get the path to the profile-specific settings file."""
try:
# Calculate addon_path dynamically
current_dir = os.path.dirname(os.path.abspath(__file__))
user_files = os.path.join(current_dir, 'user_files')
os.makedirs(user_files, exist_ok=True)
# Determine profile name
if mw.col and mw.pm and mw.pm.name:
profile_name = mw.pm.name
else:
profile_name = "default"
return os.path.join(user_files, f'settings_{profile_name}.json')
except Exception as e:
print(f"Error determining settings path: {e}")
return ""
# Cached result of _build_config(). Rebuilding costs a deepcopy of DEFAULTS plus
# a JSON read on every call, and the render path calls get_config() dozens of
# times per screen change, so the result is memoised until the settings file
# changes on disk (or write_config()/invalidate_config_cache() clears it).
_CONFIG_CACHE = None
_CONFIG_CACHE_KEY = None
def invalidate_config_cache():
"""Drops the memoised config so the next read rebuilds it from disk."""
global _CONFIG_CACHE, _CONFIG_CACHE_KEY
_CONFIG_CACHE = None
_CONFIG_CACHE_KEY = None
def _config_cache_key():
"""Identity of the on-disk settings, so external edits are picked up."""
settings_path = _get_settings_path()
try:
stat = os.stat(settings_path)
return (settings_path, stat.st_mtime_ns, stat.st_size)
except OSError:
return (settings_path, 0, 0)