1
0
Fork 0
mirror of synced 2024-06-28 19:21:05 +12:00

Add Reasons to IndicatorLineEdit as tooltip

This commit is contained in:
Dummerle 2022-01-13 19:49:39 +01:00
parent a4ac523406
commit 25c04d2812
No known key found for this signature in database
GPG key ID: AB68CC59CA39F2F1
7 changed files with 70 additions and 41 deletions

View file

@ -1,6 +1,7 @@
import os import os
import platform import platform
from multiprocessing import Queue as MPQueue from multiprocessing import Queue as MPQueue
from typing import Tuple
from PyQt5.QtCore import Qt, QObject, QRunnable, QThreadPool, pyqtSignal, pyqtSlot from PyQt5.QtCore import Qt, QObject, QRunnable, QThreadPool, pyqtSignal, pyqtSlot
from PyQt5.QtGui import QCloseEvent, QKeyEvent from PyQt5.QtGui import QCloseEvent, QKeyEvent
@ -35,6 +36,10 @@ class InstallDialog(QDialog, Ui_InstallDialog):
self.game = self.core.get_game(self.app_name) \ self.game = self.core.get_game(self.app_name) \
if not self.dl_item.options.overlay \ if not self.dl_item.options.overlay \
else Game(app_name=self.app_name, app_title="Epic Overlay") else Game(app_name=self.app_name, app_title="Epic Overlay")
self.game_path = self.game.metadata.get('customAttributes', {}). \
get('FolderName', {}).get('value', self.game.app_name)
self.update = update self.update = update
self.silent = silent self.silent = silent
@ -194,13 +199,17 @@ class InstallDialog(QDialog, Ui_InstallDialog):
self.get_options() self.get_options()
self.get_download_info() self.get_download_info()
def option_changed(self, path): def option_changed(self, path) -> Tuple[bool, str, str]:
self.options_changed = True self.options_changed = True
self.install_button.setEnabled(False) self.install_button.setEnabled(False)
self.verify_button.setEnabled(not self.worker_running) self.verify_button.setEnabled(not self.worker_running)
return True, path # directory is not empty
# TODO Add check, if directory is empty full_path = os.path.join(self.dl_item.options.base_path, self.game_path)
if not self.dl_item.options.update and os.path.exists(full_path) and os.listdir(full_path) != 0:
return False, path, PathEdit.reasons.dir_not_empty
return True, path, ""
def non_reload_option_changed(self, option: str): def non_reload_option_changed(self, option: str):
if option == "download_only": if option == "download_only":

View file

@ -46,19 +46,19 @@ class BrowserLogin(QWidget, Ui_BrowserLogin):
return self.sid_edit.is_valid return self.sid_edit.is_valid
@staticmethod @staticmethod
def text_changed(text) -> Tuple[bool, str]: def text_changed(text) -> Tuple[bool, str, str]:
if text: if text:
text = text.strip() text = text.strip()
if text.startswith("{") and text.endswith("}"): if text.startswith("{") and text.endswith("}"):
try: try:
text = json.loads(text).get("sid") text = json.loads(text).get("sid")
except json.JSONDecodeError: except json.JSONDecodeError:
return False, text return False, text, IndicatorLineEdit.reasons.wrong_format
elif '"' in text: elif '"' in text:
text = text.strip('"') text = text.strip('"')
return len(text) == 32, text return len(text) == 32, text, IndicatorLineEdit.reasons.wrong_format
else: else:
return False, text return False, text, ""
def do_login(self): def do_login(self):
self.status_label.setText(self.tr("Logging in...")) self.status_label.setText(self.tr("Logging in..."))

View file

@ -66,7 +66,7 @@ class GameSettings(QWidget, Ui_GameSettings):
"", "",
file_type=QFileDialog.DirectoryOnly, file_type=QFileDialog.DirectoryOnly,
ph_text=self.tr("Cloud save path"), ph_text=self.tr("Cloud save path"),
edit_func=lambda text: (os.path.exists(text), text), edit_func=lambda text: (os.path.exists(text), text, PathEdit.reasons.dir_not_exist),
save_func=self.save_save_path, save_func=self.save_save_path,
) )
self.cloud_gb.layout().addRow( self.cloud_gb.layout().addRow(
@ -296,10 +296,10 @@ class GameSettings(QWidget, Ui_GameSettings):
self.core.lgd.save_config() self.core.lgd.save_config()
def proton_prefix_edit(self, text: str) -> Tuple[bool, str]: def proton_prefix_edit(self, text: str) -> Tuple[bool, str, str]:
if not text: if not text:
text = os.path.expanduser("~/.proton") text = os.path.expanduser("~/.proton")
return True, text return True, text, ""
parent = os.path.dirname(text) parent = os.path.dirname(text)
return os.path.exists(parent), text return os.path.exists(parent), text

View file

@ -88,11 +88,11 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup):
self.egl_path_edit.setText(path) self.egl_path_edit.setText(path)
@staticmethod @staticmethod
def egl_path_edit_edit_cb(path) -> Tuple[bool, str]: def egl_path_edit_edit_cb(path) -> Tuple[bool, str, str]:
if not path: if not path:
return True, path return True, path, ""
if os.path.exists(os.path.join(path, "system.reg")) and os.path.exists( if os.path.exists(os.path.join(path, "system.reg")) and os.path.exists(
os.path.join(path, "dosdevices/c:") os.path.join(path, "dosdevices/c:")
): ):
# path is a wine prefix # path is a wine prefix
path = os.path.join( path = os.path.join(
@ -101,13 +101,13 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup):
"ProgramData/Epic/EpicGamesLauncher/Data/Manifests", "ProgramData/Epic/EpicGamesLauncher/Data/Manifests",
) )
elif not path.rstrip("/").endswith( elif not path.rstrip("/").endswith(
"ProgramData/Epic/EpicGamesLauncher/Data/Manifests" "ProgramData/Epic/EpicGamesLauncher/Data/Manifests"
): ):
# lower() might or might not be needed in the check # lower() might or might not be needed in the check
return False, path return False, path, PathEdit.reasons.wrong_path
if os.path.exists(path): if os.path.exists(path):
return True, path return True, path, ""
return False, path return False, path, PathEdit.reasons.dir_not_exist
@staticmethod @staticmethod
def egl_path_edit_save_cb(path): def egl_path_edit_save_cb(path):

View file

@ -99,13 +99,15 @@ class ImportGroup(QGroupBox, Ui_ImportGroup):
self.import_button.setEnabled(False) self.import_button.setEnabled(False)
self.import_button.clicked.connect(self.import_game) self.import_button.clicked.connect(self.import_game)
def path_edit_cb(self, path) -> Tuple[bool, str]: def path_edit_cb(self, path) -> Tuple[bool, str, str]:
if os.path.exists(path): if os.path.exists(path):
if os.path.exists(os.path.join(path, ".egstore")): if os.path.exists(os.path.join(path, ".egstore")):
return True, path return True, path, ""
elif os.path.basename(path) in self.install_dir_list: elif os.path.basename(path) in self.install_dir_list:
return True, path return True, path, ""
return False, path else:
return False, path, PathEdit.reasons.dir_not_exist
return False, path, ""
def path_changed(self, path): def path_changed(self, path):
self.info_label.setText(str()) self.info_label.setText(str())
@ -114,13 +116,13 @@ class ImportGroup(QGroupBox, Ui_ImportGroup):
else: else:
self.app_name.setText(str()) self.app_name.setText(str())
def app_name_edit_cb(self, text) -> Tuple[bool, str]: def app_name_edit_cb(self, text) -> Tuple[bool, str, str]:
if not text: if not text:
return False, text return False, text, ""
if text in self.app_name_list: if text in self.app_name_list:
return True, text return True, text, ""
else: else:
return False, text return False, text, IndicatorLineEdit.reasons.game_not_installed
def app_name_changed(self, text): def app_name_changed(self, text):
self.info_label.setText(str()) self.info_label.setText(str())

View file

@ -100,14 +100,18 @@ class LegendarySettings(QWidget, Ui_LegendarySettings):
QThreadPool.globalInstance().start(worker) QThreadPool.globalInstance().start(worker)
@staticmethod @staticmethod
def locale_edit_cb(text: str) -> Tuple[bool, str]: def locale_edit_cb(text: str) -> Tuple[bool, str, str]:
if text: if text:
if re.match("^[a-zA-Z]{2,3}[-_][a-zA-Z]{2,3}$", text): if re.match("^[a-zA-Z]{2,3}[-_][a-zA-Z]{2,3}$", text):
language, country = text.replace("_", "-").split("-") language, country = text.replace("_", "-").split("-")
text = "-".join([language.lower(), country.upper()]) text = "-".join([language.lower(), country.upper()])
return bool(re.match("^[a-z]{2,3}-[A-Z]{2,3}$", text)), text if bool(re.match("^[a-z]{2,3}-[A-Z]{2,3}$", text)):
return True, text, ""
else:
return False, text, IndicatorLineEdit.reasons.wrong_format
else: else:
return True, text return True, text, ""
def locale_save_cb(self, text: str): def locale_save_cb(self, text: str):
if text: if text:

View file

@ -143,19 +143,28 @@ class FlowLayout(QLayout):
return parent.spacing() return parent.spacing()
class IndicatorReasons:
dir_not_empty = QCoreApplication.translate("IndicatorReasons", "Directory is not empty")
wrong_format = QCoreApplication.translate("IndicatorReasons", "Given text has wrong format")
game_not_installed = QCoreApplication.translate("IndicatorReasons", "Game is not installed or does not exist")
dir_not_exist = QCoreApplication.translate("IndicatorReasons", "Directory does not exist")
wrong_path = QCoreApplication.translate("IndicatorReasons", "Wrong Directory")
class IndicatorLineEdit(QWidget): class IndicatorLineEdit(QWidget):
textChanged = pyqtSignal(str) textChanged = pyqtSignal(str)
is_valid = False is_valid = False
reasons = IndicatorReasons()
def __init__( def __init__(
self, self,
text: str = "", text: str = "",
ph_text: str = "", ph_text: str = "",
completer: QCompleter = None, completer: QCompleter = None,
edit_func: Callable[[str], Tuple[bool, str]] = None, edit_func: Callable[[str], Tuple[bool, str, str]] = None,
save_func: Callable[[str], None] = None, save_func: Callable[[str], None] = None,
horiz_policy: QSizePolicy = QSizePolicy.Expanding, horiz_policy: QSizePolicy = QSizePolicy.Expanding,
parent=None, parent=None,
): ):
super(IndicatorLineEdit, self).__init__(parent=parent) super(IndicatorLineEdit, self).__init__(parent=parent)
self.setObjectName("IndicatorLineEdit") self.setObjectName("IndicatorLineEdit")
@ -219,20 +228,25 @@ class IndicatorLineEdit(QWidget):
self.hint_label.setFrameRect(self.line_edit.rect()) self.hint_label.setFrameRect(self.line_edit.rect())
self.hint_label.setText(text) self.hint_label.setText(text)
def __indicator(self, res): def __indicator(self, res, reason=None):
color = "green" if res else "red" color = "green" if res else "red"
self.indicator_label.setPixmap( self.indicator_label.setPixmap(
qta_icon("ei.info-circle", color=color).pixmap(16, 16) qta_icon("ei.info-circle", color=color).pixmap(16, 16)
) )
if reason:
self.indicator_label.setToolTip(reason)
else:
self.indicator_label.setToolTip("")
def __edit(self, text): def __edit(self, text):
if self.edit_func is not None: if self.edit_func is not None:
self.line_edit.blockSignals(True) self.line_edit.blockSignals(True)
self.is_valid, text = self.edit_func(text)
self.is_valid, text, reason = self.edit_func(text)
if text != self.line_edit.text(): if text != self.line_edit.text():
self.line_edit.setText(text) self.line_edit.setText(text)
self.line_edit.blockSignals(False) self.line_edit.blockSignals(False)
self.__indicator(self.is_valid) self.__indicator(self.is_valid, reason)
if self.is_valid: if self.is_valid:
self.__save(text) self.__save(text)
self.textChanged.emit(text) self.textChanged.emit(text)
@ -280,13 +294,13 @@ class PathEdit(IndicatorLineEdit):
compl_model = QFileSystemModel() compl_model = QFileSystemModel()
def __init__( def __init__(
self, self,
path: str = "", path: str = "",
file_type: QFileDialog.FileType = QFileDialog.AnyFile, file_type: QFileDialog.FileType = QFileDialog.AnyFile,
type_filter: str = "", type_filter: str = "",
name_filter: str = "", name_filter: str = "",
ph_text: str = "", ph_text: str = "",
edit_func: Callable[[str], Tuple[bool, str]] = None, edit_func: Callable[[str], Tuple[bool, str, str]] = None,
save_func: Callable[[str], None] = None, save_func: Callable[[str], None] = None,
horiz_policy: QSizePolicy = QSizePolicy.Expanding, horiz_policy: QSizePolicy = QSizePolicy.Expanding,
parent=None, parent=None,