Skip to content

Commit

Permalink
Add custom theme selection
Browse files Browse the repository at this point in the history
  • Loading branch information
jake158 committed Mar 5, 2024
1 parent 66dd780 commit ccda1bb
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
import os
import sys
import json
import customtkinter as ctk


ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("themes/Default.json")


def save_theme(theme):
config = {'selected_theme': theme}
with open('theme.json', 'w') as config_file:
json.dump(config, config_file)

def load_theme():
try:
with open('theme.json', 'r') as config_file:
config = json.load(config_file)
selected_theme = config.get('selected_theme', 'Default')
except FileNotFoundError:
selected_theme = 'Default'

ctk.set_default_color_theme(f"themes/{selected_theme}.json")


def reload_app():
os.execl(sys.executable, sys.executable, *sys.argv)


class SettingsFrame(ctk.CTkFrame):
def __init__(self, master):
super().__init__(master)

self.theme_label = ctk.CTkLabel(self, text="Select Theme:")
self.theme_label.pack(pady=10)

themes_dir = 'themes'
self.theme_options = [os.path.splitext(theme)[0] for theme in os.listdir(themes_dir) if theme.endswith('.json')]

self.theme_var = ctk.StringVar(value="...")

self.theme_menu = ctk.CTkOptionMenu(self, variable=self.theme_var, values=self.theme_options, anchor="n", command=self.change_theme)
self.theme_menu.pack()

def change_theme(self, theme):
save_theme(theme)
reload_app()


class PomodoroFrame(ctk.CTkFrame):
Expand All @@ -13,7 +55,7 @@ def __init__(self, master):
self.timer_display.pack(pady=50)

self.start_button = ctk.CTkButton(self, text="Start", fg_color="transparent",
border_width=2, corner_radius=32, command=self.start_timer)
border_width=2, command=self.start_timer)
self.start_button.pack()

def start_timer(self):
Expand All @@ -30,6 +72,9 @@ def __init__(self, master, **kwargs):
self.main_frame = PomodoroFrame(self.tab("Main"))
self.main_frame.pack()

self.settings_frame = SettingsFrame(self.tab("Settings"))
self.settings_frame.pack()


class PomodoroApp(ctk.CTk):
WIDTH = 350
Expand All @@ -46,5 +91,6 @@ def __init__(self):


if __name__ == "__main__":
load_theme()
app = PomodoroApp()
app.mainloop()

0 comments on commit ccda1bb

Please sign in to comment.