Skip to content

Commit

Permalink
bottles-preferences: Fully utilize list splices
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEvilSkeleton authored and mirkobrombin committed Dec 12, 2024
1 parent 9ea570a commit af29960
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 68 deletions.
18 changes: 15 additions & 3 deletions bottles/frontend/ui/details-preferences.blp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ template $DetailsPreferences: Adw.PreferencesPage {
visible: false;
}

model: StringList str_list_dxvk {};
model: StringList str_list_dxvk {
strings [
_("Disabled"),
]
};
}

Adw.ComboRow combo_vkd3d {
Expand All @@ -48,7 +52,11 @@ template $DetailsPreferences: Adw.PreferencesPage {
visible: false;
}

model: StringList str_list_vkd3d {};
model: StringList str_list_vkd3d {
strings [
_("Disabled"),
]
};
}

Adw.ComboRow combo_nvapi {
Expand All @@ -74,7 +82,11 @@ template $DetailsPreferences: Adw.PreferencesPage {
visible: false;
}

model: StringList str_list_latencyflex {};
model: StringList str_list_latencyflex {
strings [
_("Disabled")
]
};
}
}

Expand Down
85 changes: 20 additions & 65 deletions bottles/frontend/views/bottle_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,37 +366,13 @@ def update_combo_components(self):
self.combo_language.handler_block_by_func(self.__set_language)
self.combo_windows.handler_block_by_func(self.__set_windows)

for string_list in [
self.str_list_runner,
self.str_list_dxvk,
self.str_list_vkd3d,
self.str_list_nvapi,
self.str_list_latencyflex,
self.str_list_languages,
self.str_list_windows,
]:
string_list.splice(0, string_list.get_n_items())

self.str_list_dxvk.append("Disabled")
self.str_list_vkd3d.append("Disabled")
self.str_list_latencyflex.append("Disabled")
for index, dxvk in enumerate(self.manager.dxvk_available):
self.str_list_dxvk.append(dxvk)

for index, vkd3d in enumerate(self.manager.vkd3d_available):
self.str_list_vkd3d.append(vkd3d)

for index, runner in enumerate(self.manager.runners_available):
self.str_list_runner.append(runner)

for index, nvapi in enumerate(self.manager.nvapi_available):
self.str_list_nvapi.append(nvapi)

for index, latencyflex in enumerate(self.manager.latencyflex_available):
self.str_list_latencyflex.append(latencyflex)
self.str_list_runner.splice(0, self.str_list_runner.get_n_items(), self.manager.runners_available)
self.str_list_nvapi.splice(0, self.str_list_nvapi.get_n_items(), self.manager.nvapi_available)
self.str_list_languages.splice(0, self.str_list_languages.get_n_items(), ManagerUtils.get_languages())

for lang in ManagerUtils.get_languages():
self.str_list_languages.append(lang)
self.str_list_dxvk.splice(1, self.str_list_dxvk.get_n_items() - 1, self.manager.dxvk_available)
self.str_list_vkd3d.splice(1, self.str_list_vkd3d.get_n_items() - 1, self.manager.vkd3d_available)
self.str_list_latencyflex.splice(1, self.str_list_latencyflex.get_n_items() - 1, self.manager.latencyflex_available)

self.combo_runner.handler_unblock_by_func(self.__set_runner)
self.combo_dxvk.handler_unblock_by_func(self.__set_dxvk)
Expand Down Expand Up @@ -488,49 +464,37 @@ def set_config(self, config: BottleConfig):
"winxp": "Windows XP",
}

sync_types = [
"wine",
"esync",
"fsync",
]

if self.config.Arch == Arch.WIN32:
self.windows_versions["win98"] = "Windows 98"
self.windows_versions["win95"] = "Windows 95"

for index, windows_version in enumerate(self.windows_versions):
self.str_list_windows.append(self.windows_versions[windows_version])
if windows_version == self.config.Windows:
self.combo_windows.set_selected(index)
self.str_list_windows.splice(0, self.str_list_windows.get_n_items(), list(self.windows_versions.values()))
self.combo_windows.set_selected(list(self.windows_versions.keys()).index(self.config.Windows))
self.combo_nvapi.set_selected(self.manager.nvapi_available.index(self.config.NVAPI))
self.combo_sync.set_selected(sync_types.index(parameters.sync))
# endregion

parameters = self.config.Parameters

_dxvk = self.config.DXVK
# self.combo_windows.set_selected(self.manager.dxvk_available.index(self.config.DXVK))
if parameters.dxvk:
if _dxvk in self.manager.dxvk_available:
if _i_dxvk := self.manager.dxvk_available.index(_dxvk) + 1:
self.combo_dxvk.set_selected(_i_dxvk)
self.combo_dxvk.set_selected(self.manager.dxvk_available.index(self.config.DXVK) + 1)
else:
self.combo_dxvk.set_selected(0)

_vkd3d = self.config.VKD3D
if parameters.vkd3d:
if _vkd3d in self.manager.vkd3d_available:
if _i_vkd3d := self.manager.vkd3d_available.index(_vkd3d) + 1:
self.combo_vkd3d.set_selected(_i_vkd3d)
self.combo_vkd3d.set_selected(self.manager.vkd3d_available.index(self.config.VKD3D) + 1)
else:
self.combo_vkd3d.set_selected(0)

_nvapi = self.config.NVAPI
if _nvapi in self.manager.nvapi_available:
if _i_nvapi := self.manager.nvapi_available.index(_nvapi):
self.combo_nvapi.set_selected(_i_nvapi)

_latencyflex = self.config.LatencyFleX
if parameters.latencyflex:
if _latencyflex in self.manager.latencyflex_available:
if (
_i_latencyflex := self.manager.latencyflex_available.index(
_latencyflex
)
+ 1
):
self.combo_latencyflex.set_selected(_i_latencyflex)
self.combo_latencyflex.set_selected(self.manager.latencyflex_available.index(self.config.LatencyFleX) + 1)
else:
self.combo_latencyflex.set_selected(0)

Expand All @@ -539,15 +503,6 @@ def set_config(self, config: BottleConfig):
if _i_runner := self.manager.runners_available.index(_runner):
self.combo_runner.set_selected(_i_runner)

sync_types = [
"wine",
"esync",
"fsync",
]
for sync in sync_types:
if sync == parameters.sync:
self.combo_sync.set_selected(sync_types.index(sync))

# unlock functions connected to the widgets
self.switch_mangohud.handler_unblock_by_func(self.__toggle_feature)
self.switch_nvapi.handler_unblock_by_func(self.__toggle_nvapi)
Expand Down

0 comments on commit af29960

Please sign in to comment.