Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements #3102

Merged
merged 18 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 41 additions & 76 deletions bottles/backend/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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))
orowith2os marked this conversation as resolved.
Show resolved Hide resolved

@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():
Expand Down
98 changes: 43 additions & 55 deletions bottles/frontend/views/bottle_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"""
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -556,36 +544,36 @@ 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()

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()
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions bottles/frontend/windows/dlloverrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand All @@ -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"]
)
Expand All @@ -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
)
Expand Down
Loading