Skip to content

Commit

Permalink
Sort lists early to avoid any weird bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
milouk committed Sep 30, 2024
1 parent 2351676 commit 129f1b1
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def get_available_systems(self) -> list[str]:
filtered_systems = [
system for system in available_systems if system in all_systems
]
return filtered_systems
return sorted(filtered_systems)

def get_roms(self, system: str) -> list[Rom]:
roms = []
Expand All @@ -109,7 +109,7 @@ def get_roms(self, system: str) -> list[Rom]:
name = file_path.stem
rom = Rom(filename=file, name=name)
roms.append(rom)
return roms
return sorted(roms, key=lambda rom: rom.name)

def delete_all_files_in_directory(self, directory_path):
directory = Path(directory_path)
Expand Down Expand Up @@ -166,7 +166,7 @@ def load_emulators(self) -> None:
if len(available_systems) >= 1:
start_idx = int(selected_position / max_elem) * max_elem
end_idx = start_idx + max_elem
for i, system in enumerate(sorted(available_systems[start_idx:end_idx])):
for i, system in enumerate(available_systems[start_idx:end_idx]):
logo = f"{self.systems_logo_path}/{system}.png"
self.row_list(
system,
Expand Down Expand Up @@ -241,7 +241,6 @@ def load_roms(self) -> None:
time.sleep(2)
gr.draw_clear()
exit_menu = True
return

box_dir = Path(system["box"])
preview_dir = Path(system["preview"])
Expand Down Expand Up @@ -388,9 +387,7 @@ def load_roms(self) -> None:

start_idx = int(roms_selected_position / max_elem) * max_elem
end_idx = start_idx + max_elem
for i, rom in enumerate(
sorted(roms_without_image[start_idx:end_idx], key=lambda rom: rom.name)
):
for i, rom in enumerate(roms_without_image[start_idx:end_idx]):
self.row_list(
rom.name[:48] + "..." if len(rom.name) > 50 else rom.name,
(20, 50 + (i * 35)),
Expand Down

0 comments on commit 129f1b1

Please sign in to comment.