-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.py
More file actions
348 lines (300 loc) · 11.6 KB
/
theme.py
File metadata and controls
348 lines (300 loc) · 11.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
"""
Theme module for consistent dark/light theme support across all GUIs
"""
import tkinter as tk
from tkinter import ttk
class Theme:
"""Manages application theme settings"""
# Dark theme colors
DARK = {
'bg': '#1e1e1e', # Main background
'fg': '#d4d4d4', # Main foreground/text
'bg_secondary': '#252526', # Secondary background (frames, etc)
'bg_tertiary': '#2d2d30', # Tertiary background (input fields)
'bg_hover': '#2a2d2e', # Hover state
'bg_selected': '#094771', # Selected items
'border': '#3e3e42', # Borders
'accent': '#0e639c', # Accent color (buttons)
'accent_hover': '#1177bb', # Accent hover
'text_disabled': '#858585', # Disabled text
'text_muted': '#969696', # Muted/secondary text
'success': '#4ec9b0', # Success messages
'error': '#f48771', # Error messages
'warning': '#dcdcaa', # Warning messages
'info': '#4fc1ff', # Info messages
'log_bg': '#1e1e1e', # Log/text area background
'tree_bg': '#252526', # Treeview background
'tree_fg': '#d4d4d4', # Treeview foreground
'tree_selected': '#094771', # Treeview selected
'button_bg': '#0e639c', # Button background
'button_fg': '#ffffff', # Button foreground
'entry_bg': '#3c3c3c', # Entry background
'entry_fg': '#d4d4d4', # Entry foreground
}
# Light theme colors
LIGHT = {
'bg': '#ffffff',
'fg': '#000000',
'bg_secondary': '#f3f3f3',
'bg_tertiary': '#ffffff',
'bg_hover': '#e5f3ff',
'bg_selected': '#0078d4',
'border': '#d1d1d1',
'accent': '#0078d4',
'accent_hover': '#106ebe',
'text_disabled': '#a0a0a0',
'text_muted': '#606060',
'success': '#107c10',
'error': '#d13438',
'warning': '#f7630c',
'info': '#0078d4',
'log_bg': '#ffffff',
'tree_bg': '#ffffff',
'tree_fg': '#000000',
'tree_selected': '#0078d4',
'button_bg': '#0078d4',
'button_fg': '#ffffff',
'entry_bg': '#ffffff',
'entry_fg': '#000000',
}
def __init__(self, root, dark_mode=True):
self.root = root
self.dark_mode = dark_mode
self.colors = self.DARK if dark_mode else self.LIGHT
self.apply_theme()
def apply_theme(self):
"""Apply the current theme to the root window"""
colors = self.colors
# Configure root window
self.root.configure(bg=colors['bg'])
# Create ttk style
style = ttk.Style()
# Try to use a base theme that works well with dark mode
try:
if self.dark_mode:
# Try clam theme as it's more customizable
style.theme_use('clam')
else:
style.theme_use('clam')
except:
pass
# Configure general ttk styles
style.configure('.',
background=colors['bg'],
foreground=colors['fg'],
bordercolor=colors['border'],
darkcolor=colors['bg_secondary'],
lightcolor=colors['bg_secondary'],
troughcolor=colors['bg_tertiary'],
fieldbackground=colors['entry_bg'],
selectbackground=colors['bg_selected'],
selectforeground=colors['fg'],
insertcolor=colors['fg']
)
# Frame styles
style.configure('TFrame',
background=colors['bg']
)
style.configure('TLabelFrame',
background=colors['bg'],
foreground=colors['fg'],
bordercolor=colors['border'],
relief='solid'
)
style.configure('TLabelFrame.Label',
background=colors['bg'],
foreground=colors['fg']
)
# Label styles
style.configure('TLabel',
background=colors['bg'],
foreground=colors['fg']
)
# Button styles
style.configure('TButton',
background=colors['bg_tertiary'],
foreground=colors['fg'],
bordercolor=colors['border'],
focuscolor=colors['accent'],
lightcolor=colors['bg_tertiary'],
darkcolor=colors['bg_tertiary']
)
style.map('TButton',
background=[('active', colors['bg_hover']), ('pressed', colors['bg_selected'])],
foreground=[('disabled', colors['text_disabled'])]
)
# Accent button style
style.configure('Accent.TButton',
background=colors['accent'],
foreground=colors['button_fg'],
bordercolor=colors['accent'],
focuscolor=colors['accent_hover']
)
style.map('Accent.TButton',
background=[('active', colors['accent_hover']), ('pressed', colors['bg_selected'])],
foreground=[('disabled', colors['text_disabled'])]
)
# Entry styles
style.configure('TEntry',
fieldbackground=colors['entry_bg'],
background=colors['entry_bg'],
foreground=colors['entry_fg'],
bordercolor=colors['border'],
insertcolor=colors['fg']
)
style.map('TEntry',
fieldbackground=[('readonly', colors['bg_secondary'])],
foreground=[('readonly', colors['text_muted'])]
)
# Combobox styles
style.configure('TCombobox',
fieldbackground=colors['entry_bg'],
background=colors['entry_bg'],
foreground=colors['entry_fg'],
bordercolor=colors['border'],
arrowcolor=colors['fg'],
selectbackground=colors['bg_selected'],
selectforeground=colors['fg']
)
style.map('TCombobox',
fieldbackground=[('readonly', colors['entry_bg'])],
selectbackground=[('readonly', colors['bg_selected'])],
background=[('readonly', colors['bg_tertiary'])]
)
# Spinbox styles
style.configure('TSpinbox',
fieldbackground=colors['entry_bg'],
background=colors['entry_bg'],
foreground=colors['entry_fg'],
bordercolor=colors['border'],
arrowcolor=colors['fg']
)
# Checkbutton styles
style.configure('TCheckbutton',
background=colors['bg'],
foreground=colors['fg'],
indicatorcolor=colors['entry_bg'],
bordercolor=colors['border']
)
style.map('TCheckbutton',
background=[('active', colors['bg_hover'])],
indicatorcolor=[('selected', colors['accent'])]
)
# Radiobutton styles
style.configure('TRadiobutton',
background=colors['bg'],
foreground=colors['fg'],
indicatorcolor=colors['entry_bg'],
bordercolor=colors['border']
)
style.map('TRadiobutton',
background=[('active', colors['bg_hover'])],
indicatorcolor=[('selected', colors['accent'])]
)
# Treeview styles
style.configure('Treeview',
background=colors['tree_bg'],
foreground=colors['tree_fg'],
fieldbackground=colors['tree_bg'],
bordercolor=colors['border'],
relief='flat'
)
style.configure('Treeview.Heading',
background=colors['bg_secondary'],
foreground=colors['fg'],
bordercolor=colors['border'],
relief='flat'
)
style.map('Treeview',
background=[('selected', colors['tree_selected'])],
foreground=[('selected', colors['fg'])]
)
style.map('Treeview.Heading',
background=[('active', colors['bg_hover'])]
)
# Notebook (tabs) styles
style.configure('TNotebook',
background=colors['bg'],
bordercolor=colors['border'],
tabmargins=[2, 5, 2, 0]
)
style.configure('TNotebook.Tab',
background=colors['bg_secondary'],
foreground=colors['fg'],
bordercolor=colors['border'],
padding=[10, 2]
)
style.map('TNotebook.Tab',
background=[('selected', colors['bg'])],
foreground=[('selected', colors['fg'])],
expand=[('selected', [1, 1, 1, 0])]
)
# Scrollbar styles - improved visibility
# Make scrollbars more visible with better contrast
scrollbar_bg = '#4a4a4a' if self.dark_mode else '#c0c0c0' # Scrollbar thumb color
scrollbar_hover = '#5a5a5a' if self.dark_mode else '#a0a0a0' # Hover state
scrollbar_pressed = '#6a6a6a' if self.dark_mode else '#808080' # Pressed state
style.configure('TScrollbar',
background=scrollbar_bg,
bordercolor=colors['border'],
troughcolor=colors['bg_tertiary'],
arrowcolor=colors['fg'],
relief='flat'
)
style.map('TScrollbar',
background=[
('pressed', scrollbar_pressed),
('active', scrollbar_hover)
]
)
# Progressbar styles
style.configure('TProgressbar',
background=colors['accent'],
troughcolor=colors['bg_tertiary'],
bordercolor=colors['border']
)
# Store style for later reference
self.style = style
def configure_text_widget(self, text_widget, **extra_config):
"""Configure a Text widget with theme colors"""
config = {
'bg': self.colors['log_bg'],
'fg': self.colors['fg'],
'insertbackground': self.colors['fg'],
'selectbackground': self.colors['bg_selected'],
'selectforeground': self.colors['fg'],
'highlightbackground': self.colors['border'],
'highlightcolor': self.colors['accent'],
'relief': 'flat',
'borderwidth': 1
}
config.update(extra_config)
text_widget.configure(**config)
def configure_listbox(self, listbox, **extra_config):
"""Configure a Listbox widget with theme colors"""
config = {
'bg': self.colors['tree_bg'],
'fg': self.colors['tree_fg'],
'selectbackground': self.colors['tree_selected'],
'selectforeground': self.colors['fg'],
'highlightbackground': self.colors['border'],
'highlightcolor': self.colors['accent'],
'relief': 'flat',
'borderwidth': 1
}
config.update(extra_config)
listbox.configure(**config)
def toggle_theme(self):
"""Toggle between dark and light theme"""
self.dark_mode = not self.dark_mode
self.colors = self.DARK if self.dark_mode else self.LIGHT
self.apply_theme()
# Return the new mode
return self.dark_mode
def get_color(self, color_name):
"""Get a specific color from the current theme"""
return self.colors.get(color_name, '#000000')
def apply_theme_to_toplevel(toplevel, theme):
"""Apply theme to a Toplevel window"""
colors = theme.colors
toplevel.configure(bg=colors['bg'])