diff --git a/GUI.py b/GUI.py index 9b2208a..4c0cb6d 100644 --- a/GUI.py +++ b/GUI.py @@ -1,10 +1,15 @@ +from genericpath import isfile from main import main, shutdown from doctest import master import tkinter import tkinter.messagebox import customtkinter +import os +import toml +import shutil from utils.settings import check_toml +from utils import settings from pathlib import Path customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light" @@ -22,7 +27,6 @@ class App(customtkinter.CTk): self.geometry(f"{App.WIDTH}x{App.HEIGHT}") self.resizable(False, False) self.protocol("WM_DELETE_WINDOW", self.on_closing) # call .on_closing() when app gets closed - self.resizable(False, False) # ============ create two frames ============ @@ -191,7 +195,7 @@ class App(customtkinter.CTk): ) self.user_2fa.grid(row=7, column=0, padx=15) -# Thread Settings +# Thread Settings # Thread settings title self.thread_title = customtkinter.CTkLabel( @@ -377,14 +381,77 @@ class App(customtkinter.CTk): self.progressbar = customtkinter.CTkProgressBar(master=self.frame_info) self.progressbar.grid(row=1, column=0, sticky="ew", padx=15, pady=15) - # set the default values for the settings - directory = Path().absolute() - config = check_toml(f"{directory}/utils/.config.template.toml", "config.toml") +# Settings sync + + # Check if config.toml exists if not generates a new config with default values + if not os.path.isfile(f"config.toml"): + print("Can't find config generating new config") + open("config.toml", "w") + shutil.copyfile(f"utils/config.temp.toml", f"config.toml") + + config = toml.load(f"config.toml") # Loads config to be able to read and write + +# Sync config settings to gui + + # User Settings + + # User name + if not config["reddit"]["creds"]["username"] == "": + self.user_name.insert("0", config["reddit"]["creds"]["username"]) + + # User password + if not config["reddit"]["creds"]["password"] == "": + self.user_password.insert("0", config["reddit"]["creds"]["password"]) + + # Client Secret + if not config["reddit"]["creds"]["client_secret"] == "": + self.client_secret.insert("0", config["reddit"]["creds"]["client_secret"]) + + # Client Id + if not config["reddit"]["creds"]["client_id"] == "": + self.client_id.insert("0", config["reddit"]["creds"]["client_id"]) + + # 2fa + self.user_2fa.set(str(config["reddit"]["creds"]["2fa"])) + + # Thread Settings + + # Random + self.thread_random.set(str(config["reddit"]["thread"]["random"])) + + # Subreddit + if not config["reddit"]["thread"]["subreddit"] == "": + self.thread_subreddit.insert("0", config["reddit"]["thread"]["subreddit"]) + + # Post id + if not config["reddit"]["thread"]["post_id"] == "": + self.thread_post_id.insert("0", config["reddit"]["thread"]["post_id"]) + + # Max comment length + self.thread_max_comment_length.insert("0", config["reddit"]["thread"]["max_comment_length"]) + + # Post langauge + self.thread_post_lang.insert("0", config["reddit"]["thread"]["post_lang"]) + + # Min comments + self.thread_min_comment_length("0", config["reddit"]["thread"]["min_comments"]) + + # Misc Settings + + # Allow nsfw self.misc_allow_nsfw.set(str(config["settings"]["allow_nsfw"])) - self.misc_theme.set(config["settings"]["theme"]) - self.misc_times_to_run.insert(0, config["settings"]["times_to_run"]) - self.misc_opacity.insert(0, config["settings"]["opacity"]) - print("Settings imported!") + + # Theme + self.misc_theme.insert("0", config["settings"]["theme"]) + + # Times to run + self.misc_times_to_run.insert("0", config["settings"]["times_to_run"]) + + # Opacity + self.misc_opacity.insert("0", config["settings"]["opacity"]) + + + # Show frame def showFrame(self, frame): @@ -415,9 +482,9 @@ class App(customtkinter.CTk): self.destroy() shutdown() -def start(): +def launchGui(): if __name__ == "__main__": app = App() app.mainloop() -start() \ No newline at end of file +launchGui() \ No newline at end of file diff --git a/main.py b/main.py index 93b4a13..4d63ec8 100755 --- a/main.py +++ b/main.py @@ -75,30 +75,32 @@ def shutdown(): exit() -if __name__ == "__main__": - assert sys.version_info >= (3, 9), "Python 3.10 or higher is required" - config = settings.check_toml("utils/.config.template.toml", "config.toml") - config is False and exit() - try: - if len(config["reddit"]["thread"]["post_id"].split("+")) > 1: - for index, post_id in enumerate(config["reddit"]["thread"]["post_id"].split("+")): - index += 1 - print_step( - f'on the {index}{("st" if index % 10 == 1 else ("nd" if index % 10 == 2 else ("rd" if index % 10 == 3 else "th")))} post of {len(config["reddit"]["thread"]["post_id"].split("+"))}' - ) - main(post_id) - Popen("cls" if name == "nt" else "clear", shell=True).wait() - elif config["settings"]["times_to_run"]: - run_many(config["settings"]["times_to_run"]) - else: - main() - except KeyboardInterrupt: - shutdown() - except ResponseException: - # error for invalid credentials - print_markdown("## Invalid credentials") - print_markdown("Please check your credentials in the config.toml file") +def start(): + if __name__ == "__main__": + assert sys.version_info >= (3, 9), "Python 3.10 or higher is required" + config = settings.check_toml("utils/.config.template.toml", "config.toml") + config is False and exit() + try: + if len(config["reddit"]["thread"]["post_id"].split("+")) > 1: + for index, post_id in enumerate(config["reddit"]["thread"]["post_id"].split("+")): + index += 1 + print_step( + f'on the {index}{("st" if index % 10 == 1 else ("nd" if index % 10 == 2 else ("rd" if index % 10 == 3 else "th")))} post of {len(config["reddit"]["thread"]["post_id"].split("+"))}' + ) + main(post_id) + Popen("cls" if name == "nt" else "clear", shell=True).wait() + elif config["settings"]["times_to_run"]: + run_many(config["settings"]["times_to_run"]) + else: + main() + except KeyboardInterrupt: + shutdown() + except ResponseException: + # error for invalid credentials + print_markdown("## Invalid credentials") + print_markdown("Please check your credentials in the config.toml file") + + shutdown() - shutdown() + # todo error - # todo error diff --git a/utils/config.temp.toml b/utils/config.temp.toml new file mode 100644 index 0000000..1f5c5e0 --- /dev/null +++ b/utils/config.temp.toml @@ -0,0 +1,33 @@ +[settings] +allow_nsfw = false +theme = "dark" +times_to_run = 1 +opacity = 0.9 +transition = 0.2 +storymode = false + +[settings.background] +background_choice = "minecraft" + +[settings.tts] +voice_choice = "tiktok" +aws_polly_voice = "Matthew" +streamlabs_polly_voice = "Matthew" +tiktok_voice = "en_us_006" +python_voice = "1" +py_voice_num = "2" + +[reddit.creds] +client_id = "" +client_secret = "" +username = "" +password = "" +2fa = false + +[reddit.thread] +random = false +subreddit = "" +post_id = "" +max_comment_length = 50 +post_lang = "" +min_comments = 20