33
44from utils .preload import *
55from utils .constants import button_style , slider_style , audio_extensions , discord_presence_id
6- from utils .utils import FakePyPresence , UIFocusTextureButton , Card , extract_metadata , get_audio_thumbnail_texture , truncate_end
6+ from utils .utils import FakePyPresence , UIFocusTextureButton , Card , extract_metadata , get_audio_thumbnail_texture , truncate_end , get_wrapped_text
77
88from math import ceil
99from thefuzz import process , fuzz
@@ -56,7 +56,9 @@ def __init__(self, pypresence_client: None | FakePyPresence | pypresence.Presenc
5656
5757 self .tab_options = self .settings_dict .get ("tab_options" , [os .path .join ("~" , "Music" ), os .path .join ("~" , "Downloads" )])
5858 self .tab_content = {}
59+ self .tab_wrapped_text = {}
5960 self .playlist_content = {}
61+ self .playlist_wrapped_text = {}
6062 self .thumbnails = {}
6163 self .tab_buttons = {}
6264 self .music_buttons = {}
@@ -105,7 +107,7 @@ def create_ui(self):
105107 self .scrollbar .size_hint = (0.02 , 1 )
106108 self .scroll_box .add (self .scrollbar )
107109
108- self .music_grid = arcade .gui .UIGridLayout (horizontal_spacing = 30 , vertical_spacing = 30 , row_count = 100 , column_count = 5 )
110+ self .music_grid = arcade .gui .UIGridLayout (horizontal_spacing = 30 , vertical_spacing = 30 , row_count = 100 , column_count = 8 )
109111 self .scroll_area .add (self .music_grid )
110112
111113 # Utility
@@ -259,20 +261,21 @@ def show_content(self, tab):
259261 self .highest_score_file = f"{ self .current_tab } /{ matches [0 ][0 ]} "
260262 for n , match in enumerate (matches ):
261263 music_filename = match [0 ]
262- self .music_buttons [music_filename ] = self .music_grid .add (Card (card_texture = self .thumbnails [f"{ tab } /{ music_filename } " ], font_name = "Roboto" , font_size = 13 , text = music_filename , width = self .window .width / 7 , height = self .window .height / 7 ), row = 0 , column = n )
264+ self .music_buttons [music_filename ] = self .music_grid .add (Card (card_texture = self .thumbnails [f"{ tab } /{ music_filename } " ], font_name = "Roboto" , font_size = 13 , text = music_filename , width = self .window .width / 11 , height = self .window .height / 11 ), row = 0 , column = n )
263265 self .music_buttons [music_filename ].button .on_click = lambda event , tab = tab , music_filename = music_filename : self .queue .append (f"{ tab } /{ music_filename } " )
264266 else :
265- self .music_grid .row_count = ceil (len (self .tab_content [tab ]) / 5 )
267+ self .music_grid .row_count = ceil (len (self .tab_content [tab ]) / 8 )
266268 self .music_grid ._update_size_hints ()
267269
268270 self .highest_score_file = ""
269271
270272 self .no_music_label .visible = not self .tab_content [tab ]
273+
271274 for n , music_filename in enumerate (self .tab_content [tab ]):
272- row = n // 5
273- col = n % 5
275+ row = n // 8
276+ col = n % 8
274277
275- self .music_buttons [music_filename ] = self .music_grid .add (Card (card_texture = self .thumbnails [f"{ tab } /{ music_filename } " ], font_name = "Roboto" , font_size = 13 , text = music_filename , width = self .window .width / 7 , height = self .window .height / 7 ), row = row , column = col )
278+ self .music_buttons [music_filename ] = self .music_grid .add (Card (card_texture = self .thumbnails [f"{ tab } /{ music_filename } " ], font_name = "Roboto" , font_size = 13 , text = self . tab_wrapped_text [ tab ][ n ] , width = self .window .width / 11 , height = self .window .height / 11 ), row = row , column = col )
276279 self .music_buttons [music_filename ].button .on_click = lambda event , tab = tab , music_filename = music_filename : self .queue .append (f"{ tab } /{ music_filename } " )
277280
278281 elif self .current_mode == "playlist" :
@@ -284,46 +287,51 @@ def show_content(self, tab):
284287 self .highest_score_file = matches [0 ][0 ]
285288 for n , match in enumerate (matches ):
286289 music_filename = match [0 ]
287- self .music_buttons [music_filename ] = self .music_grid .add (Card (card_texture = self .thumbnails [music_filename ], font_name = "Roboto" , font_size = 13 , text = music_filename , width = self .window .width / 6 , height = self .window .height / 5 ), row = 0 , column = n )
290+ self .music_buttons [music_filename ] = self .music_grid .add (Card (card_texture = self .thumbnails [music_filename ], font_name = "Roboto" , font_size = 13 , text = music_filename , width = self .window .width / 11 , height = self .window .height / 11 ), row = 0 , column = n )
288291 self .music_buttons [music_filename ].button .on_click = lambda event , tab = tab , music_filename = music_filename : self .queue .append (music_filename )
289292
290293 else :
291- self .music_grid .row_count = ceil ((len (self .playlist_content [tab ]) + 1 ) / 5 )
294+ self .music_grid .row_count = ceil ((len (self .playlist_content [tab ]) + 1 ) / 8 )
292295 self .music_grid ._update_size_hints ()
293296
294297 self .highest_score_file = ""
295298
296299 self .no_music_label .visible = not self .playlist_content [tab ]
297300
298301 for n , music_filename in enumerate (self .playlist_content [tab ]):
299- row = n // 5
300- col = n % 5
302+ row = n // 8
303+ col = n % 8
301304
302- self .music_buttons [music_filename ] = self .music_grid .add (Card (card_texture = self .thumbnails [music_filename ], font_name = "Roboto" , font_size = 13 , text = music_filename , width = self .window .width / 6 , height = self .window .height / 5 ), row = row , column = col )
305+ self .music_buttons [music_filename ] = self .music_grid .add (Card (card_texture = self .thumbnails [music_filename ], font_name = "Roboto" , font_size = 13 , text = self . playlist_wrapped_text [ tab ][ n ] , width = self .window .width / 11 , height = self .window .height / 11 ), row = row , column = col )
303306 self .music_buttons [music_filename ].button .on_click = lambda event , tab = tab , music_filename = music_filename : self .queue .append (music_filename )
304- row = (n + 1 ) // 5
305- col = (n + 1 ) % 5
307+ row = (n + 1 ) // 8
308+ col = (n + 1 ) % 8
306309
307- self .music_buttons ["add_music" ] = self .music_grid .add (Card (card_texture = music_icon , font_name = "Roboto" , font_size = 13 , text = "Add Music" , width = self .window .width / 6 , height = self .window .height / 5 ), row = row , column = col )
310+ self .music_buttons ["add_music" ] = self .music_grid .add (Card (card_texture = music_icon , font_name = "Roboto" , font_size = 13 , text = "Add Music" , width = self .window .width / 11 , height = self .window .height / 11 ), row = row , column = col )
308311 self .music_buttons ["add_music" ].button .on_click = lambda event : self .add_music ()
309312
310313 self .update_buttons ()
311314
312315 def load_content (self ):
313316 for tab in self .tab_options :
314- self .tab_content [os .path .expanduser (tab )] = []
315- for filename in os .listdir (os .path .expanduser (tab )):
317+ expanded_tab = os .path .expanduser (tab )
318+ self .tab_content [expanded_tab ] = []
319+
320+ for filename in os .listdir (expanded_tab ):
316321 if filename .split ("." )[- 1 ] in audio_extensions :
317- if f"{ os .path .expanduser (tab )} /{ filename } " not in self .thumbnails :
318- self .thumbnails [f"{ os .path .expanduser (tab )} /{ filename } " ] = get_audio_thumbnail_texture (f"{ os .path .expanduser (tab )} /{ filename } " , self .window .size )
319- self .tab_content [os .path .expanduser (tab )].append (filename )
322+ if f"{ expanded_tab } /{ filename } " not in self .thumbnails :
323+ self .thumbnails [f"{ expanded_tab } /{ filename } " ] = get_audio_thumbnail_texture (f"{ expanded_tab } /{ filename } " , self .window .size )
324+ self .tab_content [expanded_tab ].append (filename )
325+
326+ self .tab_wrapped_text [expanded_tab ] = get_wrapped_text (self .tab_content [expanded_tab ], self .window .width // 11 , 14 )
320327
321- for content in self .settings_dict .get ("playlists" , {}).values ():
328+ for playlist , content in self .settings_dict .get ("playlists" , {}).items ():
322329 for file in content :
323330 if file not in self .thumbnails :
324331 self .thumbnails [file ] = get_audio_thumbnail_texture (file , self .window .size )
325332
326- self .playlist_content = self .settings_dict .get ("playlists" , {})
333+ self .playlist_content [playlist ] = content
334+ self .playlist_wrapped_text [playlist ] = get_wrapped_text (content , self .window .width // 11 , 14 )
327335
328336 def load_tabs (self ):
329337 self .tab_box .clear ()
0 commit comments