mathshuttle 0.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mathshuttle/recall.py ADDED
@@ -0,0 +1,337 @@
1
+ """The LaTeX an equation was copied from, given back when it returns from Word / PowerPoint unedited.
2
+
3
+ Copy for Word/PowerPoint (the window, the hotkey, the document window, `mathshuttle copy`) remembers each
4
+ equation it copied: a fingerprint of what it shows, and the LaTeX as the user wrote it (macros, \\label,
5
+ spacing). When Paste from Word/PowerPoint reads an equation with the same fingerprint, that LaTeX comes
6
+ back instead of the LaTeX rebuilt from Office's MathML (which has lost the macros and labels).
7
+
8
+ The fingerprint (:func:`fingerprint`) is what the equation shows: its characters in order, every script,
9
+ limit, fraction (a binomial apart), root, accent, matrix row and cell, and each letter's font. What Word
10
+ itself changes when it pastes and copies an equation does not count (checked with Word 16.0.20527 on 99
11
+ equations): bold letters coming back bold italic, sans-serif coming back sans-serif italic, โ„“ as ๐“,
12
+ accents written with other characters (a combining hat as ^), brackets made a stretchy pair, spaces, how
13
+ characters are split into tokens (1.5 as 1 . 5) and which kind of token holds them. Anything a user
14
+ changes does count: a symbol, an accent, a script, a matrix's shape, a letter made bold or upright.
15
+
16
+ Two copies that show the same but carry different \\label or \\tag are not told apart: such an equation
17
+ is then converted from Office's MathML as usual.
18
+
19
+ The memory is a small JSON file next to the settings (the newest 300 equations); set
20
+ MATHSHUTTLE_RECALL_PATH to use another file, or to an empty value to turn it off.
21
+ """
22
+ from __future__ import annotations
23
+
24
+ import contextlib
25
+ import json
26
+ import os
27
+ import re
28
+ import sys
29
+ import tempfile
30
+ import threading
31
+ import time
32
+ import unicodedata
33
+ from typing import Iterator, List, Optional, Tuple
34
+
35
+ _LIMIT = 300
36
+ _LOCK = threading.Lock()
37
+ _VERSION = "2"
38
+
39
+
40
+ def store_path() -> Optional[str]:
41
+ """Where the memory is kept (None: off)."""
42
+ if "MATHSHUTTLE_RECALL_PATH" in os.environ:
43
+ path = os.environ["MATHSHUTTLE_RECALL_PATH"]
44
+ return os.path.abspath(path) if path else None
45
+ base = (os.path.join(os.path.expanduser("~"), "Library", "Application Support") if sys.platform == "darwin"
46
+ else os.environ.get("APPDATA", os.path.expanduser("~")))
47
+ return os.path.join(base, "MathShuttle", "copied.json")
48
+
49
+
50
+ # ---- the fingerprint --------------------------------------------------------------------------------------
51
+ # a mathvariant -> font class: b(old) s(cript) f(raktur) d(ouble-struck) ss (sans) m(ono) u(pright) i(talic).
52
+ # Bold and bold italic are one class, as are the sans-serif ones: Word makes them bold italic, sans italic.
53
+ _VARIANTS = {"normal": "u", "italic": "i", "bold": "b", "bold-italic": "b", "double-struck": "d", "script": "s",
54
+ "bold-script": "s", "fraktur": "f", "bold-fraktur": "f", "sans-serif": "ss", "bold-sans-serif": "ss",
55
+ "sans-serif-italic": "ss", "sans-serif-bold-italic": "ss", "monospace": "m"}
56
+ _NAME_WORDS = (("DOUBLE-STRUCK", "d"), ("FRAKTUR", "f"), ("SCRIPT", "s"), ("SANS-SERIF", "ss"),
57
+ ("MONOSPACE", "m"), ("BOLD", "b"), ("ITALIC", "i"))
58
+ _LETTERLIKE = {}
59
+ for _chars, _cls in (("โ„‚โ„โ„•โ„™โ„šโ„โ„คโ……โ…†โ…‡โ…ˆโ…‰", "d"), ("โ„Šโ„‹โ„โ„’โ„›โ„ฌโ„ฐโ„ฑโ„ณโ„ฏโ„ดโ„“", "s"), ("โ„Œโ„‘โ„œโ„จโ„ญ", "f")):
60
+ for _ch in _chars:
61
+ _LETTERLIKE[_ch] = (unicodedata.normalize("NFKC", _ch) if _ch != "โ„“" else "l", _cls)
62
+ # characters with nothing to see: spaces of every width, invisible operators, zero-width marks
63
+ _INVISIBLE = frozenset("\u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u200c"
64
+ "\u200d\u205f\u2060\u2061\u2062\u2063\u2064\u3000\ufeff")
65
+ # an accent over or under a base, as Word or texmath write it -> one name
66
+ _ACCENTS = {}
67
+ for _chars, _name in (("\u0302^ห†\u02c6", "hat"), ("\u0303~หœ\u02dc\u223c", "tilde"),
68
+ ("\u0304\u0305ยฏโ€พ-\u2212\u203e\u00af\u2015\u2014\u2500", "bar"),
69
+ ("_\u0332\u2017\u0331", "underbar"), ("\u20d7โ†’\u2192", "vec"), ("\u0307.ห™\u02d9", "dot"),
70
+ ("\u0308ยจ", "ddot"), ("\u20db", "dddot"), ("\u030c\u02c7ห‡", "check"), ("\u0306ห˜\u02d8", "breve"),
71
+ ("\u0301ยด\u00b4\u02ca", "acute"), ("\u0300`\u02cb", "grave"), ("\u030aหš\u02da", "ring")):
72
+ for _ch in _chars:
73
+ _ACCENTS[_ch] = _name
74
+ _FIXED = {"msub": 2, "msup": 2, "msubsup": 3, "munder": 2, "mover": 2, "munderover": 3, "mfrac": 2, "mroot": 2}
75
+ _ONE_ARGUMENT = ("msqrt", "menclose", "mphantom", "mtd") # their content as one argument, however grouped
76
+ _OPENING, _CLOSING = frozenset("([{โŸจโŒŠโŒˆ|โ€–โŸฆโŸชใ€ˆ"), frozenset(")]}โŸฉโŒ‹โŒ‰|โ€–โŸงโŸซใ€‰")
77
+ # characters Word writes for others it was given: one of each pair stands for both
78
+ _SAME = {"*": "โˆ—", "-": "โˆ’", "'": "โ€ฒ"}
79
+
80
+
81
+ def _tag(el) -> str:
82
+ return el.tag.rsplit("}", 1)[-1] if isinstance(el.tag, str) else ""
83
+
84
+
85
+ def _char(ch: str, tag: str, variant: Optional[str], word: bool) -> str:
86
+ """One character as it shows: a letter with its font class, any other symbol as itself."""
87
+ ch = _SAME.get(ch, ch)
88
+ if ch in _LETTERLIKE:
89
+ base, cls = _LETTERLIKE[ch]
90
+ return base + cls
91
+ name = unicodedata.name(ch, "")
92
+ if name.startswith("MATHEMATICAL"): # ๐ฑ ๐‘ฅ ๐”ค ๐Ÿ ๐Ÿ™ ๐›ป: the character says its font
93
+ # its letter (๐œ™ is ฯ•, \phi, and ๐œ‘ is ฯ†, \varphi: Word writes each in its italic form; NFKC would
94
+ # make both ฯ†)
95
+ decomposition = unicodedata.decomposition(ch)
96
+ base = chr(int(decomposition.split()[1], 16)) if decomposition.startswith("<font>") else \
97
+ unicodedata.normalize("NFKC", ch)
98
+ base = _SAME.get(base, base)
99
+ cls = next((c for w, c in _NAME_WORDS if w in name), "u")
100
+ # (a letter or digit keeps its font, ๐Ÿ™ is not 1; a symbol only bold: Word writes โˆ‡ as ๐›ป)
101
+ return base + (cls if base.isalnum() or cls == "b" else "")
102
+ if not ch.isalpha():
103
+ return ch
104
+ if tag == "mi":
105
+ return ch + _VARIANTS.get((variant or ("normal" if word else "italic")).lower(), "u")
106
+ return ch + _VARIANTS.get((variant or "normal").lower(), "u") # mtext, mo, mn: upright unless said
107
+
108
+
109
+ def _accent(el) -> Optional[str]:
110
+ """The accent's name if `el` (the second child of an mover / munder) is a single accent character."""
111
+ if _tag(el) not in ("mo", "mi", "mtext"):
112
+ return None
113
+ text = "".join(ch for ch in (el.text or "") if not ch.isspace() and ch not in _INVISIBLE)
114
+ return _ACCENTS.get(text) if len(text) == 1 else None
115
+
116
+
117
+ def _fence(el, chars) -> bool:
118
+ return _tag(el) == "mo" and (el.text or "").strip() in chars and len((el.text or "").strip()) == 1
119
+
120
+
121
+ def _fenced(base) -> Optional[list]:
122
+ """The children of `base` if it is a bracketed group, ( โ€ฆ ) or โ€– โ€ฆ โ€– (Word's form of a script on one)."""
123
+ while _tag(base) == "mrow":
124
+ kids = [k for k in base if isinstance(k.tag, str)]
125
+ if len(kids) != 1:
126
+ break
127
+ base = kids[0]
128
+ if _tag(base) != "mrow":
129
+ return None
130
+ kids = [k for k in base if isinstance(k.tag, str)]
131
+ if len(kids) >= 2 and _fence(kids[0], _OPENING) and _fence(kids[-1], _CLOSING):
132
+ return kids
133
+ return None
134
+
135
+
136
+ def fingerprint(mathml: str) -> Optional[str]:
137
+ """What a single <math> shows, as a string to compare (None if it is not one readable equation)."""
138
+ from .pandoc_engine import parse_mathml
139
+ try:
140
+ maths = parse_mathml(mathml)
141
+ except Exception: # noqa: BLE001 - not MathML we can read: nothing to recall
142
+ return None
143
+ if len(maths) != 1:
144
+ return None
145
+ out: List[str] = [_VERSION, "|"]
146
+
147
+ def walk(el, variant: Optional[str]) -> None:
148
+ tag = _tag(el)
149
+ variant = el.get("mathvariant") or variant
150
+ if tag in ("annotation", "annotation-xml", "mspace", "maligngroup", "malignmark", "mprescripts", "none"):
151
+ out.append({"mprescripts": "<pre>", "none": "<none>"}.get(tag, ""))
152
+ return
153
+ kids = [k for k in el if isinstance(k.tag, str)]
154
+ if tag == "semantics":
155
+ if kids:
156
+ walk(kids[0], variant)
157
+ return
158
+ if tag in ("mi", "mo", "mn", "mtext", "ms"):
159
+ text = "".join(ch for ch in (el.text or "") if not ch.isspace() and ch not in _INVISIBLE)
160
+ word = len([ch for ch in text if ch.isalpha()]) > 1
161
+ out.extend(_char(ch, tag, variant, word) for ch in text)
162
+ return
163
+ if tag == "mfenced":
164
+ seps = [ch for ch in el.get("separators", ",") if not ch.isspace()]
165
+ out.append(el.get("open", "("))
166
+ for k, child in enumerate(kids):
167
+ if k and seps:
168
+ out.append(seps[min(k - 1, len(seps) - 1)])
169
+ walk(child, variant)
170
+ out.append(el.get("close", ")"))
171
+ return
172
+ if tag in ("mover", "munder") and len(kids) == 2 and _accent(kids[1]):
173
+ out.append("<%s:%s{" % (tag, _accent(kids[1])))
174
+ walk(kids[0], variant)
175
+ out.append("}>")
176
+ return
177
+ if tag in ("msub", "msup", "msubsup") and kids:
178
+ fenced = _fenced(kids[0])
179
+ if fenced: # a script on a bracketed group, which texmath puts on the closing bracket alone
180
+ for child in fenced[:-1]:
181
+ walk(child, variant)
182
+ kids = [fenced[-1]] + kids[1:]
183
+ if tag in _FIXED or tag in _ONE_ARGUMENT or tag in ("mmultiscripts", "mtable", "mtr", "mlabeledtr"):
184
+ mark = tag
185
+ if tag == "mfrac" and (el.get("linethickness") or "").strip() in ("0", "0pt", "0em", "0px", "0ex"):
186
+ mark = "binom" # no fraction bar
187
+ if tag == "menclose":
188
+ mark += ":" + " ".join(sorted((el.get("notation") or "longdiv").split()))
189
+ out.append("<%s" % mark)
190
+ for child in ([el] if tag in _ONE_ARGUMENT else kids):
191
+ out.append("{")
192
+ if child is el:
193
+ for k in kids:
194
+ walk(k, variant)
195
+ else:
196
+ walk(child, variant)
197
+ out.append("}")
198
+ out.append(">")
199
+ return
200
+ for child in kids: # mrow, mstyle, mpadded, math...: their content in order
201
+ walk(child, variant)
202
+
203
+ walk(maths[0], None)
204
+ return "".join(out)
205
+
206
+
207
+ # ---- the memory ---------------------------------------------------------------------------------------------
208
+ _MARKS = re.compile(r"\\(?:label|tag\*?)\s*\{[^{}]*\}")
209
+
210
+
211
+ def _marks(tex: str) -> List[str]:
212
+ """The \\label s and \\tag s of an equation's LaTeX (what two same-looking equations differ in)."""
213
+ return [" ".join(m.split()) for m in _MARKS.findall(tex)]
214
+
215
+
216
+ def _load(path: str) -> list:
217
+ """The entries; [] for a missing or unreadable file (OSError other than a missing file is raised)."""
218
+ try:
219
+ with open(path, encoding="utf-8") as f:
220
+ data = json.load(f)
221
+ except FileNotFoundError:
222
+ return []
223
+ except ValueError:
224
+ return []
225
+ return [e for e in data if isinstance(e, dict)] if isinstance(data, list) else []
226
+
227
+
228
+ @contextlib.contextmanager
229
+ def _locked(path: str) -> Iterator[bool]:
230
+ """Holds `path`.lock (made exclusively) while another process could write the memory too: yields
231
+ whether it got the lock within about 2 s (a lock left by a crashed process is taken after 10 s)."""
232
+ lock = path + ".lock"
233
+ got = False
234
+ for _ in range(100):
235
+ try:
236
+ os.close(os.open(lock, os.O_CREAT | os.O_EXCL | os.O_WRONLY))
237
+ got = True
238
+ break
239
+ except FileExistsError:
240
+ try:
241
+ if time.time() - os.path.getmtime(lock) > 10:
242
+ os.remove(lock)
243
+ continue
244
+ except OSError:
245
+ pass
246
+ time.sleep(0.02)
247
+ except OSError:
248
+ break
249
+ try:
250
+ yield got
251
+ finally:
252
+ if got:
253
+ try:
254
+ os.remove(lock)
255
+ except OSError:
256
+ pass
257
+
258
+
259
+ def _save(path: str, entries: list) -> None:
260
+ folder = os.path.dirname(path)
261
+ handle, part = tempfile.mkstemp(dir=folder, prefix=".copied.", suffix=".part")
262
+ try:
263
+ with os.fdopen(handle, "w", encoding="utf-8") as f:
264
+ json.dump(entries, f, ensure_ascii=False)
265
+ for attempt in range(5):
266
+ try:
267
+ os.replace(part, path)
268
+ return
269
+ except PermissionError: # a reader has it open for a moment (Windows)
270
+ if attempt == 4:
271
+ raise
272
+ time.sleep(0.05)
273
+ finally:
274
+ try:
275
+ os.remove(part)
276
+ except OSError:
277
+ pass
278
+
279
+
280
+ def remember(mathml: str, tex: str, display: bool) -> None:
281
+ """Note that `mathml` was copied for Office from the LaTeX `tex` (an equation's body as written)."""
282
+ path = store_path()
283
+ key = fingerprint(mathml) if path else None
284
+ if not key:
285
+ return
286
+ with _LOCK:
287
+ try:
288
+ os.makedirs(os.path.dirname(path), exist_ok=True)
289
+ with _locked(path) as got:
290
+ if not got:
291
+ return # another process is writing: this copy is not remembered, nothing is lost
292
+ entries = _load(path)
293
+ old = next((e for e in entries if e.get("fingerprint") == key), None)
294
+ entries = [e for e in entries if e.get("fingerprint") != key]
295
+ if old is not None and (old.get("ambiguous") or _marks(old.get("tex") or "") != _marks(tex)):
296
+ # the same equation with another \label or \tag: which one comes back is not known
297
+ entries.append({"fingerprint": key, "ambiguous": True, "time": int(time.time())})
298
+ else:
299
+ entries.append({"fingerprint": key, "tex": tex, "display": bool(display), "time": int(time.time())})
300
+ _save(path, entries[-_LIMIT:])
301
+ except OSError:
302
+ pass # a memory that cannot be read or written is no reason to fail a copy
303
+
304
+
305
+ def recall(mathml: str) -> Optional[Tuple[str, bool]]:
306
+ """(LaTeX, display) the equation `mathml` was copied from, if it comes back unedited; else None."""
307
+ path = store_path()
308
+ key = fingerprint(mathml) if path else None
309
+ if not key:
310
+ return None
311
+ with _LOCK:
312
+ try:
313
+ entries = _load(path)
314
+ except OSError:
315
+ return None
316
+ for entry in reversed(entries):
317
+ if entry.get("fingerprint") == key:
318
+ if entry.get("ambiguous") or not isinstance(entry.get("tex"), str):
319
+ return None
320
+ return entry["tex"], bool(entry.get("display", True))
321
+ return None
322
+
323
+
324
+ NOTE = ("The equation came back from Office unchanged: this is the LaTeX it was copied from (your macros, "
325
+ "labels and spacing).")
326
+
327
+
328
+ def latex_for(mathml: str, wrapper: str = "auto", mode: str = "auto") -> Optional[str]:
329
+ """The LaTeX `mathml` was copied from, in `wrapper` (`mode`: auto keeps its own display or inline), or
330
+ None when it was not copied from here or has been edited."""
331
+ found = recall(mathml)
332
+ if found is None:
333
+ return None
334
+ from . import latex_wrap
335
+ tex, display = found
336
+ display = display if mode == "auto" else mode == "display"
337
+ return latex_wrap.wrap(tex, wrapper, display)
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) rdbende <rdbende@proton.me>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,130 @@
1
+ package require Tk 8.6-
2
+
3
+ source [file join [file dirname [info script]] theme light.tcl]
4
+ source [file join [file dirname [info script]] theme dark.tcl]
5
+
6
+
7
+ if {[tk windowingsystem] == "win32"} {
8
+ set static ""
9
+ } else {
10
+ set static " static"
11
+ }
12
+
13
+ font create SunValleyCaptionFont -family "Segoe UI Variable$static Small" -size -12
14
+ font create SunValleyBodyFont -family "Segoe UI Variable$static Text" -size -14
15
+ font create SunValleyBodyStrongFont -family "Segoe UI Variable$static Text Semibold" -size -14
16
+ font create SunValleyBodyLargeFont -family "Segoe UI Variable$static Text" -size -18
17
+ font create SunValleySubtitleFont -family "Segoe UI Variable$static Display Semibold" -size -20
18
+ font create SunValleyTitleFont -family "Segoe UI Variable$static Display Semibold" -size -28
19
+ font create SunValleyTitleLargeFont -family "Segoe UI Variable$static Display Semibold" -size -40
20
+ font create SunValleyDisplayFont -family "Segoe UI Variable$static Display Semibold" -size -68
21
+
22
+
23
+ proc config_entry_font {w} {
24
+ set font_config [$w config -font]
25
+ if {[lindex $font_config 3] != [lindex $font_config 4]} {
26
+ return
27
+ }
28
+ if {[ttk::style theme use] in {"sun-valley-dark" "sun-valley-light"}} {
29
+ $w configure -font SunValleyBodyFont
30
+ }
31
+ }
32
+
33
+
34
+ proc config_menus {w} {
35
+ if {[tk windowingsystem] == "aqua" || [tk windowingsystem] == "win32"} {
36
+ return
37
+ }
38
+
39
+ set theme [ttk::style theme use]
40
+ if {$theme == "sun-valley-dark"} {
41
+ $w configure \
42
+ -relief solid \
43
+ -borderwidth 1 \
44
+ -activeborderwidth 0 \
45
+ -background "#292929" \
46
+ -activebackground $ttk::theme::sv_dark::colors(-selbg) \
47
+ -activeforeground $ttk::theme::sv_dark::colors(-selfg) \
48
+ -selectcolor $ttk::theme::sv_dark::colors(-selfg)
49
+ } elseif {$theme == "sun-valley-light"} {
50
+ $w configure \
51
+ -relief solid \
52
+ -borderwidth 1 \
53
+ -activeborderwidth 0 \
54
+ -background "#e7e7e7" \
55
+ -activebackground $ttk::theme::sv_light::colors(-selbg) \
56
+ -activeforeground $ttk::theme::sv_light::colors(-selfg) \
57
+ -selectcolor $ttk::theme::sv_light::colors(-selfg)
58
+ }
59
+
60
+ if {[[winfo toplevel $w] cget -menu] != $w} {
61
+ if {$theme == "sun-valley-dark"} {
62
+ $w configure -borderwidth 0 -background $ttk::theme::sv_dark::colors(-bg)
63
+ } elseif {$theme == "sun-valley-light"} {
64
+ $w configure -borderwidth 0 -background $ttk::theme::sv_light::colors(-bg)
65
+ }
66
+ }
67
+ }
68
+
69
+
70
+ proc configure_colors {} {
71
+ set theme [ttk::style theme use]
72
+ if {$theme == "sun-valley-dark"} {
73
+ ttk::style configure . \
74
+ -background $ttk::theme::sv_dark::colors(-bg) \
75
+ -foreground $ttk::theme::sv_dark::colors(-fg) \
76
+ -troughcolor $ttk::theme::sv_dark::colors(-bg) \
77
+ -focuscolor $ttk::theme::sv_dark::colors(-selbg) \
78
+ -selectbackground $ttk::theme::sv_dark::colors(-selbg) \
79
+ -selectforeground $ttk::theme::sv_dark::colors(-selfg) \
80
+ -insertwidth 1 \
81
+ -insertcolor $ttk::theme::sv_dark::colors(-fg) \
82
+ -fieldbackground $ttk::theme::sv_dark::colors(-bg) \
83
+ -font SunValleyBodyFont \
84
+ -borderwidth 0 \
85
+ -relief flat
86
+
87
+ tk_setPalette \
88
+ background $ttk::theme::sv_dark::colors(-bg) \
89
+ foreground $ttk::theme::sv_dark::colors(-fg) \
90
+ highlightColor $ttk::theme::sv_dark::colors(-selbg) \
91
+ selectBackground $ttk::theme::sv_dark::colors(-selbg) \
92
+ selectForeground $ttk::theme::sv_dark::colors(-selfg) \
93
+ activeBackground $ttk::theme::sv_dark::colors(-selbg) \
94
+ activeForeground $ttk::theme::sv_dark::colors(-selfg)
95
+
96
+ ttk::style map . -foreground [list disabled $ttk::theme::sv_dark::colors(-disfg)]
97
+ } elseif {$theme == "sun-valley-light"} {
98
+ ttk::style configure . \
99
+ -background $ttk::theme::sv_light::colors(-bg) \
100
+ -foreground $ttk::theme::sv_light::colors(-fg) \
101
+ -troughcolor $ttk::theme::sv_light::colors(-bg) \
102
+ -focuscolor $ttk::theme::sv_light::colors(-selbg) \
103
+ -selectbackground $ttk::theme::sv_light::colors(-selbg) \
104
+ -selectforeground $ttk::theme::sv_light::colors(-selfg) \
105
+ -insertwidth 1 \
106
+ -insertcolor $ttk::theme::sv_light::colors(-fg) \
107
+ -fieldbackground $ttk::theme::sv_light::colors(-bg) \
108
+ -font SunValleyBodyFont \
109
+ -borderwidth 0 \
110
+ -relief flat
111
+
112
+ tk_setPalette \
113
+ background $ttk::theme::sv_light::colors(-bg) \
114
+ foreground $ttk::theme::sv_light::colors(-fg) \
115
+ highlightColor $ttk::theme::sv_light::colors(-selbg) \
116
+ selectBackground $ttk::theme::sv_light::colors(-selbg) \
117
+ selectForeground $ttk::theme::sv_light::colors(-selfg) \
118
+ activeBackground $ttk::theme::sv_light::colors(-selbg) \
119
+ activeForeground $ttk::theme::sv_light::colors(-selfg)
120
+
121
+ ttk::style map . -foreground [list disabled $ttk::theme::sv_light::colors(-disfg)]
122
+ }
123
+ }
124
+
125
+
126
+ bind [winfo class .] <<ThemeChanged>> {+configure_colors}
127
+ bind TEntry <<ThemeChanged>> {+config_entry_font %W}
128
+ bind TCombobox <<ThemeChanged>> {+config_entry_font %W}
129
+ bind TSpinbox <<ThemeChanged>> {+config_entry_font %W}
130
+ bind Menu <<ThemeChanged>> {+config_menus %W}