-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsettings.py
More file actions
82 lines (67 loc) · 2.77 KB
/
settings.py
File metadata and controls
82 lines (67 loc) · 2.77 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
# CrossTask Team
# Developers: @zlElo and @DarkGloves
# Licensed under GPL 3.0
from customtkinter import *
import tkinter as tk
import customtkinter
import json
import platform
import os
class SettingsWindow(CTkToplevel):
def __init__(self):
super().__init__()
self.geometry('200x150')
self.resizable(False, False)
self.title('Settings')
# read settings
doc_path = os.path.join(os.path.expanduser('~'), 'Documents')
with open(f'{doc_path}/CrossTask/Settings/settings.json', 'r') as f:
data = json.load(f)
theme = data['theme']
f.close()
if theme == "System":
customtkinter.set_appearance_mode("system")
elif theme == "Dark":
customtkinter.set_appearance_mode("dark")
elif theme == "White":
customtkinter.set_appearance_mode("white")
# platform check for window icon
operating_system = platform.system()
if operating_system == 'Windows':
self.after(200, lambda: self.iconbitmap(os.path.join(os.getcwd(), 'img', 'bitmap.ico')))
elif operating_system == 'Linux':
pass
else:
# setup macos window icon
img = tk.Image("photo", file="content/logo_crosstask-removebg.png")
self.after(200, lambda: self.tk.call('wm','iconphoto', self._w, img))
self._settings()
def _settings(self):
# read settings
doc_path = os.path.join(os.path.expanduser('~'), 'Documents')
with open(f'{doc_path}/CrossTask/Settings/settings.json', 'r') as f:
data = json.load(f)
theme = data['theme']
f.close()
# settings
self.frame = CTkFrame(self)
self.frame.pack(pady=10)
# theme selection
combobox_var = customtkinter.StringVar(value=theme)
label = CTkLabel(self.frame, text='Theme:').pack()
self.theme_selection_ = CTkComboBox(self.frame, values=["System", "Dark", "White"], variable=combobox_var)
self.theme_selection_.pack(padx=10)
self.button_save_theme = CTkButton(self.frame, text='Save', command=lambda: self.__save_settings_theme(self.theme_selection_))
self.button_save_theme.pack(pady=7)
def __save_settings_theme(self, box):
# read settings
doc_path = os.path.join(os.path.expanduser('~'), 'Documents')
with open(f'{doc_path}/CrossTask/Settings/settings.json', 'r') as file:
data = json.load(file)
data['theme'] = box.get()
with open(f'{doc_path}/CrossTask/Settings/settings.json', 'w') as file:
json.dump(data, file, indent=4)
theme_id = data['theme']
print(theme_id)
# update ui
customtkinter.set_appearance_mode(theme_id)