Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pupgui2/pupgui2gamelistdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def update_game_list_steam(self, cached=True):
ctools = [c if c != 'SteamTinkerLaunch' else 'Proton-stl' for c in sort_compatibility_tool_names(list_installed_ctools(self.install_dir, without_version=True), reverse=True)]
ctools.extend(t.ctool_name for t in get_steam_ctool_list(steam_config_folder=self.install_loc.get('vdf_dir'), cached=True))

qt_sort = self.gamelist_disable_sort(len(self.games))

self.ui.tableGames.setRowCount(len(self.games))

game_id_table_lables = []
Expand Down Expand Up @@ -195,12 +197,16 @@ def update_game_list_steam(self, cached=True):

game_id_table_lables.append(game.app_id)

self.gamelist_enable_sort(qt_sort)

def update_game_list_lutris(self):
""" update the game list for the Lutris launcher """
# Filter blank runners and Steam games, because we can't change any compat tool options for Steam games via Lutris
# Steam games can be seen from the Steam games list, so no need to duplicate it here
self.games: list[LutrisGame] = [game for game in get_lutris_game_list(self.install_loc) if self.is_valid_lutris_gameslist_game(game)]

qt_sort = self.gamelist_disable_sort(len(self.games))

self.ui.tableGames.setRowCount(len(self.games))

# Not sure if we can allow compat tool updating from here, as Lutris allows configuring more than just Wine version
Expand Down Expand Up @@ -257,11 +263,15 @@ def update_game_list_lutris(self):
self.ui.tableGames.setItem(i, 1, runner_item)
self.ui.tableGames.setItem(i, 2, install_dir_item)
self.ui.tableGames.setItem(i, 3, install_date_item)

self.gamelist_enable_sort(qt_sort)

def update_game_list_heroic(self):
heroic_dir = os.path.join(os.path.expanduser(self.install_loc.get('install_dir')), '../..')
self.games: list[HeroicGame] = list(filter(lambda heroic_game: (heroic_game.is_installed and len(heroic_game.runner) > 0 and not heroic_game.is_dlc), get_heroic_game_list(heroic_dir)))

qt_sort = self.gamelist_disable_sort(len(self.games))

ctools_heroic = get_heroic_ctool_list(heroic_dir)

self.ui.tableGames.setRowCount(len(self.games))
Expand Down Expand Up @@ -327,10 +337,14 @@ def update_game_list_heroic(self):
self.ui.tableGames.setItem(i, 2, install_path_item)
self.ui.tableGames.setItem(i, 3, runner_item)

self.gamelist_enable_sort(qt_sort)

def update_game_list_epic(self):
epic_dir = get_epic_dir_from_install_dir(self.install_loc.get('install_dir'))
self.games: list[EpicGame] = get_epic_game_list(epic_dir)

qt_sort = self.gamelist_disable_sort(len(self.games))

self.ui.tableGames.setRowCount(len(self.games))

for i, game in enumerate(self.games):
Expand Down Expand Up @@ -364,6 +378,8 @@ def update_game_list_epic(self):
self.ui.tableGames.setItem(i, 2, install_path_item)
self.ui.tableGames.setItem(i, 3, platform_item)

self.gamelist_enable_sort(qt_sort)

def set_apply_btn_text(self):
""" Set text for Apply button to 'Close' if the games list is empty, if the current launcher is not Steam or if there are no queued changes."""

Expand Down Expand Up @@ -406,6 +422,23 @@ def btn_shortcut_editor_clicked(self):
self.ui.close()
PupguiShortcutDialog(self.install_loc.get('vdf_dir'), self.game_property_changed, self.ui)

def gamelist_disable_sort(self, row_count: int) -> bool:
""" Disable Qt sorting of a gamelist temporarily and empty the gamelist to generate a fresh list from scratch. Needs to be enabled later on with <gamelist_enable_sort> """
gamelist = self.ui.tableGames

# Sorting must be off while filling the table, otherwise setItem() re-sorts
# and the row moves away from index i before the other columns are written
is_sorted = gamelist.isSortingEnabled()
gamelist.setSortingEnabled(False)
gamelist.setRowCount(0) # drop stale items from the previous load
gamelist.setRowCount(row_count)

return is_sorted

def gamelist_enable_sort(self, is_sorted: bool):
""" Restore the Qt sorting state; Qt re-applies the sort currently shown in the header """
self.ui.tableGames.setSortingEnabled(is_sorted)

def search_gamelist_games(self, text):
for row in range(self.ui.tableGames.rowCount()):
should_hide: bool = not text.lower() in self.ui.tableGames.item(row, 0).text().lower()
Expand Down
Loading