diff --git a/menus/add_music.py b/menus/add_music.py index 70adc9a..0465668 100644 --- a/menus/add_music.py +++ b/menus/add_music.py @@ -6,16 +6,17 @@ from menus.file_manager import FileManager from arcade.gui.experimental.focus import UIFocusGroup class AddMusic(arcade.gui.UIView): - def __init__(self, pypresence_client, *args, music_file_selected=None): + def __init__(self, pypresence_client, *args, playlist_selected=None, music_file_selected=None): super().__init__() self.args = args - self.music_file_selected = music_file_selected - + with open("settings.json", "r", encoding="utf-8") as file: self.settings_dict = json.load(file) self.playlists = self.settings_dict.get("playlists", {}) + self.music_file_selected = music_file_selected + self.playlist_selected = playlist_selected or list(self.playlists.keys())[0] self.pypresence_client = pypresence_client self.pypresence_client.update(state="Adding music to playlist", start=self.pypresence_client.start_time) @@ -28,7 +29,7 @@ class AddMusic(arcade.gui.UIView): self.playlist_label = self.box.add(arcade.gui.UILabel(text="Playlist", font_name="Roboto", font_size=32)) - self.playlist_option = self.box.add(arcade.gui.UIDropdown(default=list(self.playlists.keys())[0], options=list(self.playlists.keys()), width=self.window.width / 2, height=self.window.height / 15, primary_style=button_style, dropdown_style=button_style, active_style=button_style)) + self.playlist_option = self.box.add(arcade.gui.UIDropdown(default=self.playlist_selected, options=list(self.playlists.keys()), width=self.window.width / 2, height=self.window.height / 15, primary_style=button_style, dropdown_style=button_style, active_style=button_style)) self.music_label = self.box.add(arcade.gui.UILabel(text="Music File Path", font_name="Roboto", font_size=32)) @@ -44,7 +45,7 @@ class AddMusic(arcade.gui.UIView): self.anchor.detect_focusable_widgets() def select_file(self): - self.window.show_view(FileManager(os.path.expanduser("~"), [f".{extension}" for extension in audio_extensions], "file", self.pypresence_client, *self.args)) + self.window.show_view(FileManager(os.path.expanduser("~"), [f".{extension}" for extension in audio_extensions], "file", self.pypresence_client, self.playlist_selected, *self.args)) def add_music(self): music_path = self.music_file_selected diff --git a/menus/file_manager.py b/menus/file_manager.py index f8d6079..0b3ab86 100644 --- a/menus/file_manager.py +++ b/menus/file_manager.py @@ -15,7 +15,11 @@ class FileManager(arcade.gui.UIView): self.file_buttons = [] self.submitted_content = "" self.done = False - self.args = args + + if not self.select_mode == "file": + self.args = args + else: + self.playlist_selected, *self.args = args self.anchor = self.ui.add(arcade.gui.UIAnchorLayout(size_hint=(1, 1))) self.box = self.anchor.add(arcade.gui.UIBoxLayout(size_hint=(0.7, 0.7)), anchor_x="center", anchor_y="center") @@ -40,7 +44,7 @@ class FileManager(arcade.gui.UIView): self.scroll_area.add(self.files_box) self.back_button = self.anchor.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='<--', style=button_style, width=100, height=50), anchor_x="left", anchor_y="top", align_x=5, align_y=-5) - self.back_button.on_click = lambda event: self.change_directory(os.path.dirname(self.current_directory)) + self.back_button.on_click = lambda event: self.main_exit() self.show_directory() @@ -110,6 +114,9 @@ class FileManager(arcade.gui.UIView): self.current_directory_label.text = self.current_directory + self.file_buttons.append(self.files_box.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text="Back", style=button_style, width=self.window.width / 1.5))) + self.file_buttons[-1].on_click = lambda event, directory=os.path.dirname(self.current_directory): self.change_directory(directory) + for file in self.get_content(self.current_directory): self.file_buttons.append(self.files_box.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text=file, style=button_style, width=self.window.width / 1.5))) @@ -128,9 +135,8 @@ class FileManager(arcade.gui.UIView): def on_key_press(self, symbol: int, modifiers: int) -> bool | None: if symbol == arcade.key.ESCAPE: - from menus.main import Main - self.window.show_view(Main(*self.args)) + self.main_exit() - def on_mouse_press(self, x, y, button, modifiers): - if button == arcade.MOUSE_BUTTON_RIGHT: - self.change_directory(os.path.dirname(self.current_directory)) \ No newline at end of file + def main_exit(self): + from menus.main import Main + self.window.show_view(Main(*self.args)) diff --git a/menus/main.py b/menus/main.py index 9d3c750..e99845f 100644 --- a/menus/main.py +++ b/menus/main.py @@ -516,7 +516,10 @@ class Main(arcade.gui.UIView): self.skip_sound() # reset properties if self.shuffle: - self.queue.append(f"{self.current_tab}/{random.choice(self.tab_content[self.current_tab])}") + if self.current_mode == "files": + self.queue.append(f"{self.current_tab}/{random.choice(self.tab_content[self.current_tab])}") + elif self.current_mode == "playlist": + self.queue.append(random.choice(self.playlist_content[self.current_tab])) if not self.current_music_player is None: if self.time_to_seek is not None: