From c22c6f9378775ad59be69d951b2c0c4a305b5d58 Mon Sep 17 00:00:00 2001 From: Hari Rana Date: Sun, 22 Dec 2024 19:10:10 -0500 Subject: [PATCH] Reapply "bottle-preferences: Use single private method to toggle feature" This reverts commit 32bee7deb1103a733292d90654d57b41c9da5125. --- bottles/frontend/views/bottle_preferences.py | 179 +++++-------------- 1 file changed, 47 insertions(+), 132 deletions(-) diff --git a/bottles/frontend/views/bottle_preferences.py b/bottles/frontend/views/bottle_preferences.py index b36ef4da3a..87ad53a294 100644 --- a/bottles/frontend/views/bottle_preferences.py +++ b/bottles/frontend/views/bottle_preferences.py @@ -224,24 +224,25 @@ def __init__(self, details, config, **kwargs): ) self.btn_cwd.connect("clicked", self.choose_cwd) self.btn_cwd_reset.connect("clicked", self.reset_cwd, True) - self.switch_mangohud.connect("state-set", self.__toggle_mangohud) - self.switch_obsvkc.connect("state-set", self.__toggle_obsvkc) - self.switch_vkbasalt.connect("state-set", self.__toggle_vkbasalt) - self.switch_fsr.connect("state-set", self.__toggle_fsr) + self.switch_mangohud.connect("state-set", self.__toggle_feature, "mangohud") + self.switch_obsvkc.connect("state-set", self.__toggle_feature, "obsvkc") + self.switch_vkbasalt.connect("state-set", self.__toggle_feature, "vkbasalt") + self.switch_fsr.connect("state-set", self.__toggle_feature, "fsr") self.switch_nvapi.connect("state-set", self.__toggle_nvapi) - # self.switch_latencyflex.connect('state-set', self.__toggle_latencyflex) - self.switch_gamemode.connect("state-set", self.__toggle_gamemode) - self.switch_gamescope.connect("state-set", self.__toggle_gamescope) - self.switch_sandbox.connect("state-set", self.__toggle_sandbox) - self.switch_discrete.connect("state-set", self.__toggle_discrete_gpu) + self.switch_gamemode.connect("state-set", self.__toggle_feature, "gamemode") + self.switch_gamescope.connect("state-set", self.__toggle_feature, "gamescope") + self.switch_sandbox.connect("state-set", self.__toggle_feature, "sandbox") + self.switch_discrete.connect("state-set", self.__toggle_feature, "discrete_gpu") self.switch_versioning_compression.connect( "state-set", self.__toggle_versioning_compression ) - self.switch_auto_versioning.connect("state-set", self.__toggle_auto_versioning) + self.switch_auto_versioning.connect( + "state-set", self.__toggle_feature, "versioning_automatic" + ) self.switch_versioning_patterns.connect( - "state-set", self.__toggle_versioning_patterns + "state-set", self.__toggle_feature, "versioning_exclusion_patterns" ) - self.switch_vmtouch.connect("state-set", self.__toggle_vmtouch) + self.switch_vmtouch.connect("state-set", self.__toggle_feature, "vmtouch") self.combo_runner.connect("notify::selected", self.__set_runner) self.combo_dxvk.connect("notify::selected", self.__set_dxvk) self.combo_vkd3d.connect("notify::selected", self.__set_vkd3d) @@ -261,7 +262,9 @@ def __init__(self, details, config, **kwargs): if RuntimeManager.get_runtimes("steam"): self.row_steam_runtime.set_visible(True) - self.switch_steam_runtime.connect("state-set", self.__toggle_steam_runtime) + self.switch_steam_runtime.connect( + "state-set", self.__toggle_feature, "use_steam_runtime" + ) """Toggle some utilities according to its availability""" self.switch_gamemode.set_sensitive(gamemode_available) @@ -401,24 +404,22 @@ def set_config(self, config: BottleConfig): parameters = self.config.Parameters # temporary lock functions connected to the widgets - self.switch_mangohud.handler_block_by_func(self.__toggle_mangohud) + self.switch_mangohud.handler_block_by_func(self.__toggle_feature) self.switch_nvapi.handler_block_by_func(self.__toggle_nvapi) - self.switch_vkbasalt.handler_block_by_func(self.__toggle_vkbasalt) - self.switch_fsr.handler_block_by_func(self.__toggle_fsr) - self.switch_obsvkc.handler_block_by_func(self.__toggle_obsvkc) - self.switch_gamemode.handler_block_by_func(self.__toggle_gamemode) - self.switch_gamescope.handler_block_by_func(self.__toggle_gamescope) - self.switch_sandbox.handler_block_by_func(self.__toggle_sandbox) - self.switch_discrete.handler_block_by_func(self.__toggle_discrete_gpu) + self.switch_vkbasalt.handler_block_by_func(self.__toggle_feature) + self.switch_fsr.handler_block_by_func(self.__toggle_feature) + self.switch_obsvkc.handler_block_by_func(self.__toggle_feature) + self.switch_gamemode.handler_block_by_func(self.__toggle_feature) + self.switch_gamescope.handler_block_by_func(self.__toggle_feature) + self.switch_sandbox.handler_block_by_func(self.__toggle_feature) + self.switch_discrete.handler_block_by_func(self.__toggle_feature) self.switch_versioning_compression.handler_block_by_func( self.__toggle_versioning_compression ) - self.switch_auto_versioning.handler_block_by_func(self.__toggle_auto_versioning) - self.switch_versioning_patterns.handler_block_by_func( - self.__toggle_versioning_patterns - ) + self.switch_auto_versioning.handler_block_by_func(self.__toggle_feature) + self.switch_versioning_patterns.handler_block_by_func(self.__toggle_feature) with contextlib.suppress(TypeError): - self.switch_steam_runtime.handler_block_by_func(self.__toggle_steam_runtime) + self.switch_steam_runtime.handler_block_by_func(self.__toggle_feature) self.combo_runner.handler_block_by_func(self.__set_runner) self.combo_dxvk.handler_block_by_func(self.__set_dxvk) self.combo_vkd3d.handler_block_by_func(self.__set_vkd3d) @@ -537,28 +538,22 @@ def set_config(self, config: BottleConfig): self.combo_sync.set_selected(sync_types.index(sync)) # unlock functions connected to the widgets - self.switch_mangohud.handler_unblock_by_func(self.__toggle_mangohud) + self.switch_mangohud.handler_unblock_by_func(self.__toggle_feature) self.switch_nvapi.handler_unblock_by_func(self.__toggle_nvapi) - self.switch_vkbasalt.handler_unblock_by_func(self.__toggle_vkbasalt) - self.switch_fsr.handler_unblock_by_func(self.__toggle_fsr) - self.switch_obsvkc.handler_unblock_by_func(self.__toggle_obsvkc) - self.switch_gamemode.handler_unblock_by_func(self.__toggle_gamemode) - self.switch_gamescope.handler_unblock_by_func(self.__toggle_gamescope) - self.switch_sandbox.handler_unblock_by_func(self.__toggle_sandbox) - self.switch_discrete.handler_unblock_by_func(self.__toggle_discrete_gpu) + self.switch_vkbasalt.handler_unblock_by_func(self.__toggle_feature) + self.switch_fsr.handler_unblock_by_func(self.__toggle_feature) + self.switch_obsvkc.handler_unblock_by_func(self.__toggle_feature) + self.switch_gamemode.handler_unblock_by_func(self.__toggle_feature) + self.switch_gamescope.handler_unblock_by_func(self.__toggle_feature) + self.switch_sandbox.handler_unblock_by_func(self.__toggle_feature) + self.switch_discrete.handler_unblock_by_func(self.__toggle_feature) self.switch_versioning_compression.handler_unblock_by_func( self.__toggle_versioning_compression ) - self.switch_auto_versioning.handler_unblock_by_func( - self.__toggle_auto_versioning - ) - self.switch_versioning_patterns.handler_unblock_by_func( - self.__toggle_versioning_patterns - ) + self.switch_auto_versioning.handler_unblock_by_func(self.__toggle_feature) + self.switch_versioning_patterns.handler_unblock_by_func(self.__toggle_feature) with contextlib.suppress(TypeError): - self.switch_steam_runtime.handler_unblock_by_func( - self.__toggle_steam_runtime - ) + self.switch_steam_runtime.handler_unblock_by_func(self.__toggle_feature) self.combo_runner.handler_unblock_by_func(self.__set_runner) self.combo_dxvk.handler_unblock_by_func(self.__set_dxvk) self.combo_vkd3d.handler_unblock_by_func(self.__set_vkd3d) @@ -585,6 +580,12 @@ def __show_feature_dialog(self, _widget: Gtk.Widget, dialog: Adw.Window) -> None window = dialog(window=self.window, config=self.config) window.present() + def __toggle_feature(self, _widget: Gtk.Widget, state: bool, key: str) -> None: + """Toggle a specific feature.""" + self.config = self.manager.update_config( + config=self.config, key=key, value=state, scope="Parameters" + ).data["config"] + def __set_sync_type(self, *_args): """ Set the sync type (wine, esync, fsync) @@ -606,30 +607,6 @@ def __set_sync_type(self, *_args): self.combo_sync.set_sensitive(True) self.queue.end_task() - def __toggle_mangohud(self, widget, state): - """Toggle the Mangohud for current bottle""" - self.config = self.manager.update_config( - config=self.config, key="mangohud", value=state, scope="Parameters" - ).data["config"] - - def __toggle_obsvkc(self, widget, state): - """Toggle the OBS Vulkan capture for current bottle""" - self.config = self.manager.update_config( - config=self.config, key="obsvkc", value=state, scope="Parameters" - ).data["config"] - - def __toggle_vkbasalt(self, widget, state): - """Toggle the vkBasalt for current bottle""" - self.config = self.manager.update_config( - config=self.config, key="vkbasalt", value=state, scope="Parameters" - ).data["config"] - - def __toggle_fsr(self, widget, state): - """Toggle the FSR for current bottle""" - self.config = self.manager.update_config( - config=self.config, key="fsr", value=state, scope="Parameters" - ).data["config"] - def __toggle_nvapi(self, widget=False, state=False): """Install/Uninstall NVAPI from the bottle""" self.queue.add_task() @@ -643,45 +620,7 @@ def __toggle_nvapi(self, widget=False, state=False): remove=not state, ) - self.config = self.manager.update_config( - config=self.config, key="dxvk_nvapi", value=state, scope="Parameters" - ).data["config"] - - def __toggle_gamemode(self, widget=False, state=False): - """Toggle the gamemode for current bottle""" - self.config = self.manager.update_config( - config=self.config, key="gamemode", value=state, scope="Parameters" - ).data["config"] - - def __toggle_gamescope(self, widget=False, state=False): - """Toggle the gamescope for current bottle""" - self.config = self.manager.update_config( - config=self.config, key="gamescope", value=state, scope="Parameters" - ).data["config"] - - def __toggle_sandbox(self, widget=False, state=False): - """Toggle the sandbox for current bottle""" - self.config = self.manager.update_config( - config=self.config, key="sandbox", value=state, scope="Parameters" - ).data["config"] - - def __toggle_runtime(self, widget, state): - """Toggle the Bottles runtime for current bottle""" - self.config = self.manager.update_config( - config=self.config, key="use_runtime", value=state, scope="Parameters" - ).data["config"] - - def __toggle_steam_runtime(self, widget, state): - """Toggle the Steam runtime for current bottle""" - self.config = self.manager.update_config( - config=self.config, key="use_steam_runtime", value=state, scope="Parameters" - ).data["config"] - - def __toggle_discrete_gpu(self, widget, state): - """Toggle the discrete GPU for current bottle""" - self.config = self.manager.update_config( - config=self.config, key="discrete_gpu", value=state, scope="Parameters" - ).data["config"] + self.__toggle_feature(widget=None, state=state, key="dxvk_nvapi") def __toggle_versioning_compression(self, widget, state): """Toggle the versioning compression for current bottle""" @@ -715,30 +654,6 @@ def handle_response(_widget, response_id): else: update() - def __toggle_auto_versioning(self, widget, state): - """Toggle the auto versioning for current bottle""" - self.config = self.manager.update_config( - config=self.config, - key="versioning_automatic", - value=state, - scope="Parameters", - ).data["config"] - - def __toggle_versioning_patterns(self, widget, state): - """Toggle the versioning patterns for current bottle""" - self.config = self.manager.update_config( - config=self.config, - key="versioning_exclusion_patterns", - value=state, - scope="Parameters", - ).data["config"] - - def __toggle_vmtouch(self, widget=False, state=False): - """Toggle vmtouch for current bottle""" - self.config = self.manager.update_config( - config=self.config, key="vmtouch", value=state, scope="Parameters" - ).data["config"] - def __set_runner(self, *_args): """Set the runner to use for the bottle""" @@ -769,11 +684,11 @@ def update(result: Result[dict], error=False): self.config = result.data["config"] if self.config.Parameters.use_steam_runtime: self.switch_steam_runtime.handler_block_by_func( - self.__toggle_steam_runtime + self.__toggle_feature ) self.switch_steam_runtime.set_active(True) self.switch_steam_runtime.handler_unblock_by_func( - self.__toggle_steam_runtime + self.__toggle_feature ) set_widgets_status(True)