Skip to content

Commit d4fd3ca

Browse files
Use Sun-Valley-ttk-theme by rdbende
1 parent f55f05b commit d4fd3ca

File tree

152 files changed

+1103
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+1103
-3
lines changed

main.py

+42-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
from TkZero.Menu import Menu, MenuCascade, MenuCommand, MenuSeparator, \
1717
MenuCheckbutton, MenuRadiobutton
1818
from TkZero.Progressbar import Progressbar, ProgressModes
19-
from TkZero.Vector import Position
2019
from TkZero.Scale import Scale
20+
from TkZero.Vector import Position
2121

2222
from create_logger import create_logger
2323
from picam import RemotePiCam
@@ -38,6 +38,16 @@ def __init__(self):
3838
super().__init__()
3939
self.title = "Remote PiCam"
4040
self.resizable(False, False)
41+
theme_path = Path.cwd() / "sun-valley.tcl"
42+
self.has_theme = theme_path.exists()
43+
if self.has_theme:
44+
logger.info(f"Importing theme file {theme_path}")
45+
self.tk.call("source", str(theme_path.expanduser().resolve()))
46+
self.tk.call("set_theme", "light")
47+
else:
48+
logger.warning(f"{theme_path} does not exist, unable to set "
49+
f"theme!")
50+
4151
self.create_gui()
4252
self.create_menu()
4353
self.on_close = self.close_window
@@ -77,9 +87,25 @@ def create_menu(self) -> None:
7787
self.effect_var.trace_add("write", self.update_effect_status)
7888
self.iso_var = tk.IntVar(self, value=0)
7989
self.iso_var.trace_add("write", self.update_iso_status)
90+
self.dark_mode_var = tk.BooleanVar(self, value=False)
91+
self.dark_mode_var.trace_add("write", self.toggle_theme)
8092
self.menu_bar = Menu(self, is_menubar=True, command=self.remake_menu)
8193
self.remake_menu()
8294

95+
def toggle_theme(self, *args) -> None:
96+
"""
97+
Toggle the theme between light and dark mode.
98+
99+
:return: None.
100+
"""
101+
if self.has_theme:
102+
if not self.dark_mode_var.get():
103+
logger.debug("Switching to light mode")
104+
self.tk.call("set_theme", "light")
105+
else:
106+
logger.debug("Switching to dark mode")
107+
self.tk.call("set_theme", "dark")
108+
83109
def remake_menu(self) -> None:
84110
"""
85111
Remake the menus.
@@ -158,10 +184,23 @@ def remake_menu(self) -> None:
158184
MenuCascade(label="Control", items=[
159185
MenuCommand(label="Open pan-tilt control panel",
160186
underline=14,
161-
enabled=self.cam.is_connected)
187+
enabled=self.cam.is_connected,
188+
command=self.open_pan_tilt_control_panel)
189+
]),
190+
MenuCascade(label="View", items=[
191+
MenuCheckbutton(label="Dark mode",
192+
variable=self.dark_mode_var,
193+
enabled=self.has_theme)
162194
])
163195
]
164196

197+
def open_pan_tilt_control_panel(self) -> None:
198+
"""
199+
Open the pan-tilt control panel.
200+
201+
:return: None.
202+
"""
203+
165204
def set_saturation(self) -> None:
166205
"""
167206
Set the saturation of the stream.
@@ -387,7 +426,7 @@ def set_resolution(self) -> None:
387426
new_res_frame = Frame(self.res_window)
388427
new_res_frame.grid(row=0, column=0, columnspan=2)
389428
new_res_lbl = Label(new_res_frame, text="New resolution: ")
390-
new_res_lbl.grid(row=0, column=0, padx=1, pady=1, sticky=tk.NW)
429+
new_res_lbl.grid(row=0, column=0, padx=1, pady=1, sticky=tk.W)
391430
resolutions = self.cam.settings["resolution"]["available"]
392431
self.new_res_combobox = Combobox(new_res_frame, values=resolutions,
393432
width=30)

sun-valley.tcl

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright © 2021 rdbende <[email protected]>
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+
option add *tearOff 0
7+
8+
proc set_theme {mode} {
9+
if {$mode == "dark"} {
10+
ttk::style theme use "sun-valley-dark"
11+
12+
array set colors {
13+
-fg "#ffffff"
14+
-bg "#1c1c1c"
15+
-disabledfg "#595959"
16+
-selectfg "#ffffff"
17+
-selectbg "#2f60d8"
18+
}
19+
20+
ttk::style configure . \
21+
-background $colors(-bg) \
22+
-foreground $colors(-fg) \
23+
-troughcolor $colors(-bg) \
24+
-focuscolor $colors(-selectbg) \
25+
-selectbackground $colors(-selectbg) \
26+
-selectforeground $colors(-selectfg) \
27+
-insertwidth 1 \
28+
-insertcolor $colors(-fg) \
29+
-fieldbackground $colors(-selectbg) \
30+
-font {"Segoe Ui" 10} \
31+
-borderwidth 1 \
32+
-relief flat
33+
34+
tk_setPalette \
35+
background [ttk::style lookup . -background] \
36+
foreground [ttk::style lookup . -foreground] \
37+
highlightColor [ttk::style lookup . -focuscolor] \
38+
selectBackground [ttk::style lookup . -selectbackground] \
39+
selectForeground [ttk::style lookup . -selectforeground] \
40+
activeBackground [ttk::style lookup . -selectbackground] \
41+
activeForeground [ttk::style lookup . -selectforeground]
42+
43+
ttk::style map . -foreground [list disabled $colors(-disabledfg)]
44+
45+
option add *font [ttk::style lookup . -font]
46+
option add *Menu.selectcolor $colors(-fg)
47+
option add *Menu.background #2f2f2f
48+
49+
} elseif {$mode == "light"} {
50+
ttk::style theme use "sun-valley-light"
51+
52+
array set colors {
53+
-fg "#202020"
54+
-bg "#fafafa"
55+
-disabledfg "#a0a0a0"
56+
-selectfg "#ffffff"
57+
-selectbg "#2f60d8"
58+
}
59+
60+
ttk::style configure . \
61+
-background $colors(-bg) \
62+
-foreground $colors(-fg) \
63+
-troughcolor $colors(-bg) \
64+
-focuscolor $colors(-selectbg) \
65+
-selectbackground $colors(-selectbg) \
66+
-selectforeground $colors(-selectfg) \
67+
-insertwidth 1 \
68+
-insertcolor $colors(-fg) \
69+
-fieldbackground $colors(-selectbg) \
70+
-font {"Segoe Ui" 10} \
71+
-borderwidth 0 \
72+
-relief flat
73+
74+
tk_setPalette background [ttk::style lookup . -background] \
75+
foreground [ttk::style lookup . -foreground] \
76+
highlightColor [ttk::style lookup . -focuscolor] \
77+
selectBackground [ttk::style lookup . -selectbackground] \
78+
selectForeground [ttk::style lookup . -selectforeground] \
79+
activeBackground [ttk::style lookup . -selectbackground] \
80+
activeForeground [ttk::style lookup . -selectforeground]
81+
82+
ttk::style map . -foreground [list disabled $colors(-disabledfg)]
83+
84+
option add *font [ttk::style lookup . -font]
85+
option add *Menu.selectcolor $colors(-fg)
86+
option add *Menu.background #e7e7e7
87+
}
88+
}

0 commit comments

Comments
 (0)