diff --git a/bottles/backend/health.py b/bottles/backend/health.py index 1ef0111818..3756b3e59f 100644 --- a/bottles/backend/health.py +++ b/bottles/backend/health.py @@ -69,27 +69,16 @@ def __init__(self): } self.get_ram_data() - if "FLATPAK_ID" not in os.environ: - self.cabextract = self.check_cabextract() - self.p7zip = self.check_p7zip() - self.patool = self.check_patool() - self.icoextract = self.check_icoextract() - self.pefile = self.check_pefile() - self.orjson = self.check_orjson() - self.markdown = self.check_markdown() - self.xdpyinfo = self.check_xdpyinfo() - self.ImageMagick = self.check_ImageMagick() - self.FVS = self.check_FVS() - else: - self.cabextract = True - self.p7zip = True - self.patool = True - self.icoextract = True - self.pefile = True - self.orjson = True - self.markdown = True - self.ImageMagick = True - self.FVS = True + self.cabextract = self.check_cabextract() + self.p7zip = self.check_p7zip() + self.patool = self.check_patool() + self.icoextract = self.check_icoextract() + self.pefile = self.check_pefile() + self.orjson = self.check_orjson() + self.markdown = self.check_markdown() + self.xdpyinfo = self.check_xdpyinfo() + self.ImageMagick = self.check_ImageMagick() + self.FVS = self.check_FVS() @staticmethod def check_gpus(): @@ -104,92 +93,68 @@ def check_x11(self): @staticmethod def check_wayland(): - if "WAYLAND_DISPLAY" in os.environ: - return True - return False + return "WAYLAND_DISPLAY" in os.environ def check_xwayland(self): - if self.x11 and self.wayland: - return True - return False + return self.x11 and self.wayland def check_desktop(self): - return os.environ.get("DESKTOP_SESSION") + return os.environ.get("XDG_CURRENT_DESKTOP") + + @staticmethod + # TODO: additional cleanup: don't have individual `check_*` methods, just one like this, + # and iterate over them for the results. + def check_executable(executable): + return bool(shutil.which(executable)) @staticmethod def check_cabextract(): - res = shutil.which("cabextract") - if res is None: - return False - return True + return check_executable("cabextract") @staticmethod def check_p7zip(): - res = shutil.which("7z") - if res is None: - return False - return True + return check_executable("7z") @staticmethod def check_patool(): - res = shutil.which("patool") - if res is None: - return False - return True + return check_executable("patool") @staticmethod - def check_icoextract(): - try: - import icoextract - return True - except ModuleNotFoundError: - return False + def check_xdpyinfo(): + return check_executable("xdpyinfo") @staticmethod - def check_pefile(): - try: - import pefile - return True - except ModuleNotFoundError: - return False + def check_ImageMagick(): + return check_executable("identify") @staticmethod - def check_markdown(): + def check_module(module): try: - import markdown - return True + __import__(module) except ModuleNotFoundError: return False + else: + return True @staticmethod - def check_orjson(): - try: - import orjson - return True - except ModuleNotFoundError: - return False + def check_icoextract(): + return check_module("icoextract") @staticmethod - def check_xdpyinfo(): - res = shutil.which("xdpyinfo") - if res is None: - return False - return True + def check_pefile(): + return check_module("pefile") @staticmethod - def check_ImageMagick(): - res = shutil.which("identify") - if res is None: - return False - return True + def check_markdown(): + return check_module("markdown") + + @staticmethod + def check_orjson(): + return check_module("orjson") @staticmethod def check_FVS(): - try: - from fvs.repo import FVSRepo - return True - except ModuleNotFoundError: - return False + return check_module("fvs") @staticmethod def get_bottles_envs(): diff --git a/bottles/frontend/views/bottle_preferences.py b/bottles/frontend/views/bottle_preferences.py index 7f5e9cb96f..66241e71cf 100644 --- a/bottles/frontend/views/bottle_preferences.py +++ b/bottles/frontend/views/bottle_preferences.py @@ -143,30 +143,30 @@ def __init__(self, details, config, **kwargs): self.btn_manage_vmtouch.connect("clicked", self.__show_vmtouch_settings) 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_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_versioning_compression.connect('state-set', self.__toggle_versioning_compression) - self.switch_auto_versioning.connect('state-set', self.__toggle_auto_versioning) - self.switch_versioning_patterns.connect('state-set', self.__toggle_versioning_patterns) - 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) - self.combo_nvapi.connect('notify::selected', self.__set_nvapi) - self.combo_latencyflex.connect('notify::selected', self.__set_latencyflex) - self.combo_windows.connect('notify::selected', self.__set_windows) + 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_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_auto_versioning) + self.switch_versioning_patterns.connect("state-set", self.__toggle_versioning_patterns) + 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) + self.combo_nvapi.connect("notify::selected", self.__set_nvapi) + self.combo_latencyflex.connect("notify::selected", self.__set_latencyflex) + self.combo_windows.connect("notify::selected", self.__set_windows) self.combo_language.connect('notify::selected-item', self.__set_language) - self.combo_sync.connect('notify::selected', self.__set_sync_type) - self.entry_name.connect('changed', self.__check_entry_name) - self.entry_name.connect('apply', self.__save_name) + self.combo_sync.connect("notify::selected", self.__set_sync_type) + self.entry_name.connect("changed", self.__check_entry_name) + self.entry_name.connect("apply", self.__save_name) # endregion """Set DXVK_NVAPI related rows to visible when an NVIDIA GPU is detected (invisible by default)""" @@ -177,11 +177,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_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_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) @@ -338,26 +338,16 @@ def update_combo_components(self): ]: 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) + self.str_list_dxvk.append(_("Disabled")) + self.str_list_vkd3d.append(_("Disabled")) + self.str_list_latencyflex.append(_("Disabled")) - 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) - - for lang in ManagerUtils.get_languages(): - self.str_list_languages.append(lang) + self.str_list_dxvk.splice(self.str_list_dxvk.get_n_items(), 0, self.manager.dxvk_available) + self.str_list_vkd3d.splice(self.str_list_vkd3d.get_n_items(), 0, self.manager.vkd3d_available) + self.str_list_runner.splice(self.str_list_runner.get_n_items(), 0, self.manager.runners_available) + self.str_list_nvapi.splice(self.str_list_nvapi.get_n_items(), 0, self.manager.nvapi_available) + self.str_list_latencyflex.splice(self.str_list_latencyflex.get_n_items(), 0, self.manager.latencyflex_available) + self.str_list_languages.splice(self.str_list_languages.get_n_items(), 0, ManagerUtils.get_languages()) self.combo_runner.handler_unblock_by_func(self.__set_runner) self.combo_dxvk.handler_unblock_by_func(self.__set_dxvk) @@ -445,10 +435,8 @@ def set_config(self, config: BottleConfig): 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(self.str_list_windows.get_n_items(), 0, list(self.windows_versions.values())) + self.combo_windows.set_selected(list(self.windows_versions).index(self.config.get("Windows"))) # endregion parameters = self.config.Parameters @@ -524,7 +512,7 @@ def set_config(self, config: BottleConfig): def __show_gamescope_settings(self, widget): new_window = GamescopeDialog( - window=self.window, + parent_window=self.window, config=self.config ) new_window.present() @@ -556,21 +544,21 @@ def __show_display_settings(self, widget): def __show_exclusionpatterns_settings(self, widget): new_window = ExclusionPatternsDialog( - window=self.window, + parent_window=self.window, config=self.config ) new_window.present() def __show_sandbox_settings(self, widget): new_window = SandboxDialog( - window=self.window, + parent_window=self.window, config=self.config ) new_window.present() def __show_drives(self, widget): new_window = DrivesDialog( - window=self.window, + parent_window=self.window, config=self.config ) new_window.present() @@ -578,14 +566,14 @@ def __show_drives(self, widget): def __show_environment_variables(self, widget=False): """Show the environment variables dialog""" new_window = EnvVarsDialog( - window=self.window, + parent_window=self.window, config=self.config ) new_window.present() def __show_vmtouch_settings(self, widget): new_window = VmtouchDialog( - window=self.window, + parent_window=self.window, config=self.config ) new_window.present() @@ -1051,7 +1039,7 @@ def __set_language(self, *_args): def __show_dll_overrides_view(self, widget=False): """Show the DLL overrides view""" new_window = DLLOverridesDialog( - window=self.window, + parent_window=self.window, config=self.config ) new_window.present() diff --git a/bottles/frontend/windows/dlloverrides.py b/bottles/frontend/windows/dlloverrides.py index 3db97747e3..28003bf6e9 100644 --- a/bottles/frontend/windows/dlloverrides.py +++ b/bottles/frontend/windows/dlloverrides.py @@ -27,12 +27,12 @@ class DLLEntry(Adw.ComboRow): # endregion - def __init__(self, window, config, override, **kwargs): + def __init__(self, parent_window, config, override, **kwargs): super().__init__(**kwargs) # common variables and references - self.window = window - self.manager = window.manager + self.parent_window = parent_window + self.manager = parent_window.manager self.config = config self.override = override types = ("b", "n", "b,n", "n,b", "d") @@ -87,13 +87,13 @@ class DLLOverridesDialog(Adw.PreferencesWindow): # endregion - def __init__(self, window, config, **kwargs): + def __init__(self, parent_window, config, **kwargs): super().__init__(**kwargs) - self.set_transient_for(window) + self.set_transient_for(parent_window) # common variables and references - self.window = window - self.manager = window.manager + self.parent_window = parent_window + self.manager = parent_window.manager self.config = config self.__populate_overrides_list() @@ -117,7 +117,7 @@ def __save_override(self, *_args): scope="DLL_Overrides" ) _entry = DLLEntry( - window=self.window, + parent_window=self.parent_window, config=self.config, override=[dll_name, "n,b"] ) @@ -139,7 +139,7 @@ def __populate_overrides_list(self): self.group_overrides.set_description("") for override in overrides: _entry = DLLEntry( - window=self.window, + parent_window=self.parent_window, config=self.config, override=override ) diff --git a/bottles/frontend/windows/drives.py b/bottles/frontend/windows/drives.py index 7482543545..37971e56d8 100644 --- a/bottles/frontend/windows/drives.py +++ b/bottles/frontend/windows/drives.py @@ -18,6 +18,7 @@ from gi.repository import Gtk, GLib, Adw from bottles.backend.wine.drives import Drives +from string import ascii_uppercase @Gtk.Template(resource_path='/com/usebottles/bottles/drive-entry.ui') @@ -90,10 +91,7 @@ def __remove(self, *_args): @Gtk.Template(resource_path='/com/usebottles/bottles/dialog-drives.ui') class DrivesDialog(Adw.Window): __gtype_name__ = 'DrivesDialog' - __alphabet = ["A", "B", "D", "E", "F", "G", "H", - "I", "J", "K", "L", "M", "N", "O", - "P", "Q", "R", "S", "T", "U", "V", - "W", "X", "Y", "Z"] + __alphabet = list(ascii_uppercase.replace("C", "")) # region Widgets combo_letter = Gtk.Template.Child() @@ -103,12 +101,12 @@ class DrivesDialog(Adw.Window): # endregion - def __init__(self, window, config, **kwargs): + def __init__(self, parent_window, config, **kwargs): super().__init__(**kwargs) - self.set_transient_for(window) + self.set_transient_for(parent_window) # common variables and references - self.window = window + self.parent_window = parent_window self.manager = window.manager self.config = config @@ -143,7 +141,6 @@ def __populate_drives_list(self): def __populate_combo_letter(self): drives = Drives(self.config).get_all() - self.str_list_letters.splice(0, self.str_list_letters.get_n_items()) for letter in self.__alphabet: if letter not in drives: diff --git a/bottles/frontend/windows/envvars.py b/bottles/frontend/windows/envvars.py index 3ec5d6c656..84a9fdccbb 100644 --- a/bottles/frontend/windows/envvars.py +++ b/bottles/frontend/windows/envvars.py @@ -80,13 +80,13 @@ class EnvVarsDialog(Adw.Window): group_vars = Gtk.Template.Child() # endregion - def __init__(self, window, config, **kwargs): + def __init__(self, parent_window, config, **kwargs): super().__init__(**kwargs) - self.set_transient_for(window) + self.set_transient_for(parent_window) # common variables and references - self.window = window - self.manager = window.manager + self.parent_window = parent_window + self.manager = parent_window.manager self.config = config self.__populate_vars_list() diff --git a/bottles/frontend/windows/exclusionpatterns.py b/bottles/frontend/windows/exclusionpatterns.py index 139d9c6c60..a3a084de42 100644 --- a/bottles/frontend/windows/exclusionpatterns.py +++ b/bottles/frontend/windows/exclusionpatterns.py @@ -66,13 +66,13 @@ class ExclusionPatternsDialog(Adw.Window): group_patterns = Gtk.Template.Child() # endregion - def __init__(self, window, config, **kwargs): + def __init__(self, parent_window, config, **kwargs): super().__init__(**kwargs) - self.set_transient_for(window) + self.set_transient_for(parent_window) # common variables and references - self.window = window - self.manager = window.manager + self.parent_window = parent_window + self.manager = parent_window.manager self.config = config self.__populate_patterns_list() diff --git a/bottles/frontend/windows/fsr.py b/bottles/frontend/windows/fsr.py index 99838fb6b6..a82af6f2f0 100644 --- a/bottles/frontend/windows/fsr.py +++ b/bottles/frontend/windows/fsr.py @@ -56,8 +56,7 @@ def __update(self, config): parameters = config.Parameters # Populate entries - for mode in self.quality_mode.values(): - self.str_list_quality_mode.append(mode) + self.str_list_quality_mode.splice(0, 0, list(self.quality_mode.values())) # Select right entry if parameters.fsr_quality_mode: diff --git a/bottles/frontend/windows/gamescope.py b/bottles/frontend/windows/gamescope.py index b04203bb81..de19a21d73 100644 --- a/bottles/frontend/windows/gamescope.py +++ b/bottles/frontend/windows/gamescope.py @@ -37,13 +37,13 @@ class GamescopeDialog(Adw.Window): # endregion - def __init__(self, window, config, **kwargs): + def __init__(self, parent_window, config, **kwargs): super().__init__(**kwargs) - self.set_transient_for(window) + self.set_transient_for(parent_window) # common variables and references - self.window = window - self.manager = window.manager + self.parent_window = parent_window + self.manager = parent_window.manager self.config = config # connect signals diff --git a/bottles/frontend/windows/sandbox.py b/bottles/frontend/windows/sandbox.py index 3f47a98322..45205b6fe0 100644 --- a/bottles/frontend/windows/sandbox.py +++ b/bottles/frontend/windows/sandbox.py @@ -28,12 +28,12 @@ class SandboxDialog(Adw.Window): # endregion - def __init__(self, window, config, **kwargs): + def __init__(self, parent_window, config, **kwargs): super().__init__(**kwargs) - self.set_transient_for(window) + self.set_transient_for(parent_window) # common variables and references - self.window = window + self.parent_window = parent_window self.manager = window.manager self.config = config self.__update(config) diff --git a/bottles/frontend/windows/vmtouch.py b/bottles/frontend/windows/vmtouch.py index 29d59ce137..16d9bcebd8 100644 --- a/bottles/frontend/windows/vmtouch.py +++ b/bottles/frontend/windows/vmtouch.py @@ -31,13 +31,13 @@ class VmtouchDialog(Adw.Window): # endregion - def __init__(self, window, config, **kwargs): + def __init__(self, parent_window, config, **kwargs): super().__init__(**kwargs) - self.set_transient_for(window) + self.set_transient_for(parent_window) # common variables and references - self.window = window - self.manager = window.manager + self.parent_window = parent_window + self.manager = parent_window.manager self.config = config # connect signals