From e7736a1cf1c21e21906210c483dbd6d104cd8981 Mon Sep 17 00:00:00 2001 From: Sean Reifschneider Date: Tue, 6 Feb 2024 20:16:54 -0700 Subject: [PATCH] Black formatting --- spotify2ytmusic/gui.py | 47 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/spotify2ytmusic/gui.py b/spotify2ytmusic/gui.py index cf68157..d8c453e 100644 --- a/spotify2ytmusic/gui.py +++ b/spotify2ytmusic/gui.py @@ -15,7 +15,7 @@ def create_label(parent: tk.Frame, text: str, **kwargs) -> tk.Label: - """ Simply creates a label with the given text and the given parent. + """Simply creates a label with the given text and the given parent. Args: parent (tk.Frame): The parent of the label. @@ -35,7 +35,7 @@ def create_label(parent: tk.Frame, text: str, **kwargs) -> tk.Label: def create_button(parent: tk.Frame, text: str, **kwargs) -> tk.Button: - """ Simply creates a button with the given text and the given parent. + """Simply creates a button with the given text and the given parent. Args: parent (tk.Frame): The parent of the button. @@ -56,11 +56,10 @@ def create_button(parent: tk.Frame, text: str, **kwargs) -> tk.Button: class Window: - """ The main window of the application. It contains the tabs and the logs. - """ + """The main window of the application. It contains the tabs and the logs.""" + def __init__(self) -> None: - """ Initializes the main window of the application. It contains the tabs and the logs. - """ + """Initializes the main window of the application. It contains the tabs and the logs.""" self.root = tk.Tk() self.root.title("Spotify to YT Music") self.root.geometry("1280x720") @@ -106,9 +105,9 @@ def __init__(self) -> None: self.tab5 = ttk.Frame(self.tabControl) self.tab6 = ttk.Frame(self.tabControl) self.tab7 = ttk.Frame(self.tabControl) - - self.tabControl.add(self.tab1, text='Login to YT Music') - self.tabControl.add(self.tab2, text='Spotify backup') + + self.tabControl.add(self.tab1, text="Login to YT Music") + self.tabControl.add(self.tab2, text="Spotify backup") # self.tabControl.add(self.tab2, text='Reverse playlist') self.tabControl.add(self.tab3, text="Load liked songs") @@ -137,10 +136,16 @@ def __init__(self) -> None: # tab2 - create_label(self.tab2, text="First, you need to backup your spotify playlists").pack(anchor=tk.CENTER, - expand=True) - create_button(self.tab2, text="Backup", command=lambda: self.call_func(func=spotify_backup.main, args=(), next_tab=self.tab3)).pack( - anchor=tk.CENTER, expand=True) + create_label( + self.tab2, text="First, you need to backup your spotify playlists" + ).pack(anchor=tk.CENTER, expand=True) + create_button( + self.tab2, + text="Backup", + command=lambda: self.call_func( + func=spotify_backup.main, args=(), next_tab=self.tab3 + ), + ).pack(anchor=tk.CENTER, expand=True) # tab3 create_label(self.tab3, text="Now, you can load your liked songs.").pack( @@ -247,7 +252,6 @@ def __init__(self) -> None: menu_algo.pack(anchor=tk.CENTER, expand=True) menu_algo.config(background="#696969", foreground="#ffffff", border=1) - def redirector(self, input_str="") -> None: """ Inserts the input string into the logs widget and disables editing. @@ -261,10 +265,9 @@ def redirector(self, input_str="") -> None: self.logs.config(state=tk.DISABLED) if self.var_scroll.get(): self.logs.see(tk.END) - - + def call_func(self, func: Callable, args: tuple, next_tab: ttk.Frame) -> None: - """ Calls the given function in a separate thread and switches to the next tab when the function is done. + """Calls the given function in a separate thread and switches to the next tab when the function is done. Args: func (Callable): The function to be called. @@ -278,13 +281,13 @@ def call_func(self, func: Callable, args: tuple, next_tab: ttk.Frame) -> None: self.tabControl.select(next_tab) print() - def yt_login(self, auto=False) -> None: - """ Logs in to YT Music. If the oauth.json file is not found, it opens a new console window to run the 'ytmusicapi oauth' command. + """Logs in to YT Music. If the oauth.json file is not found, it opens a new console window to run the 'ytmusicapi oauth' command. Args: auto (bool, optional): Weather to automatically login using the oauth.json file. Defaults to False. """ + def run_in_thread(): if os.path.exists("oauth.json"): print("File detected, auto login") @@ -297,7 +300,8 @@ def run_in_thread(): # Open a new console window to run the command if os.name == "nt": # If the OS is Windows process = subprocess.Popen( - ["ytmusicapi", "oauth"], creationflags=subprocess.CREATE_NEW_CONSOLE + ["ytmusicapi", "oauth"], + creationflags=subprocess.CREATE_NEW_CONSOLE, ) process.communicate() else: # For Unix and Linux @@ -321,9 +325,8 @@ def run_in_thread(): th = threading.Thread(target=run_in_thread) th.start() - def load_write_settings(self, action: int) -> None: - """ Loads or writes the settings to the settings.json file. + """Loads or writes the settings to the settings.json file. Args: action (int): 0 to load the settings, 1 to write the settings.