1
0
Fork 0
mirror of synced 2024-06-28 11:11:15 +12:00

Add IndicatorLineEdit and base PathEdit on it.

This commit is contained in:
Stelios Tsampas 2021-10-09 14:33:54 +03:00
parent 30a70090c5
commit c1e750138f
4 changed files with 112 additions and 49 deletions

View file

@ -150,12 +150,12 @@ class GameSettings(QWidget, Ui_GameSettings):
self.core.lgd.config.set(self.game.app_name, "no_wine", "true") self.core.lgd.config.set(self.game.app_name, "no_wine", "true")
self.core.lgd.config.set(self.game.app_name + ".env", "STEAM_COMPAT_DATA_PATH", self.core.lgd.config.set(self.game.app_name + ".env", "STEAM_COMPAT_DATA_PATH",
os.path.expanduser("~/.proton")) os.path.expanduser("~/.proton"))
self.proton_prefix.text_edit.setText(os.path.expanduser("~/.proton")) self.proton_prefix.setText(os.path.expanduser("~/.proton"))
# Dont use Wine # Dont use Wine
self.linux_settings.wine_exec.text_edit.setText("") self.linux_settings.wine_exec.setText("")
self.linux_settings.save_setting(self.linux_settings.wine_exec, "wine_exec") self.linux_settings.save_setting(self.linux_settings.wine_exec, "wine_exec")
self.linux_settings.wine_prefix.text_edit.setText("") self.linux_settings.wine_prefix.setText("")
self.linux_settings.save_setting(self.linux_settings.wine_prefix, "wine_prefix") self.linux_settings.save_setting(self.linux_settings.wine_prefix, "wine_prefix")
self.core.lgd.save_config() self.core.lgd.save_config()
@ -164,14 +164,14 @@ class GameSettings(QWidget, Ui_GameSettings):
text = self.proton_prefix.text() text = self.proton_prefix.text()
if not text: if not text:
text = os.path.expanduser("~/.proton") text = os.path.expanduser("~/.proton")
self.proton_prefix.text_edit.setText(text) self.proton_prefix.setText(text)
if not os.path.exists(text): if not os.path.exists(text):
try: try:
os.makedirs(text) os.makedirs(text)
except PermissionError: except PermissionError:
QMessageBox.warning(self, "Warning", self.tr("No permission to create folder")) QMessageBox.warning(self, "Warning", self.tr("No permission to create folder"))
text = os.path.expanduser("~/.proton") text = os.path.expanduser("~/.proton")
self.proton_prefix.text_edit.setText(text) self.proton_prefix.setText(text)
self.core.lgd.config.set(self.game.app_name + ".env", "STEAM_COMPAT_DATA_PATH", text) self.core.lgd.config.set(self.game.app_name + ".env", "STEAM_COMPAT_DATA_PATH", text)
self.core.lgd.save_config() self.core.lgd.save_config()
@ -219,7 +219,7 @@ class GameSettings(QWidget, Ui_GameSettings):
proton_prefix = self.core.lgd.config.get(f"{app_name}.env", "STEAM_COMPAT_DATA_PATH", proton_prefix = self.core.lgd.config.get(f"{app_name}.env", "STEAM_COMPAT_DATA_PATH",
fallback=self.tr( fallback=self.tr(
"Please select path for proton prefix")) "Please select path for proton prefix"))
self.proton_prefix.text_edit.setText(proton_prefix) self.proton_prefix.setText(proton_prefix)
self.wrapper_widget.setEnabled(False) self.wrapper_widget.setEnabled(False)
else: else:
self.proton_wrapper.setCurrentIndex(0) self.proton_wrapper.setCurrentIndex(0)
@ -243,7 +243,7 @@ class LinuxAppSettings(LinuxSettings):
def update_game(self, app_name): def update_game(self, app_name):
self.name = app_name self.name = app_name
self.wine_prefix.text_edit.setText(self.core.lgd.config.get(self.name, "wine_prefix", fallback="")) self.wine_prefix.setText(self.core.lgd.config.get(self.name, "wine_prefix", fallback=""))
self.wine_exec.text_edit.setText(self.core.lgd.config.get(self.name, "wine_executable", fallback="")) self.wine_exec.setText(self.core.lgd.config.get(self.name, "wine_executable", fallback=""))
self.dxvk.name = app_name self.dxvk.name = app_name
self.dxvk.more_settings_widget.name = app_name self.dxvk.more_settings_widget.name = app_name

View file

@ -89,6 +89,8 @@ class ImportWidget(QWidget):
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")):
self.app_name_input.setText(self.find_app_name(path)) self.app_name_input.setText(self.find_app_name(path))
return True, path
return False, path
def find_app_name(self, path): def find_app_name(self, path):
if not os.path.exists(os.path.join(path, ".egstore")): if not os.path.exists(os.path.join(path, ".egstore")):

View file

@ -17,10 +17,6 @@ QLabel {
padding: 0px; padding: 0px;
} }
QScrollArea#noborder {
border-color: transparent;
}
QMenu, QMenu,
QListView, QListView,
QListView::item, QListView::item,
@ -83,6 +79,9 @@ QToolButton {
QFrame[frameShape="6"] { QFrame[frameShape="6"] {
border-radius: 4px; border-radius: 4px;
} }
QScrollArea#noborder {
border-color: transparent;
}
QComboBox { QComboBox {
background-color: #3c3f41; background-color: #3c3f41;
} }
@ -489,7 +488,7 @@ QTabBar::tab:selected:right {
background: qlineargradient(x1: 2, y1: 0, x2: 0, y2: 0, background: qlineargradient(x1: 2, y1: 0, x2: 0, y2: 0,
stop: 0 #483d8b, stop: 1 #202225); /* stop: 0 #2f4f4f stop: 0.2 #203636 */ stop: 0 #483d8b, stop: 1 #202225); /* stop: 0 #2f4f4f stop: 0.2 #203636 */
} }
QTabBar::tab:disabled#settings_bar { QTabBar::tab:disabled#side_tab_bar {
color: transparent; color: transparent;
border-color: transparent; border-color: transparent;
background-color: transparent; background-color: transparent;

View file

@ -1,17 +1,17 @@
import io import io
import os import os
from typing import Callable
from logging import getLogger from logging import getLogger
import PIL import PIL
from PIL import Image from PIL import Image
from PyQt5.QtCore import Qt, QRect, QSize, QPoint, pyqtSignal from PyQt5.QtCore import Qt, QCoreApplication, QRect, QSize, QPoint, pyqtSignal
from PyQt5.QtGui import QMovie, QPixmap, QFontMetrics from PyQt5.QtGui import QMovie, QPixmap, QFontMetrics
from PyQt5.QtWidgets import QLayout, QStyle, QSizePolicy, QLabel, QFileDialog, QHBoxLayout, QWidget, QPushButton, \ from PyQt5.QtWidgets import QLayout, QStyle, QSizePolicy, QLabel, QFileDialog, QHBoxLayout, QWidget, QPushButton, \
QStyleOptionTab, QStylePainter, QTabBar, QLineEdit, QToolButton QStyleOptionTab, QStylePainter, QTabBar, QLineEdit, QToolButton, QTabWidget
from qtawesome import icon from qtawesome import icon
from rare import resources_path, cache_dir from rare import resources_path, cache_dir
from rare.ui.utils.pathedit import Ui_PathEdit
from rare.utils.qt_requests import QtRequestManager from rare.utils.qt_requests import QtRequestManager
logger = getLogger("ExtraWidgets") logger = getLogger("ExtraWidgets")
@ -123,42 +123,102 @@ class FlowLayout(QLayout):
return parent.spacing() return parent.spacing()
class PathEdit(QWidget, Ui_PathEdit): class IndicatorLineEdit(QWidget):
textChanged = pyqtSignal(str)
is_valid = False
def __init__(self,
text: str = "",
ph_text: str = "",
edit_func: Callable[[str], tuple[bool, str]] = None,
save_func: Callable[[str], None] = None,
horiz_policy: QSizePolicy = QSizePolicy.Expanding,
parent=None):
super(IndicatorLineEdit, self).__init__(parent=parent)
self.setObjectName("IndicatorTextEdit")
self.layout = QHBoxLayout(self)
self.layout.setObjectName("layout")
self.layout.setContentsMargins(0, 0, 0, 0)
self.line_edit = QLineEdit(self)
self.line_edit.setObjectName("line_edit")
self.line_edit.setPlaceholderText(ph_text)
self.line_edit.setSizePolicy(horiz_policy, QSizePolicy.Fixed)
self.layout.addWidget(self.line_edit)
if edit_func is not None:
self.indicator_label = QLabel()
self.indicator_label.setPixmap(icon("ei.info-circle", color="gray").pixmap(16, 16))
self.indicator_label.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.layout.addWidget(self.indicator_label)
if not ph_text:
_translate = QCoreApplication.translate
self.line_edit.setPlaceholderText(_translate("PathEdit", "Default"))
if text:
self.line_edit.setText(text)
self.edit_func = edit_func
self.save_func = save_func
self.line_edit.textChanged.connect(self.__edit)
if self.edit_func is None:
self.line_edit.textChanged.connect(self.__save)
def text(self) -> str:
return self.line_edit.text()
def setText(self, text: str):
self.line_edit.setText(text)
def __indicator(self, res):
color = "green" if res else "red"
self.indicator_label.setPixmap(icon("ei.info-circle", color=color).pixmap(16, 16))
def __edit(self, text):
if self.edit_func is not None:
self.line_edit.blockSignals(True)
self.is_valid, text = self.edit_func(text)
self.line_edit.setText(text)
self.line_edit.blockSignals(False)
self.__indicator(self.is_valid)
self.textChanged.emit(text)
if self.is_valid:
self.__save(text)
def __save(self, text):
if self.save_func is not None:
self.save_func(text)
class PathEdit(IndicatorLineEdit):
def __init__(self, def __init__(self,
text: str = "", text: str = "",
file_type: QFileDialog.FileType = QFileDialog.AnyFile, file_type: QFileDialog.FileType = QFileDialog.AnyFile,
type_filter: str = None, type_filter: str = "",
name_filter: str = None, name_filter: str = "",
edit_func: callable = None, ph_text: str = "",
save_func: callable = None): edit_func: Callable[[str], tuple[bool, str]] = None,
super(PathEdit, self).__init__() save_func: Callable[[str], None] = None,
self.setupUi(self) horiz_policy: QSizePolicy = QSizePolicy.Expanding,
parent=None):
super(PathEdit, self).__init__(text=text, ph_text=ph_text,
edit_func=edit_func, save_func=save_func,
horiz_policy=horiz_policy, parent=parent)
self.setObjectName("PathEdit")
self.path_select = QToolButton(self)
self.path_select.setObjectName("path_select")
self.layout.addWidget(self.path_select)
_translate = QCoreApplication.translate
self.path_select.setText(_translate("PathEdit", "Browse..."))
self.type_filter = type_filter self.type_filter = type_filter
self.name_filter = name_filter self.name_filter = name_filter
self.file_type = file_type self.file_type = file_type
self.edit_func = edit_func
self.save_func = save_func
if text:
self.text_edit.setText(text)
if self.edit_func is not None:
self.text_edit.textChanged.connect(self.edit_func)
self.path_select.clicked.connect(self.set_path) self.path_select.clicked.connect(self.__set_path)
self.text_edit.textChanged.connect(self.save)
def text(self): def __set_path(self):
return self.text_edit.text() dlg_path = self.line_edit.text()
def setText(self, text: str):
self.text_edit.setText(text)
def save(self):
if self.save_func:
self.save_func()
def set_path(self):
dlg_path = self.text_edit.text()
if not dlg_path: if not dlg_path:
dlg_path = os.path.expanduser("~/") dlg_path = os.path.expanduser("~/")
dlg = QFileDialog(self, self.tr("Choose path"), dlg_path) dlg = QFileDialog(self, self.tr("Choose path"), dlg_path)
@ -169,14 +229,13 @@ class PathEdit(QWidget, Ui_PathEdit):
dlg.setNameFilter(self.name_filter) dlg.setNameFilter(self.name_filter)
if dlg.exec_(): if dlg.exec_():
names = dlg.selectedFiles() names = dlg.selectedFiles()
self.text_edit.setText(names[0]) self.line_edit.setText(names[0])
self.save()
class SideTabBar(QTabBar): class SideTabBar(QTabBar):
def __init__(self): def __init__(self, parent=None):
super(SideTabBar, self).__init__() super(SideTabBar, self).__init__(parent=parent)
self.setObjectName("settings_bar") self.setObjectName("side_tab_bar")
self.fm = QFontMetrics(self.font()) self.fm = QFontMetrics(self.font())
def tabSizeHint(self, index): def tabSizeHint(self, index):
@ -202,7 +261,7 @@ class SideTabBar(QTabBar):
painter.translate(c) painter.translate(c)
painter.rotate(90) painter.rotate(90)
painter.translate(-c) painter.translate(-c)
painter.drawControl(QStyle.CE_TabBarTabLabel, opt); painter.drawControl(QStyle.CE_TabBarTabLabel, opt)
painter.restore() painter.restore()
@ -260,6 +319,9 @@ class SelectViewWidget(QWidget):
class ImageLabel(QLabel): class ImageLabel(QLabel):
image = None
img_size = None
name = str()
def __init__(self): def __init__(self):
super(ImageLabel, self).__init__() super(ImageLabel, self).__init__()