Skip to content

Commit

Permalink
Revert "bottle-preferences: Use single private method to toggle feature"
Browse files Browse the repository at this point in the history
This reverts commit 9ea570a.
  • Loading branch information
mirkobrombin committed Dec 14, 2024
1 parent 6afb16b commit 32bee7d
Showing 1 changed file with 126 additions and 46 deletions.
172 changes: 126 additions & 46 deletions bottles/frontend/views/bottle_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,24 @@ 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_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_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_nvapi.connect("state-set", self.__toggle_nvapi)
# self.switch_latencyflex.connect('state-set', self.__toggle_latencyflex)
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_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_versioning_compression.connect(
"state-set", self.__toggle_versioning_compression
)
self.switch_auto_versioning.connect("state-set", self.__toggle_feature, "versioning_automatic")
self.switch_auto_versioning.connect("state-set", self.__toggle_auto_versioning)
self.switch_versioning_patterns.connect(
"state-set", self.__toggle_feature, "versioning_exclusion_patterns"
"state-set", self.__toggle_versioning_patterns
)
self.switch_vmtouch.connect("state-set", self.__toggle_feature, "vmtouch")
self.switch_vmtouch.connect("state-set", self.__toggle_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)
Expand All @@ -193,11 +193,11 @@ def __init__(self, details, config, **kwargs):
"""Set Bottles Runtime row to visible when Bottles is not running inside Flatpak"""
if "FLATPAK_ID" not in os.environ and RuntimeManager.get_runtimes("bottles"):
self.row_runtime.set_visible(True)
self.switch_runtime.connect("state-set", self.__toggle_feature, "use_runtime")
self.switch_runtime.connect("state-set", self.__toggle_runtime)

if RuntimeManager.get_runtimes("steam"):
self.row_steam_runtime.set_visible(True)
self.switch_steam_runtime.connect("state-set", self.__toggle_feature, "use_steam_runtime")
self.switch_steam_runtime.connect("state-set", self.__toggle_steam_runtime)

"""Toggle some utilities according to its availability"""
self.switch_gamemode.set_sensitive(gamemode_available)
Expand Down Expand Up @@ -411,25 +411,25 @@ 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_feature)
self.switch_mangohud.handler_block_by_func(self.__toggle_mangohud)
self.switch_nvapi.handler_block_by_func(self.__toggle_nvapi)
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_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_versioning_compression.handler_block_by_func(
self.__toggle_versioning_compression
)
self.switch_auto_versioning.handler_block_by_func(self.__toggle_feature)
self.switch_auto_versioning.handler_block_by_func(self.__toggle_auto_versioning)
self.switch_versioning_patterns.handler_block_by_func(
self.__toggle_feature
self.__toggle_versioning_patterns
)
with contextlib.suppress(TypeError):
self.switch_runtime.handler_block_by_func(self.__toggle_feature)
self.switch_steam_runtime.handler_block_by_func(self.__toggle_feature)
self.switch_runtime.handler_block_by_func(self.__toggle_runtime)
self.switch_steam_runtime.handler_block_by_func(self.__toggle_steam_runtime)
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)
Expand Down Expand Up @@ -549,28 +549,28 @@ 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_feature)
self.switch_mangohud.handler_unblock_by_func(self.__toggle_mangohud)
self.switch_nvapi.handler_unblock_by_func(self.__toggle_nvapi)
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_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_versioning_compression.handler_unblock_by_func(
self.__toggle_versioning_compression
)
self.switch_auto_versioning.handler_unblock_by_func(
self.__toggle_feature
self.__toggle_auto_versioning
)
self.switch_versioning_patterns.handler_unblock_by_func(
self.__toggle_feature
self.__toggle_versioning_patterns
)
with contextlib.suppress(TypeError):
self.switch_runtime.handler_unblock_by_func(self.__toggle_feature)
self.switch_runtime.handler_unblock_by_func(self.__toggle_runtime)
self.switch_steam_runtime.handler_unblock_by_func(
self.__toggle_feature
self.__toggle_steam_runtime
)
self.combo_runner.handler_unblock_by_func(self.__set_runner)
self.combo_dxvk.handler_unblock_by_func(self.__set_dxvk)
Expand Down Expand Up @@ -598,12 +598,6 @@ 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)
Expand All @@ -625,6 +619,30 @@ 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()
Expand All @@ -638,7 +656,45 @@ def __toggle_nvapi(self, widget=False, state=False):
remove=not state,
)

self.__toggle_feature(widget=None, state=state, key="dxvk_nvapi")
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"]

def __toggle_versioning_compression(self, widget, state):
"""Toggle the versioning compression for current bottle"""
Expand Down Expand Up @@ -672,6 +728,30 @@ 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"""

Expand Down Expand Up @@ -702,11 +782,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_feature
self.__toggle_steam_runtime
)
self.switch_steam_runtime.set_active(True)
self.switch_steam_runtime.handler_unblock_by_func(
self.__toggle_feature
self.__toggle_steam_runtime
)

set_widgets_status(True)
Expand Down

0 comments on commit 32bee7d

Please sign in to comment.