-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme_manager.py
68 lines (63 loc) · 2.34 KB
/
theme_manager.py
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
import configparser
class ThemeManager:
def __init__(self, config_file='config.ini'):
self.config_file = config_file
self.config = configparser.ConfigParser()
self.load_config()
self.themes = {
'default': {
'bg': '#f0f0f0',
'button_bg': '#e1e1e1',
'button_fg': '#000000',
'button_active_bg': '#d1d1d1',
'button_active_fg': '#000000',
'entry_bg': '#ffffff',
'entry_fg': '#000000'
},
'dark': {
'bg': '#2c2c2c',
'button_bg': '#3c3c3c',
'button_fg': '#ffffff',
'button_active_bg': '#4c4c4c',
'button_active_fg': '#ffffff',
'entry_bg': '#1c1c1c',
'entry_fg': '#ffffff'
},
'light': {
'bg': '#ffffff',
'button_bg': '#f0f0f0',
'button_fg': '#000000',
'button_active_bg': '#e0e0e0',
'button_active_fg': '#000000',
'entry_bg': '#ffffff',
'entry_fg': '#000000'
},
'blue': {
'bg': '#e6f2ff',
'button_bg': '#b3d9ff',
'button_fg': '#000000',
'button_active_bg': '#80bfff',
'button_active_fg': '#000000',
'entry_bg': '#ffffff',
'entry_fg': '#000000'
}
}
self.current_theme = self.config.get('Theme', 'current', fallback='default')
def load_config(self):
self.config.read(self.config_file)
if not self.config.has_section('Theme'):
self.config.add_section('Theme')
self.config.set('Theme', 'current', 'default')
self.save_config()
def save_config(self):
with open(self.config_file, 'w') as configfile:
self.config.write(configfile)
def get_current_theme(self):
return self.themes[self.current_theme]
def next_theme(self):
themes = list(self.themes.keys())
current_index = themes.index(self.current_theme)
next_index = (current_index + 1) % len(themes)
self.current_theme = themes[next_index]
self.config.set('Theme', 'current', self.current_theme)
self.save_config()