1
0
Fork 0
mirror of synced 2024-05-20 04:22:58 +12:00

GameInfo: Use ui member instead of double inheritance for the UI module

Signed-off-by: loathingKernel <142770+loathingKernel@users.noreply.github.com>
This commit is contained in:
loathingKernel 2022-12-26 15:18:48 +02:00
parent 7b6a3e181a
commit b73fc328d2
4 changed files with 78 additions and 76 deletions

View file

@ -42,13 +42,14 @@ from .move_game import CopyGameInstallation, MoveGamePopUp, is_game_dir
logger = getLogger("GameInfo")
class GameInfo(QWidget, Ui_GameInfo):
class GameInfo(QWidget):
verification_finished = pyqtSignal(InstalledGame)
uninstalled = pyqtSignal(str)
def __init__(self, game_utils, parent=None):
super(GameInfo, self).__init__(parent=parent)
self.setupUi(self)
self.ui = Ui_GameInfo()
self.ui.setupUi(self)
self.core = LegendaryCoreSingleton()
self.signals = GlobalSignalsSingleton()
self.args = ArgumentsSingleton()
@ -62,36 +63,36 @@ class GameInfo(QWidget, Ui_GameInfo):
self.image = ImageWidget(self)
self.image.setFixedSize(ImageSize.Display)
self.layout_game_info.insertWidget(0, self.image, alignment=Qt.AlignTop)
self.ui.layout_game_info.insertWidget(0, self.image, alignment=Qt.AlignTop)
if platform.system() == "Windows":
self.lbl_grade.setVisible(False)
self.grade.setVisible(False)
self.ui.lbl_grade.setVisible(False)
self.ui.grade.setVisible(False)
else:
self.steam_worker: SteamWorker = SteamWorker(self.core)
self.steam_worker.signals.rating.connect(self.grade.setText)
self.steam_worker.signals.rating.connect(self.ui.grade.setText)
self.steam_worker.setAutoDelete(False)
self.game_actions_stack.setCurrentIndex(0)
self.game_actions_stack.resize(self.game_actions_stack.minimumSize())
self.ui.game_actions_stack.setCurrentIndex(0)
self.ui.game_actions_stack.resize(self.ui.game_actions_stack.minimumSize())
self.uninstall_button.clicked.connect(self.uninstall)
self.verify_button.clicked.connect(self.verify)
self.ui.uninstall_button.clicked.connect(self.uninstall)
self.ui.verify_button.clicked.connect(self.verify)
self.verify_pool = QThreadPool()
self.verify_pool.setMaxThreadCount(2)
if self.args.offline:
self.repair_button.setDisabled(True)
self.ui.repair_button.setDisabled(True)
else:
self.repair_button.clicked.connect(self.repair)
self.ui.repair_button.clicked.connect(self.repair)
self.install_button.clicked.connect(self.install)
self.ui.install_button.clicked.connect(self.install)
self.move_game_pop_up = MoveGamePopUp()
self.move_action = QWidgetAction(self)
self.move_action.setDefaultWidget(self.move_game_pop_up)
self.move_button.setMenu(QMenu())
self.move_button.menu().addAction(self.move_action)
self.ui.move_button.setMenu(QMenu())
self.ui.move_button.menu().addAction(self.move_action)
self.progress_of_moving = QProgressBar()
self.existing_game_dir = False
@ -102,12 +103,12 @@ class GameInfo(QWidget, Ui_GameInfo):
self.widget_container = QWidget()
box_layout = QHBoxLayout()
box_layout.setContentsMargins(0, 0, 0, 0)
box_layout.addWidget(self.move_button)
box_layout.addWidget(self.ui.move_button)
self.widget_container.setLayout(box_layout)
index = self.move_stack.addWidget(self.widget_container)
self.move_stack.setCurrentIndex(index)
index = self.ui.move_stack.addWidget(self.widget_container)
self.ui.move_stack.setCurrentIndex(index)
self.move_game_pop_up.browse_done.connect(self.show_menu_after_browse)
self.move_game_pop_up.move_clicked.connect(self.move_button.menu().close)
self.move_game_pop_up.move_clicked.connect(self.ui.move_button.menu().close)
self.move_game_pop_up.move_clicked.connect(self.move_game)
@pyqtSlot()
@ -170,21 +171,21 @@ class GameInfo(QWidget, Ui_GameInfo):
self.verify_game(self.igame)
def verify_game(self, igame: InstalledGame):
self.verify_widget.setCurrentIndex(1)
self.ui.verify_widget.setCurrentIndex(1)
verify_worker = VerifyWorker(igame.app_name)
verify_worker.signals.status.connect(self.verify_status)
verify_worker.signals.result.connect(self.verify_result)
verify_worker.signals.error.connect(self.verify_error)
self.verify_progress.setValue(0)
self.ui.verify_progress.setValue(0)
self.verify_threads[igame.app_name] = verify_worker
self.verify_pool.start(verify_worker)
self.move_button.setEnabled(False)
self.ui.move_button.setEnabled(False)
def verify_cleanup(self, app_name: str):
self.verify_widget.setCurrentIndex(0)
self.ui.verify_widget.setCurrentIndex(0)
self.verify_threads.pop(app_name)
self.move_button.setEnabled(True)
self.verify_button.setEnabled(True)
self.ui.move_button.setEnabled(True)
self.ui.verify_button.setEnabled(True)
@pyqtSlot(str, str)
def verify_error(self, app_name, message):
@ -200,12 +201,12 @@ class GameInfo(QWidget, Ui_GameInfo):
def verify_status(self, app_name, num, total, percentage, speed):
# checked, max, app_name
if app_name == self.game.app_name:
self.verify_progress.setValue(num * 100 // total)
self.ui.verify_progress.setValue(num * 100 // total)
@pyqtSlot(str, bool, int, int)
def verify_result(self, app_name, success, failed, missing):
self.verify_cleanup(app_name)
self.repair_button.setDisabled(success)
self.ui.repair_button.setDisabled(success)
igame = self.core.get_installed_game(app_name)
if success:
QMessageBox.information(
@ -262,13 +263,13 @@ class GameInfo(QWidget, Ui_GameInfo):
else:
return
self.move_stack.addWidget(self.progress_of_moving)
self.move_stack.setCurrentWidget(self.progress_of_moving)
self.ui.move_stack.addWidget(self.progress_of_moving)
self.ui.move_stack.setCurrentWidget(self.progress_of_moving)
self.game_moving = self.igame.app_name
self.is_moving = True
self.verify_button.setEnabled(False)
self.ui.verify_button.setEnabled(False)
if self.move_game_pop_up.is_different_drive(str(dest_path), str(install_path)):
# Destination dir on different drive
@ -295,12 +296,12 @@ class GameInfo(QWidget, Ui_GameInfo):
QThreadPool.globalInstance().start(copy_worker)
def move_helper_clean_up(self):
self.move_stack.setCurrentWidget(self.move_button)
self.ui.move_stack.setCurrentWidget(self.ui.move_button)
self.move_game_pop_up.refresh_indicator()
self.is_moving = False
self.game_moving = None
self.verify_button.setEnabled(True)
self.move_button.setEnabled(True)
self.ui.verify_button.setEnabled(True)
self.ui.move_button.setEnabled(True)
# This func does the needed UI changes, e.g. changing back to the initial move tool button and other stuff
def warn_no_space_left(self):
@ -311,7 +312,7 @@ class GameInfo(QWidget, Ui_GameInfo):
# Sets all needed variables to the new path.
def set_new_game(self, dest_path_with_suffix):
self.install_path.setText(str(dest_path_with_suffix))
self.ui.install_path.setText(str(dest_path_with_suffix))
self.igame.install_path = str(dest_path_with_suffix)
self.core.lgd.set_installed_game(self.igame.app_name, self.igame)
self.move_game_pop_up.install_path = self.igame.install_path
@ -321,7 +322,7 @@ class GameInfo(QWidget, Ui_GameInfo):
# We need to re-show the menu, as after clicking on browse, the whole menu gets closed.
# Otherwise, the user would need to click on the move button again to open it again.
def show_menu_after_browse(self):
self.move_button.showMenu()
self.ui.move_button.showMenu()
def update_game(self, rgame: RareGame):
# FIXME: Use RareGame for the rest of the code
@ -332,64 +333,64 @@ class GameInfo(QWidget, Ui_GameInfo):
self.image.setPixmap(rgame.pixmap)
self.app_name.setText(self.game.app_name)
self.ui.app_name.setText(self.game.app_name)
if self.igame:
self.version.setText(self.igame.version)
self.ui.version.setText(self.igame.version)
else:
self.version.setText(self.game.app_version(self.igame.platform if self.igame else "Windows"))
self.dev.setText(self.game.metadata["developer"])
self.ui.version.setText(self.game.app_version(self.igame.platform if self.igame else "Windows"))
self.ui.dev.setText(self.game.metadata["developer"])
if self.igame:
self.install_size.setText(get_size(self.igame.install_size))
self.install_path.setText(self.igame.install_path)
self.platform.setText(self.igame.platform)
self.ui.install_size.setText(get_size(self.igame.install_size))
self.ui.install_path.setText(self.igame.install_path)
self.ui.platform.setText(self.igame.platform)
else:
self.install_size.setText("N/A")
self.install_path.setText("N/A")
self.platform.setText("Windows")
self.ui.install_size.setText("N/A")
self.ui.install_path.setText("N/A")
self.ui.platform.setText("Windows")
self.install_size.setEnabled(bool(self.igame))
self.lbl_install_size.setEnabled(bool(self.igame))
self.install_path.setEnabled(bool(self.igame))
self.lbl_install_path.setEnabled(bool(self.igame))
self.ui.install_size.setEnabled(bool(self.igame))
self.ui.lbl_install_size.setEnabled(bool(self.igame))
self.ui.install_path.setEnabled(bool(self.igame))
self.ui.lbl_install_path.setEnabled(bool(self.igame))
self.uninstall_button.setEnabled(bool(self.igame))
self.verify_button.setEnabled(bool(self.igame))
self.repair_button.setEnabled(bool(self.igame))
self.ui.uninstall_button.setEnabled(bool(self.igame))
self.ui.verify_button.setEnabled(bool(self.igame))
self.ui.repair_button.setEnabled(bool(self.igame))
if not self.igame:
self.game_actions_stack.setCurrentIndex(1)
self.ui.game_actions_stack.setCurrentIndex(1)
if self.game.metadata.get("customAttributes", {}).get("ThirdPartyManagedApp", {}).get("value") == "Origin":
self.version.setText("N/A")
self.version.setEnabled(False)
self.install_button.setText(self.tr("Link to Origin/Launch"))
self.ui.version.setText("N/A")
self.ui.version.setEnabled(False)
self.ui.install_button.setText(self.tr("Link to Origin/Launch"))
else:
self.install_button.setText(self.tr("Install"))
self.ui.install_button.setText(self.tr("Install"))
else:
if not self.args.offline:
self.repair_button.setDisabled(
self.ui.repair_button.setDisabled(
not os.path.exists(os.path.join(self.core.lgd.get_tmp_path(), f"{self.igame.app_name}.repair"))
)
self.game_actions_stack.setCurrentIndex(0)
self.ui.game_actions_stack.setCurrentIndex(0)
try:
is_ue = self.core.get_asset(rgame.app_name).namespace == "ue"
except ValueError:
is_ue = False
grade_visible = not is_ue and platform.system() != "Windows"
self.grade.setVisible(grade_visible)
self.lbl_grade.setVisible(grade_visible)
self.ui.grade.setVisible(grade_visible)
self.ui.lbl_grade.setVisible(grade_visible)
if platform.system() != "Windows" and not is_ue:
self.grade.setText(self.tr("Loading"))
self.ui.grade.setText(self.tr("Loading"))
self.steam_worker.set_app_name(self.game.app_name)
QThreadPool.globalInstance().start(self.steam_worker)
if len(self.verify_threads.keys()) == 0 or not self.verify_threads.get(self.game.app_name):
self.verify_widget.setCurrentIndex(0)
self.ui.verify_widget.setCurrentIndex(0)
elif self.verify_threads.get(self.game.app_name):
self.verify_widget.setCurrentIndex(1)
self.verify_progress.setValue(
self.ui.verify_widget.setCurrentIndex(1)
self.ui.verify_progress.setValue(
int(
self.verify_threads[self.game.app_name].num
/ self.verify_threads[self.game.app_name].total
@ -401,19 +402,19 @@ class GameInfo(QWidget, Ui_GameInfo):
# Otherwhise, we show the move tool button.
if self.igame is not None:
if self.game_moving == self.igame.app_name:
index = self.move_stack.addWidget(self.progress_of_moving)
self.move_stack.setCurrentIndex(index)
index = self.ui.move_stack.addWidget(self.progress_of_moving)
self.ui.move_stack.setCurrentIndex(index)
else:
index = self.move_stack.addWidget(self.move_button)
self.move_stack.setCurrentIndex(index)
index = self.ui.move_stack.addWidget(self.ui.move_button)
self.ui.move_stack.setCurrentIndex(index)
# If a game is verifying or moving, disable both verify and moving buttons.
if len(self.verify_threads):
self.verify_button.setEnabled(False)
self.move_button.setEnabled(False)
self.ui.verify_button.setEnabled(False)
self.ui.move_button.setEnabled(False)
if self.is_moving:
self.move_button.setEnabled(False)
self.verify_button.setEnabled(False)
self.ui.move_button.setEnabled(False)
self.ui.verify_button.setEnabled(False)
self.move_game_pop_up.update_game(rgame.app_name)

View file

@ -22,7 +22,7 @@ class GameSettings(DefaultGameSettings):
igame: InstalledGame
def __init__(self, parent=None):
super(GameSettings, self).__init__(False, parent)
super(GameSettings, self).__init__(False, parent=parent)
self.pre_launch_settings = PreLaunchSettings()
self.launch_settings_group.layout().addRow(
QLabel(self.tr("Pre-launch command")), self.pre_launch_settings

View file

@ -19,8 +19,8 @@ class MoveGamePopUp(QWidget):
move_clicked = pyqtSignal(str)
browse_done = pyqtSignal()
def __init__(self):
super(MoveGamePopUp, self).__init__()
def __init__(self, parent=None):
super(MoveGamePopUp, self).__init__(parent=parent)
layout: QVBoxLayout = QVBoxLayout()
self.install_path = str()
self.core = LegendaryCoreSingleton()

View file

@ -5,3 +5,4 @@ toml
nuitka
ordered-set
PyQt5-stubs
qstylizer