Skip to content

Commit

Permalink
Black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
linsomniac committed Feb 7, 2024
1 parent ffdee57 commit e7736a1
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions spotify2ytmusic/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit e7736a1

Please sign in to comment.