mirror of
https://github.com/csd4ni3l/music-player.git
synced 2026-01-01 04:03:42 +01:00
fix playlist shuffling, improve file manager navigation, keep playlist selected after selecting a playlist when adding music
This commit is contained in:
@@ -6,16 +6,17 @@ 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, *args, music_file_selected=None):
|
def __init__(self, pypresence_client, *args, playlist_selected=None, music_file_selected=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.args = args
|
self.args = args
|
||||||
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:
|
||||||
self.settings_dict = json.load(file)
|
self.settings_dict = json.load(file)
|
||||||
|
|
||||||
self.playlists = self.settings_dict.get("playlists", {})
|
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 = pypresence_client
|
||||||
self.pypresence_client.update(state="Adding music to playlist", start=self.pypresence_client.start_time)
|
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_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))
|
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()
|
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.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):
|
def add_music(self):
|
||||||
music_path = self.music_file_selected
|
music_path = self.music_file_selected
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ class FileManager(arcade.gui.UIView):
|
|||||||
self.file_buttons = []
|
self.file_buttons = []
|
||||||
self.submitted_content = ""
|
self.submitted_content = ""
|
||||||
self.done = False
|
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.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")
|
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.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 = 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()
|
self.show_directory()
|
||||||
|
|
||||||
@@ -110,6 +114,9 @@ class FileManager(arcade.gui.UIView):
|
|||||||
|
|
||||||
self.current_directory_label.text = self.current_directory
|
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):
|
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)))
|
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:
|
def on_key_press(self, symbol: int, modifiers: int) -> bool | None:
|
||||||
if symbol == arcade.key.ESCAPE:
|
if symbol == arcade.key.ESCAPE:
|
||||||
from menus.main import Main
|
self.main_exit()
|
||||||
self.window.show_view(Main(*self.args))
|
|
||||||
|
|
||||||
def on_mouse_press(self, x, y, button, modifiers):
|
def main_exit(self):
|
||||||
if button == arcade.MOUSE_BUTTON_RIGHT:
|
from menus.main import Main
|
||||||
self.change_directory(os.path.dirname(self.current_directory))
|
self.window.show_view(Main(*self.args))
|
||||||
|
|||||||
@@ -516,7 +516,10 @@ class Main(arcade.gui.UIView):
|
|||||||
self.skip_sound() # reset properties
|
self.skip_sound() # reset properties
|
||||||
|
|
||||||
if self.shuffle:
|
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 not self.current_music_player is None:
|
||||||
if self.time_to_seek is not None:
|
if self.time_to_seek is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user