1
0
Fork 0
mirror of synced 2024-06-23 08:40:45 +12:00
Rare/rare/components/dialogs/install_dialog.py

118 lines
4.1 KiB
Python
Raw Normal View History

2021-02-10 23:48:25 +13:00
import os
from PyQt5.QtWidgets import QDialog, QFormLayout, QVBoxLayout, QSpinBox, QFileDialog, QLabel, QPushButton, QHBoxLayout, \
QCheckBox
2021-02-10 23:48:25 +13:00
from custom_legendary.core import LegendaryCore
2021-04-23 00:34:06 +12:00
from rare.utils.extra_widgets import PathEdit
2021-05-21 09:00:38 +12:00
from rare.utils.utils import get_size
2021-02-10 23:48:25 +13:00
class InstallDialog(QDialog):
2021-02-18 05:46:03 +13:00
infos = 0
def __init__(self, app_name, core: LegendaryCore, update=False):
2021-02-10 23:48:25 +13:00
super(InstallDialog, self).__init__()
self.layout = QVBoxLayout()
self.core = core
self.game = self.core.get_game(app_name)
2021-02-10 23:48:25 +13:00
self.form = QFormLayout()
self.update_game = update
self.layout.addWidget(QLabel(self.tr("<h3>Install {}</h3>").format(self.game.app_title)))
if self.core.lgd.config.has_option("Legendary", "install_dir"):
default_path = self.core.lgd.config.get("Legendary", "install_dir")
else:
default_path = os.path.expanduser("~/legendary")
if not default_path:
default_path = os.path.expanduser("~/legendary")
if not update:
self.install_path_field = PathEdit(text=default_path, file_type=QFileDialog.DirectoryOnly)
self.form.addRow(QLabel("Install directory"), self.install_path_field)
2021-02-10 23:48:25 +13:00
if self.core.lgd.config.has_option("Legendary", "max_workers"):
max_workers = self.core.lgd.config.get("Legendary", "max_workers")
else:
max_workers = 0
2021-02-10 23:48:25 +13:00
self.max_workes = QSpinBox()
self.max_workes.setValue(int(max_workers))
2021-03-12 00:56:38 +13:00
self.form.addRow(QLabel(self.tr("Max workers (0: Default)")), self.max_workes)
2021-02-10 23:48:25 +13:00
self.force = QCheckBox()
self.force.setChecked(False)
self.form.addRow(QLabel(self.tr("Force download")), self.force)
self.ignore_free_space = QCheckBox()
self.ignore_free_space.setChecked(False)
self.form.addRow(QLabel(self.tr("Ignore free space (Warning!)")), self.ignore_free_space)
2021-05-21 09:00:38 +12:00
self.download_only = QCheckBox()
self.download_only.setChecked(False)
self.form.addRow(QLabel(self.tr("Do not install game")), self.download_only)
2021-02-10 23:48:25 +13:00
self.layout.addLayout(self.form)
2021-02-20 00:57:55 +13:00
self.ok_btn = QPushButton("Next")
2021-02-18 05:46:03 +13:00
self.ok_btn.clicked.connect(self.ok)
2021-02-10 23:48:25 +13:00
self.cancel = QPushButton("Cancel")
2021-02-18 05:46:03 +13:00
self.cancel.clicked.connect(lambda: self.close())
2021-02-10 23:48:25 +13:00
self.button_layout = QHBoxLayout()
self.button_layout.addStretch(1)
2021-02-18 05:46:03 +13:00
self.button_layout.addWidget(self.ok_btn)
2021-02-10 23:48:25 +13:00
self.button_layout.addWidget(self.cancel)
self.layout.addLayout(self.button_layout)
self.setLayout(self.layout)
2021-04-17 09:41:59 +12:00
def get_information(self, path=None):
if path:
self.install_path_field.text_edit.setText(path)
2021-02-10 23:48:25 +13:00
self.exec_()
2021-02-18 05:46:03 +13:00
return self.infos
def ok(self):
2021-05-21 09:00:38 +12:00
self.infos = self.install_path_field.text() if not self.update_game else None, \
self.max_workes.value(), \
self.force.isChecked(), \
self.ignore_free_space.isChecked(), \
self.download_only.isChecked()
2021-02-18 05:46:03 +13:00
self.close()
class InstallInfoDialog(QDialog):
accept: bool = False
def __init__(self, dl_size, install_size):
super(InstallInfoDialog, self).__init__()
self.layout = QVBoxLayout()
2021-03-12 00:56:38 +13:00
self.infos = QLabel(self.tr(
2021-05-21 09:00:38 +12:00
"Download size: {}\nInstall size: {}").format(get_size(dl_size), get_size(install_size)))
2021-02-18 05:46:03 +13:00
self.layout.addWidget(self.infos)
self.btn_layout = QHBoxLayout()
2021-03-12 00:56:38 +13:00
self.install_btn = QPushButton(self.tr("Install"))
2021-02-18 05:46:03 +13:00
self.install_btn.clicked.connect(self.install)
2021-03-12 00:56:38 +13:00
self.cancel_button = QPushButton(self.tr("Cancel"))
2021-02-18 05:46:03 +13:00
self.cancel_button.clicked.connect(self.cancel)
self.btn_layout.addStretch(1)
self.btn_layout.addWidget(self.install_btn)
self.btn_layout.addWidget(self.cancel_button)
self.layout.addLayout(self.btn_layout)
self.setLayout(self.layout)
def get_accept(self):
self.exec_()
return self.accept
def install(self):
self.accept = True
self.close()
def cancel(self):
self.accept = False
self.close()