|
| 1 | +import tkinter, ntkutils, darkdetect |
| 2 | +from tkinter import ttk, font |
| 3 | + |
| 4 | +import config |
| 5 | + |
| 6 | +def appearance(): |
| 7 | + global boxtheme, boxfont, boxsize, page |
| 8 | + |
| 9 | + savechanges() |
| 10 | + clearstates() |
| 11 | + |
| 12 | + btnappearence.configure(style="Accent.TButton") |
| 13 | + ntkutils.clearwin(frameright) |
| 14 | + |
| 15 | + page = "appearance" |
| 16 | + |
| 17 | + lbltheme = tkinter.Label(frameright, text="Theme:").place(x=10, y=12) |
| 18 | + boxtheme = ttk.Combobox(frameright, values=["Dark", "Light", "System"], state="readonly", width=25) |
| 19 | + boxtheme.set(cfg["theme"]) |
| 20 | + boxtheme.pack(padx=10, pady=10, anchor="e") |
| 21 | + |
| 22 | + lblfont = tkinter.Label(frameright, text="Font:").place(x=10, y=67) |
| 23 | + boxfont = ttk.Combobox(frameright, state="readonly", values=fonts, width=15) |
| 24 | + boxfont.set(cfg["font"]) |
| 25 | + boxfont.pack(padx=80, pady=10, anchor="e") |
| 26 | + boxsize = ttk.Entry(frameright, width=5) |
| 27 | + boxsize.insert(0, cfg["font-size"]) |
| 28 | + boxsize.place(x=260, y=63) |
| 29 | + |
| 30 | +def experimental(): |
| 31 | + global page, btnmica, btnhotkeys |
| 32 | + |
| 33 | + savechanges() |
| 34 | + |
| 35 | + clearstates() |
| 36 | + btnexperimental.configure(style="Accent.TButton") |
| 37 | + ntkutils.clearwin(frameright) |
| 38 | + |
| 39 | + page = "experimental" |
| 40 | + |
| 41 | + lblmica = tkinter.Label(frameright, text="Mica Blur:").place(x=10, y=12) |
| 42 | + btnmica = ttk.Checkbutton(frameright, style="Switch.TCheckbutton") |
| 43 | + btnmica.pack(padx=10, pady=10, anchor="e") |
| 44 | + btnmica.state(["!alternate"]) |
| 45 | + if cfg["mica"]: btnmica.state(["!alternate", "selected"]) |
| 46 | + micainfo = tkinter.Label(frameright, text="When switching from dark to light theme with this\noption enabled, you have to perform a restart!", justify="left", fg="grey").place(x=10, y=42) |
| 47 | + |
| 48 | + lblhotkeys = tkinter.Label(frameright, text="Enable Hotkeys: (Buggy) [needs restart]").place(x=10, y=112) |
| 49 | + btnhotkeys = ttk.Checkbutton(frameright, style="Switch.TCheckbutton") |
| 50 | + btnhotkeys.pack(padx=10, pady=65, anchor="e") |
| 51 | + btnhotkeys.state(["!alternate"]) |
| 52 | + if cfg["hotkeys"]: btnhotkeys.state(["!alternate", "selected"]) |
| 53 | + |
| 54 | +def savechanges(): |
| 55 | + if page == "appearance": |
| 56 | + cfg["theme"] = boxtheme.get() |
| 57 | + cfg["font"] = boxfont.get() |
| 58 | + cfg["font-size"] = boxsize.get() |
| 59 | + elif page == "experimental": |
| 60 | + cfg["mica"] = btnmica.instate(["selected"]) |
| 61 | + cfg["hotkeys"] = btnhotkeys.instate(["selected"]) |
| 62 | + |
| 63 | +def apply(): |
| 64 | + global page, save |
| 65 | + |
| 66 | + savechanges() |
| 67 | + |
| 68 | + ntkutils.cfgtools.SaveCFG(cfg) |
| 69 | + save = True |
| 70 | + settings.destroy() |
| 71 | + |
| 72 | + |
| 73 | +def build(): |
| 74 | + global frameright, frameleft, btnappearence, btnexperimental, settings, page, cfg, save |
| 75 | + |
| 76 | + cfg = config.get() |
| 77 | + page = "" |
| 78 | + save = False |
| 79 | + |
| 80 | + settings = tkinter.Toplevel() |
| 81 | + ntkutils.windowsetup(settings, "txt2 - Settings", "assets/logo.png", False, "500x400") |
| 82 | + ntkutils.dark_title_bar(settings) |
| 83 | + |
| 84 | + frameleft = tkinter.Frame(settings, width=175, bg="#202020") |
| 85 | + frameleft.pack(side=tkinter.LEFT, fill="y") |
| 86 | + frameleft.pack_propagate(False) |
| 87 | + |
| 88 | + if cfg["theme"] == "Light" or (cfg["theme"] == "System" and darkdetect.isLight()): |
| 89 | + frameleft.configure(bg="#f3f3f3") |
| 90 | + |
| 91 | + frameright = tkinter.Frame(settings, width=325) |
| 92 | + frameright.pack(side=tkinter.LEFT, fill="both") |
| 93 | + frameright.pack_propagate(False) |
| 94 | + |
| 95 | + btnappearence = ttk.Button(frameleft, text="Appearence", style="Accent.TButton", width=20, command=appearance) |
| 96 | + btnappearence.pack(pady=10) |
| 97 | + btnexperimental = ttk.Button(frameleft, text="Experimental Features", width=20, command=experimental) |
| 98 | + btnexperimental.pack() |
| 99 | + |
| 100 | + btnapply = ttk.Button(frameleft, text="Apply", style="Accent.TButton", width=20, command=apply) |
| 101 | + btnapply.pack(side=tkinter.BOTTOM, pady=10) |
| 102 | + |
| 103 | + getfonts() |
| 104 | + appearance() |
| 105 | + |
| 106 | +def clearstates(): |
| 107 | + for i in frameleft.pack_slaves(): |
| 108 | + i.configure(style="TButton") |
| 109 | + |
| 110 | +def getfonts(): |
| 111 | + global fonts |
| 112 | + fonts=list(font.families()) |
| 113 | + fonts.sort() |
0 commit comments