Skip to content

Commit

Permalink
Reapply "bottle-preferences: Use single private method to toggle feat…
Browse files Browse the repository at this point in the history
…ure"

This reverts commit 32bee7d.
  • Loading branch information
TheEvilSkeleton committed Dec 23, 2024
1 parent cccf40d commit c22c6f9
Showing 1 changed file with 47 additions and 132 deletions.
179 changes: 47 additions & 132 deletions bottles/frontend/views/bottle_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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"""
Expand Down Expand Up @@ -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"""

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c22c6f9

Please sign in to comment.