mirror of
https://github.com/csd4ni3l/music-player.git
synced 2026-01-01 12:13:42 +01:00
Fix add music, new tab, and tabs not being removed
This commit is contained in:
@@ -6,16 +6,10 @@ from menus.file_manager import FileManager
|
|||||||
from arcade.gui.experimental.focus import UIFocusGroup
|
from arcade.gui.experimental.focus import UIFocusGroup
|
||||||
|
|
||||||
class AddMusic(arcade.gui.UIView):
|
class AddMusic(arcade.gui.UIView):
|
||||||
def __init__(self, pypresence_client, current_mode, current_music_name, current_length, current_music_player, queue, loaded_sounds, shuffle, music_file_selected=None):
|
def __init__(self, pypresence_client, *args, music_file_selected=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.current_mode = current_mode
|
self.args = args
|
||||||
self.current_music_name = current_music_name
|
|
||||||
self.current_length = current_length
|
|
||||||
self.current_music_player = current_music_player
|
|
||||||
self.queue = queue
|
|
||||||
self.loaded_sounds = loaded_sounds
|
|
||||||
self.shuffle = shuffle
|
|
||||||
self.music_file_selected = music_file_selected
|
self.music_file_selected = music_file_selected
|
||||||
|
|
||||||
with open("settings.json", "r", encoding="utf-8") as file:
|
with open("settings.json", "r", encoding="utf-8") as file:
|
||||||
@@ -50,7 +44,7 @@ class AddMusic(arcade.gui.UIView):
|
|||||||
self.anchor.detect_focusable_widgets()
|
self.anchor.detect_focusable_widgets()
|
||||||
|
|
||||||
def select_file(self):
|
def select_file(self):
|
||||||
self.window.show_view(FileManager(os.path.expanduser("~"), [f".{extension}" for extension in audio_extensions], "file", self.pypresence_client, self.current_mode, self.current_music_name, self.current_length, self.current_music_player, self.queue, self.loaded_sounds, self.shuffle))
|
self.window.show_view(FileManager(os.path.expanduser("~"), [f".{extension}" for extension in audio_extensions], "file", self.pypresence_client, *self.args))
|
||||||
|
|
||||||
def add_music(self):
|
def add_music(self):
|
||||||
music_path = self.music_file_selected
|
music_path = self.music_file_selected
|
||||||
@@ -73,4 +67,4 @@ class AddMusic(arcade.gui.UIView):
|
|||||||
|
|
||||||
def main_exit(self):
|
def main_exit(self):
|
||||||
from menus.main import Main
|
from menus.main import Main
|
||||||
self.window.show_view(Main(self.pypresence_client, self.current_mode, self.current_music_name, self.current_length, self.current_music_player, self.queue, self.loaded_sounds, self.shuffle))
|
self.window.show_view(Main(self.pypresence_client, *self.args))
|
||||||
|
|||||||
@@ -10,16 +10,10 @@ from utils.constants import button_style
|
|||||||
from utils.preload import button_texture, button_hovered_texture
|
from utils.preload import button_texture, button_hovered_texture
|
||||||
|
|
||||||
class Downloader(arcade.gui.UIView):
|
class Downloader(arcade.gui.UIView):
|
||||||
def __init__(self, pypresence_client, current_mode, current_music_name, current_length, current_music_player, queue, loaded_sounds, shuffle):
|
def __init__(self, pypresence_client, *args):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.current_mode = current_mode
|
self.args = args
|
||||||
self.current_music_name = current_music_name
|
|
||||||
self.current_length = current_length
|
|
||||||
self.current_music_player = current_music_player
|
|
||||||
self.queue = queue
|
|
||||||
self.loaded_sounds = loaded_sounds
|
|
||||||
self.shuffle = shuffle
|
|
||||||
|
|
||||||
self.pypresence_client = pypresence_client
|
self.pypresence_client = pypresence_client
|
||||||
self.pypresence_client.update(state="Downloading music", start=self.pypresence_client.start_time)
|
self.pypresence_client.update(state="Downloading music", start=self.pypresence_client.start_time)
|
||||||
@@ -191,4 +185,4 @@ class Downloader(arcade.gui.UIView):
|
|||||||
|
|
||||||
def main_exit(self):
|
def main_exit(self):
|
||||||
from menus.main import Main
|
from menus.main import Main
|
||||||
self.window.show_view(Main(self.pypresence_client, self.current_mode, self.current_music_name, self.current_length, self.current_music_player, self.queue, self.loaded_sounds, self.shuffle))
|
self.window.show_view(Main(self.pypresence_client, *self.args))
|
||||||
|
|||||||
@@ -439,6 +439,10 @@ class Main(arcade.gui.UIView):
|
|||||||
self.should_reload = True # needed because the observer runs in another thread and OpenGL is single-threaded.
|
self.should_reload = True # needed because the observer runs in another thread and OpenGL is single-threaded.
|
||||||
|
|
||||||
def load_tabs(self):
|
def load_tabs(self):
|
||||||
|
for button in self.tab_buttons.values():
|
||||||
|
self.tab_box.remove(button)
|
||||||
|
self.tab_buttons.clear()
|
||||||
|
|
||||||
if self.current_mode == "files":
|
if self.current_mode == "files":
|
||||||
for tab in self.tab_options:
|
for tab in self.tab_options:
|
||||||
self.tab_buttons[os.path.expanduser(tab)] = self.tab_box.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text=os.path.basename(os.path.normpath(os.path.expanduser(tab))), style=button_style, width=self.window.width / 10, height=self.window.height / 15))
|
self.tab_buttons[os.path.expanduser(tab)] = self.tab_box.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text=os.path.basename(os.path.normpath(os.path.expanduser(tab))), style=button_style, width=self.window.width / 10, height=self.window.height / 15))
|
||||||
|
|||||||
@@ -8,16 +8,10 @@ from menus.file_manager import FileManager
|
|||||||
from arcade.gui.experimental.focus import UIFocusGroup
|
from arcade.gui.experimental.focus import UIFocusGroup
|
||||||
|
|
||||||
class NewTab(arcade.gui.UIView):
|
class NewTab(arcade.gui.UIView):
|
||||||
def __init__(self, pypresence_client, current_mode, current_music_name, current_length, current_music_player, queue, loaded_sounds, shuffle, directory_selected=None):
|
def __init__(self, pypresence_client, *args, directory_selected=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.current_mode = current_mode
|
self.args = args
|
||||||
self.current_music_name = current_music_name
|
|
||||||
self.current_length = current_length
|
|
||||||
self.current_music_player = current_music_player
|
|
||||||
self.queue = queue
|
|
||||||
self.loaded_sounds = loaded_sounds
|
|
||||||
self.shuffle = shuffle
|
|
||||||
self.directory_selected = directory_selected
|
self.directory_selected = directory_selected
|
||||||
|
|
||||||
with open("settings.json", "r", encoding="utf-8") as file:
|
with open("settings.json", "r", encoding="utf-8") as file:
|
||||||
@@ -26,6 +20,8 @@ class NewTab(arcade.gui.UIView):
|
|||||||
self.tab_options = self.settings_dict.get("tab_options", [os.path.join("~", "Music"), os.path.join("~", "Downloads")])
|
self.tab_options = self.settings_dict.get("tab_options", [os.path.join("~", "Music"), os.path.join("~", "Downloads")])
|
||||||
self.playlists = self.settings_dict.get("playlists", {})
|
self.playlists = self.settings_dict.get("playlists", {})
|
||||||
|
|
||||||
|
self.current_mode = self.args[0]
|
||||||
|
|
||||||
self.pypresence_client = pypresence_client
|
self.pypresence_client = pypresence_client
|
||||||
self.pypresence_client.update(state="Adding new tab", start=self.pypresence_client.start_time)
|
self.pypresence_client.update(state="Adding new tab", start=self.pypresence_client.start_time)
|
||||||
|
|
||||||
@@ -43,6 +39,7 @@ class NewTab(arcade.gui.UIView):
|
|||||||
|
|
||||||
self.new_tab_button = self.box.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='Add new tab', style=button_style, width=self.window.width / 2, height=self.window.height / 10))
|
self.new_tab_button = self.box.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='Add new tab', style=button_style, width=self.window.width / 2, height=self.window.height / 10))
|
||||||
self.new_tab_button.on_click = lambda event: self.add_tab()
|
self.new_tab_button.on_click = lambda event: self.add_tab()
|
||||||
|
|
||||||
elif self.current_mode == "playlist":
|
elif self.current_mode == "playlist":
|
||||||
self.new_tab_label = self.box.add(arcade.gui.UILabel(text="New Playlist Name:", font_name="Roboto", font_size=32))
|
self.new_tab_label = self.box.add(arcade.gui.UILabel(text="New Playlist Name:", font_name="Roboto", font_size=32))
|
||||||
|
|
||||||
@@ -57,7 +54,7 @@ class NewTab(arcade.gui.UIView):
|
|||||||
self.anchor.detect_focusable_widgets()
|
self.anchor.detect_focusable_widgets()
|
||||||
|
|
||||||
def select_directory(self):
|
def select_directory(self):
|
||||||
self.window.show_view(FileManager(os.path.expanduser("~"), [], "directory", self.pypresence_client, self.current_mode, self.current_music_name, self.current_length, self.current_music_player, self.queue, self.loaded_sounds, self.shuffle))
|
self.window.show_view(FileManager(os.path.expanduser("~"), [], "directory", self.pypresence_client, *self.args))
|
||||||
|
|
||||||
def add_tab(self):
|
def add_tab(self):
|
||||||
if self.current_mode == "files":
|
if self.current_mode == "files":
|
||||||
@@ -84,4 +81,4 @@ class NewTab(arcade.gui.UIView):
|
|||||||
|
|
||||||
def main_exit(self):
|
def main_exit(self):
|
||||||
from menus.main import Main
|
from menus.main import Main
|
||||||
self.window.show_view(Main(self.pypresence_client, self.current_mode, self.current_music_name, self.current_length, self.current_music_player, self.queue, self.loaded_sounds, self.shuffle))
|
self.window.show_view(Main(self.pypresence_client, *self.args))
|
||||||
|
|||||||
Reference in New Issue
Block a user