Rare: cherry-pick some of sourcery suggestions
This commit is contained in:
parent
8bde2c2c6d
commit
17066f9a67
|
@ -2,4 +2,4 @@ import pkg_resources
|
|||
from subprocess import call
|
||||
|
||||
for dist in pkg_resources.working_set:
|
||||
call("python -m pip install --upgrade " + dist.project_name, shell=True)
|
||||
call(f"python -m pip install --upgrade {dist.project_name}", shell=True)
|
||||
|
|
|
@ -135,7 +135,7 @@ class MoveDialog(ActionDialog):
|
|||
if not os.access(path, os.W_OK) or not os.access(self.rgame.install_path, os.W_OK):
|
||||
return helper_func(MovePathEditReasons.NO_WRITE_PERM)
|
||||
|
||||
if src_path == dst_path or src_path == dst_install_path:
|
||||
if src_path in {dst_path, dst_install_path}:
|
||||
return helper_func(MovePathEditReasons.SAME_DIR)
|
||||
|
||||
if str(src_path) in str(dst_path):
|
||||
|
|
|
@ -55,7 +55,7 @@ class DlThread(QThread):
|
|||
if result.code == DlResultCode.FINISHED:
|
||||
self.rgame.set_installed(True)
|
||||
self.rgame.state = RareGame.State.IDLE
|
||||
self.rgame.signals.progress.finish.emit(not result.code == DlResultCode.FINISHED)
|
||||
self.rgame.signals.progress.finish.emit(result.code != DlResultCode.FINISHED)
|
||||
self.result.emit(result)
|
||||
|
||||
def __status_callback(self, status: UIUpdate):
|
||||
|
@ -125,15 +125,14 @@ class DlThread(QThread):
|
|||
dlcs = self.core.get_dlc_for_game(self.item.download.igame.app_name)
|
||||
if dlcs and not self.item.options.skip_dlcs:
|
||||
result.dlcs = []
|
||||
for dlc in dlcs:
|
||||
result.dlcs.append(
|
||||
{
|
||||
"app_name": dlc.app_name,
|
||||
"app_title": dlc.app_title,
|
||||
"app_version": dlc.app_version(self.item.options.platform),
|
||||
}
|
||||
)
|
||||
|
||||
result.dlcs.extend(
|
||||
{
|
||||
"app_name": dlc.app_name,
|
||||
"app_title": dlc.app_title,
|
||||
"app_version": dlc.app_version(self.item.options.platform),
|
||||
}
|
||||
for dlc in dlcs
|
||||
)
|
||||
if (
|
||||
self.item.download.game.supports_cloud_saves
|
||||
or self.item.download.game.supports_mac_cloud_saves
|
||||
|
|
|
@ -124,25 +124,26 @@ class LibraryWidgetController(QObject):
|
|||
@pyqtSlot()
|
||||
@pyqtSlot(list)
|
||||
def update_game_views(self, app_names: List[str] = None):
|
||||
if not app_names:
|
||||
# lk: base it on icon widgets, the two lists should be identical
|
||||
icon_widgets = self._icon_container.findChildren(IconGameWidget)
|
||||
list_widgets = self._list_container.findChildren(ListGameWidget)
|
||||
icon_app_names = set([iw.rgame.app_name for iw in icon_widgets])
|
||||
list_app_names = set([lw.rgame.app_name for lw in list_widgets])
|
||||
games = list(self.rcore.games)
|
||||
game_app_names = set([g.app_name for g in games])
|
||||
new_icon_app_names = game_app_names.difference(icon_app_names)
|
||||
new_list_app_names = game_app_names.difference(list_app_names)
|
||||
for app_name in new_icon_app_names:
|
||||
game = self.rcore.get_game(app_name)
|
||||
iw = IconGameWidget(game)
|
||||
self._icon_container.layout().addWidget(iw)
|
||||
for app_name in new_list_app_names:
|
||||
game = self.rcore.get_game(app_name)
|
||||
lw = ListGameWidget(game)
|
||||
self._list_container.layout().addWidget(lw)
|
||||
self.order_game_views()
|
||||
if app_names:
|
||||
return
|
||||
# lk: base it on icon widgets, the two lists should be identical
|
||||
icon_widgets = self._icon_container.findChildren(IconGameWidget)
|
||||
list_widgets = self._list_container.findChildren(ListGameWidget)
|
||||
icon_app_names = {iw.rgame.app_name for iw in icon_widgets}
|
||||
list_app_names = {lw.rgame.app_name for lw in list_widgets}
|
||||
games = list(self.rcore.games)
|
||||
game_app_names = {g.app_name for g in games}
|
||||
new_icon_app_names = game_app_names.difference(icon_app_names)
|
||||
new_list_app_names = game_app_names.difference(list_app_names)
|
||||
for app_name in new_icon_app_names:
|
||||
game = self.rcore.get_game(app_name)
|
||||
iw = IconGameWidget(game)
|
||||
self._icon_container.layout().addWidget(iw)
|
||||
for app_name in new_list_app_names:
|
||||
game = self.rcore.get_game(app_name)
|
||||
lw = ListGameWidget(game)
|
||||
self._list_container.layout().addWidget(lw)
|
||||
self.order_game_views()
|
||||
|
||||
def __find_widget(self, app_name: str) -> Tuple[Union[IconGameWidget, None], Union[ListGameWidget, None]]:
|
||||
iw = self._icon_container.findChild(IconGameWidget, app_name)
|
||||
|
|
|
@ -52,7 +52,7 @@ class ProgressLabel(QLabel):
|
|||
origin_h = (image.height() - min_d) // 2
|
||||
for x, y in zip(range(origin_w, min_d), range(origin_h, min_d)):
|
||||
pixel = image.pixelColor(x, y).getRgb()
|
||||
color = list(map(lambda t: sum(t) // 2, zip(pixel[0:3], color)))
|
||||
color = list(map(lambda t: sum(t) // 2, zip(pixel[:3], color)))
|
||||
# take the V component of the HSV color
|
||||
fg_color = QColor(0, 0, 0) if QColor(*color).value() < 127 else QColor(255, 255, 255)
|
||||
bg_color = QColor(*map(lambda c: 255 - c, color))
|
||||
|
|
|
@ -263,13 +263,12 @@ class ImportGroup(QGroupBox):
|
|||
self.app_name_edit.setText(app_name)
|
||||
|
||||
def path_edit_callback(self, path) -> Tuple[bool, str, int]:
|
||||
if os.path.exists(path):
|
||||
if os.path.exists(os.path.join(path, ".egstore")):
|
||||
return True, path, IndicatorReasonsCommon.VALID
|
||||
elif os.path.basename(path) in self.__install_dirs:
|
||||
return True, path, IndicatorReasonsCommon.VALID
|
||||
else:
|
||||
if not os.path.exists(path):
|
||||
return False, path, IndicatorReasonsCommon.DIR_NOT_EXISTS
|
||||
if os.path.exists(os.path.join(path, ".egstore")):
|
||||
return True, path, IndicatorReasonsCommon.VALID
|
||||
elif os.path.basename(path) in self.__install_dirs:
|
||||
return True, path, IndicatorReasonsCommon.VALID
|
||||
return False, path, IndicatorReasonsCommon.UNDEFINED
|
||||
|
||||
@pyqtSlot(str)
|
||||
|
|
|
@ -243,15 +243,14 @@ class UbisoftGroup(QGroupBox):
|
|||
|
||||
if not uplay_games:
|
||||
self.info_label.setText(self.tr("You don't own any Ubisoft games."))
|
||||
elif activated == len(uplay_games):
|
||||
self.info_label.setText(self.tr("All your Ubisoft games have already been activated."))
|
||||
else:
|
||||
if activated == len(uplay_games):
|
||||
self.info_label.setText(self.tr("All your Ubisoft games have already been activated."))
|
||||
else:
|
||||
self.info_label.setText(
|
||||
self.tr("You have <b>{}</b> games available to redeem.").format(
|
||||
len(uplay_games) - activated
|
||||
)
|
||||
self.info_label.setText(
|
||||
self.tr("You have <b>{}</b> games available to redeem.").format(
|
||||
len(uplay_games) - activated
|
||||
)
|
||||
)
|
||||
logger.info(f"Found {len(uplay_games) - activated} game(s) to redeem.")
|
||||
|
||||
self.loading_widget.stop()
|
||||
|
|
|
@ -16,7 +16,7 @@ def versiontuple(v):
|
|||
try:
|
||||
return tuple(map(int, (v.split("."))))
|
||||
except Exception:
|
||||
return tuple((9, 9, 9)) # It is a beta version and newer
|
||||
return 9, 9, 9
|
||||
|
||||
|
||||
class About(QWidget):
|
||||
|
@ -63,7 +63,7 @@ class About(QWidget):
|
|||
|
||||
if self.update_available:
|
||||
logger.info(f"Update available: {__version__} -> {latest_tag}")
|
||||
self.ui.update_lbl.setText("{} -> {}".format(__version__, latest_tag))
|
||||
self.ui.update_lbl.setText(f"{__version__} -> {latest_tag}")
|
||||
self.update_available_ready.emit()
|
||||
else:
|
||||
self.ui.update_lbl.setText(self.tr("You have the latest version"))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import platform as pf
|
||||
import re
|
||||
from logging import getLogger
|
||||
from typing import Tuple, List
|
||||
from typing import Tuple, Set
|
||||
|
||||
from PyQt5.QtCore import QObject, pyqtSignal, QThreadPool, QSettings
|
||||
from PyQt5.QtGui import QShowEvent, QHideEvent
|
||||
|
@ -21,14 +21,11 @@ class RefreshGameMetaWorker(Worker):
|
|||
class Signals(QObject):
|
||||
finished = pyqtSignal()
|
||||
|
||||
def __init__(self, platforms: List[str], include_unreal: bool):
|
||||
def __init__(self, platforms: Set[str], include_unreal: bool):
|
||||
super(RefreshGameMetaWorker, self).__init__()
|
||||
self.signals = RefreshGameMetaWorker.Signals()
|
||||
self.core = LegendaryCoreSingleton()
|
||||
if platforms:
|
||||
self.platforms = platforms
|
||||
else:
|
||||
self.platforms = ["Windows"]
|
||||
self.platforms = platforms if platforms else {"Windows"}
|
||||
self.skip_ue = not include_unreal
|
||||
|
||||
def run_real(self) -> None:
|
||||
|
@ -146,11 +143,11 @@ class LegendarySettings(QWidget, Ui_LegendarySettings):
|
|||
|
||||
def refresh_metadata(self):
|
||||
self.refresh_metadata_button.setDisabled(True)
|
||||
platforms = []
|
||||
platforms = set()
|
||||
if self.fetch_win32_check.isChecked():
|
||||
platforms.append("Win32")
|
||||
platforms.add("Win32")
|
||||
if self.fetch_macos_check.isChecked():
|
||||
platforms.append("Mac")
|
||||
platforms.add("Mac")
|
||||
worker = RefreshGameMetaWorker(platforms, self.fetch_unreal_check.isChecked())
|
||||
worker.signals.finished.connect(lambda: self.refresh_metadata_button.setDisabled(False))
|
||||
QThreadPool.globalInstance().start(worker)
|
||||
|
@ -172,9 +169,8 @@ class LegendarySettings(QWidget, Ui_LegendarySettings):
|
|||
if text:
|
||||
self.core.egs.language_code, self.core.egs.country_code = text.split("-")
|
||||
self.core.lgd.config.set("Legendary", "locale", text)
|
||||
else:
|
||||
if self.core.lgd.config.has_option("Legendary", "locale"):
|
||||
self.core.lgd.config.remove_option("Legendary", "locale")
|
||||
elif self.core.lgd.config.has_option("Legendary", "locale"):
|
||||
self.core.lgd.config.remove_option("Legendary", "locale")
|
||||
|
||||
def __mac_path_save(self, text: str) -> None:
|
||||
self.__path_save(text, "mac_install_dir")
|
||||
|
@ -189,7 +185,7 @@ class LegendarySettings(QWidget, Ui_LegendarySettings):
|
|||
if not text and option in self.core.lgd.config["Legendary"].keys():
|
||||
self.core.lgd.config["Legendary"].pop(option)
|
||||
else:
|
||||
logger.debug(f"Set %s option in config to %s", option, text)
|
||||
logger.debug("Set %s option in config to %s", option, text)
|
||||
|
||||
def max_worker_save(self, workers: str):
|
||||
if workers := int(workers):
|
||||
|
@ -217,7 +213,7 @@ class LegendarySettings(QWidget, Ui_LegendarySettings):
|
|||
def cleanup(self, keep_manifests: bool):
|
||||
before = self.core.lgd.get_dir_size()
|
||||
logger.debug("Removing app metadata...")
|
||||
app_names = set(g.app_name for g in self.core.get_assets(update_assets=False))
|
||||
app_names = {g.app_name for g in self.core.get_assets(update_assets=False)}
|
||||
self.core.lgd.clean_metadata(app_names)
|
||||
|
||||
if not keep_manifests:
|
||||
|
|
|
@ -58,7 +58,7 @@ class TrayIcon(QSystemTrayIcon):
|
|||
def last_played(self) -> List:
|
||||
last_played = [game for game in self.rcore.games if (game.metadata and game.is_installed)]
|
||||
last_played.sort(key=lambda g: g.metadata.last_played, reverse=True)
|
||||
return last_played[0:5]
|
||||
return last_played[:5]
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
def notify(self, title: str, body: str):
|
||||
|
|
|
@ -90,10 +90,7 @@ class LgndrIndirectStatus:
|
|||
message: str = ""
|
||||
|
||||
def __len__(self):
|
||||
if self.message:
|
||||
return 2
|
||||
else:
|
||||
return 0
|
||||
return 2 if self.message else 0
|
||||
|
||||
def __bool__(self):
|
||||
return self.success
|
||||
|
@ -128,7 +125,7 @@ class LgndrIndirectLogger:
|
|||
self.level = level
|
||||
|
||||
def _log(self, level: int, msg: str):
|
||||
self.status.success = True if level < self.level else False
|
||||
self.status.success = level < self.level
|
||||
self.status.message = msg
|
||||
if self.logger:
|
||||
self.logger.log(level, msg)
|
||||
|
|
|
@ -341,8 +341,7 @@ class RareGame(RareGameSlim):
|
|||
"""
|
||||
if self.igame is not None:
|
||||
return self.igame.needs_verification
|
||||
else:
|
||||
return False
|
||||
return False
|
||||
|
||||
@needs_verification.setter
|
||||
def needs_verification(self, needs: bool) -> None:
|
||||
|
@ -487,9 +486,7 @@ class RareGame(RareGameSlim):
|
|||
if self.is_installed:
|
||||
if (not self.is_idle) or self.needs_verification:
|
||||
return False
|
||||
if self.is_foreign and not self.can_run_offline:
|
||||
return False
|
||||
return True
|
||||
return bool(not self.is_foreign or self.can_run_offline)
|
||||
return False
|
||||
|
||||
def get_pixmap(self, color=True) -> QPixmap:
|
||||
|
@ -635,7 +632,7 @@ class RareEosOverlay(RareGameBase):
|
|||
reg_paths = eos.query_registry_entries(prefix)
|
||||
if old_path := reg_paths["overlay_path"]:
|
||||
if os.path.normpath(old_path) == path:
|
||||
logger.info(f"Overlay already enabled, nothing to do.")
|
||||
logger.info("Overlay already enabled, nothing to do.")
|
||||
return True
|
||||
else:
|
||||
logger.info(f'Updating overlay registry entries from "{old_path}" to "{path}"')
|
||||
|
|
|
@ -21,14 +21,9 @@ class ImageSize:
|
|||
self.__img_factor = 17
|
||||
self.__size = QSize(self.__img_factor * 16, self.__img_factor * 9) * pixel_ratio / divisor
|
||||
# lk: for prettier images set this to true
|
||||
self.__smooth_transform: bool = True
|
||||
if divisor > 2:
|
||||
self.__smooth_transform = False
|
||||
|
||||
if base is not None:
|
||||
self.__base = base
|
||||
else:
|
||||
self.__base = self
|
||||
# self.__smooth_transform: bool = True
|
||||
self.__smooth_transform = divisor <= 2
|
||||
self.__base = base if base is not None else self
|
||||
|
||||
def __eq__(self, other: 'ImageSize.Preset'):
|
||||
return (
|
||||
|
|
|
@ -13,8 +13,7 @@ class Value(Namespace):
|
|||
return len(self.__dict__)
|
||||
|
||||
def __iter__(self):
|
||||
for v in self.__dict__.values():
|
||||
yield v
|
||||
yield from self.__dict__.values()
|
||||
|
||||
|
||||
# They key names are set to the existing option name
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import os
|
||||
from typing import Union, List
|
||||
from typing import Union, List, LiteralString
|
||||
|
||||
from legendary.core import LegendaryCore
|
||||
from legendary.models.game import InstalledGame
|
||||
|
@ -37,10 +37,11 @@ class PathSpec:
|
|||
@staticmethod
|
||||
def wine_egl_prefixes(results: int = 0) -> Union[List[str], str]:
|
||||
possible_prefixes = get_prefixes()
|
||||
prefixes = []
|
||||
for prefix in possible_prefixes:
|
||||
if os.path.exists(os.path.join(prefix, PathSpec.wine_egl_programdata())):
|
||||
prefixes.append(prefix)
|
||||
prefixes = [
|
||||
prefix
|
||||
for prefix in possible_prefixes
|
||||
if os.path.exists(os.path.join(prefix, PathSpec.wine_egl_programdata()))
|
||||
]
|
||||
if not prefixes:
|
||||
return ""
|
||||
if not results:
|
||||
|
@ -59,15 +60,11 @@ class PathSpec:
|
|||
}
|
||||
|
||||
if core is not None:
|
||||
self.__egl_path_vars.update({
|
||||
"{epicid}": core.lgd.userdata["account_id"]
|
||||
})
|
||||
self.__egl_path_vars["{epicid}"] = core.lgd.userdata["account_id"]
|
||||
|
||||
if igame is not None:
|
||||
self.__egl_path_vars.update({
|
||||
"{installdir}": igame.install_path,
|
||||
})
|
||||
self.__egl_path_vars["{installdir}"] = igame.install_path
|
||||
|
||||
def resolve_egl_path_vars(self, path: str) -> str:
|
||||
def resolve_egl_path_vars(self, path: str) -> Union[LiteralString, str, bytes]:
|
||||
cooked_path = [self.__egl_path_vars.get(p.lower(), p) for p in path.split("/")]
|
||||
return os.path.join(*cooked_path)
|
||||
|
|
|
@ -24,7 +24,7 @@ class Wrapper:
|
|||
|
||||
@property
|
||||
def is_editable(self) -> bool:
|
||||
return self.__wtype == WrapperType.USER_DEFINED or self.__wtype == WrapperType.LEGENDARY_IMPORT
|
||||
return self.__wtype in {WrapperType.USER_DEFINED, WrapperType.LEGENDARY_IMPORT}
|
||||
|
||||
@property
|
||||
def checksum(self) -> str:
|
||||
|
@ -53,9 +53,7 @@ class Wrapper:
|
|||
return hash(self.__command)
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
if not self.is_editable:
|
||||
return True
|
||||
return bool(self.command.strip())
|
||||
return True if not self.is_editable else bool(self.command.strip())
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: Dict):
|
||||
|
|
Loading…
Reference in a new issue