Add IndicatorLineEdit and base PathEdit on it.
This commit is contained in:
parent
30a70090c5
commit
c1e750138f
|
@ -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 + ".env", "STEAM_COMPAT_DATA_PATH",
|
||||
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
|
||||
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.wine_prefix.text_edit.setText("")
|
||||
self.linux_settings.wine_prefix.setText("")
|
||||
self.linux_settings.save_setting(self.linux_settings.wine_prefix, "wine_prefix")
|
||||
|
||||
self.core.lgd.save_config()
|
||||
|
@ -164,14 +164,14 @@ class GameSettings(QWidget, Ui_GameSettings):
|
|||
text = self.proton_prefix.text()
|
||||
if not text:
|
||||
text = os.path.expanduser("~/.proton")
|
||||
self.proton_prefix.text_edit.setText(text)
|
||||
self.proton_prefix.setText(text)
|
||||
if not os.path.exists(text):
|
||||
try:
|
||||
os.makedirs(text)
|
||||
except PermissionError:
|
||||
QMessageBox.warning(self, "Warning", self.tr("No permission to create folder"))
|
||||
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.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",
|
||||
fallback=self.tr(
|
||||
"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)
|
||||
else:
|
||||
self.proton_wrapper.setCurrentIndex(0)
|
||||
|
@ -243,7 +243,7 @@ class LinuxAppSettings(LinuxSettings):
|
|||
|
||||
def update_game(self, app_name):
|
||||
self.name = app_name
|
||||
self.wine_prefix.text_edit.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_prefix.setText(self.core.lgd.config.get(self.name, "wine_prefix", fallback=""))
|
||||
self.wine_exec.setText(self.core.lgd.config.get(self.name, "wine_executable", fallback=""))
|
||||
self.dxvk.name = app_name
|
||||
self.dxvk.more_settings_widget.name = app_name
|
||||
|
|
|
@ -89,6 +89,8 @@ class ImportWidget(QWidget):
|
|||
if os.path.exists(path):
|
||||
if os.path.exists(os.path.join(path, ".egstore")):
|
||||
self.app_name_input.setText(self.find_app_name(path))
|
||||
return True, path
|
||||
return False, path
|
||||
|
||||
def find_app_name(self, path):
|
||||
if not os.path.exists(os.path.join(path, ".egstore")):
|
||||
|
|
|
@ -17,10 +17,6 @@ QLabel {
|
|||
padding: 0px;
|
||||
}
|
||||
|
||||
QScrollArea#noborder {
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
QMenu,
|
||||
QListView,
|
||||
QListView::item,
|
||||
|
@ -83,6 +79,9 @@ QToolButton {
|
|||
QFrame[frameShape="6"] {
|
||||
border-radius: 4px;
|
||||
}
|
||||
QScrollArea#noborder {
|
||||
border-color: transparent;
|
||||
}
|
||||
QComboBox {
|
||||
background-color: #3c3f41;
|
||||
}
|
||||
|
@ -489,7 +488,7 @@ QTabBar::tab:selected:right {
|
|||
background: qlineargradient(x1: 2, y1: 0, x2: 0, y2: 0,
|
||||
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;
|
||||
border-color: transparent;
|
||||
background-color: transparent;
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import io
|
||||
import os
|
||||
from typing import Callable
|
||||
from logging import getLogger
|
||||
|
||||
import PIL
|
||||
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.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 rare import resources_path, cache_dir
|
||||
from rare.ui.utils.pathedit import Ui_PathEdit
|
||||
from rare.utils.qt_requests import QtRequestManager
|
||||
|
||||
logger = getLogger("ExtraWidgets")
|
||||
|
@ -123,42 +123,102 @@ class FlowLayout(QLayout):
|
|||
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,
|
||||
text: str = "",
|
||||
file_type: QFileDialog.FileType = QFileDialog.AnyFile,
|
||||
type_filter: str = None,
|
||||
name_filter: str = None,
|
||||
edit_func: callable = None,
|
||||
save_func: callable = None):
|
||||
super(PathEdit, self).__init__()
|
||||
self.setupUi(self)
|
||||
type_filter: str = "",
|
||||
name_filter: 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(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.name_filter = name_filter
|
||||
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.text_edit.textChanged.connect(self.save)
|
||||
self.path_select.clicked.connect(self.__set_path)
|
||||
|
||||
def text(self):
|
||||
return self.text_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()
|
||||
def __set_path(self):
|
||||
dlg_path = self.line_edit.text()
|
||||
if not dlg_path:
|
||||
dlg_path = os.path.expanduser("~/")
|
||||
dlg = QFileDialog(self, self.tr("Choose path"), dlg_path)
|
||||
|
@ -169,14 +229,13 @@ class PathEdit(QWidget, Ui_PathEdit):
|
|||
dlg.setNameFilter(self.name_filter)
|
||||
if dlg.exec_():
|
||||
names = dlg.selectedFiles()
|
||||
self.text_edit.setText(names[0])
|
||||
self.save()
|
||||
self.line_edit.setText(names[0])
|
||||
|
||||
|
||||
class SideTabBar(QTabBar):
|
||||
def __init__(self):
|
||||
super(SideTabBar, self).__init__()
|
||||
self.setObjectName("settings_bar")
|
||||
def __init__(self, parent=None):
|
||||
super(SideTabBar, self).__init__(parent=parent)
|
||||
self.setObjectName("side_tab_bar")
|
||||
self.fm = QFontMetrics(self.font())
|
||||
|
||||
def tabSizeHint(self, index):
|
||||
|
@ -202,7 +261,7 @@ class SideTabBar(QTabBar):
|
|||
painter.translate(c)
|
||||
painter.rotate(90)
|
||||
painter.translate(-c)
|
||||
painter.drawControl(QStyle.CE_TabBarTabLabel, opt);
|
||||
painter.drawControl(QStyle.CE_TabBarTabLabel, opt)
|
||||
painter.restore()
|
||||
|
||||
|
||||
|
@ -260,6 +319,9 @@ class SelectViewWidget(QWidget):
|
|||
|
||||
|
||||
class ImageLabel(QLabel):
|
||||
image = None
|
||||
img_size = None
|
||||
name = str()
|
||||
|
||||
def __init__(self):
|
||||
super(ImageLabel, self).__init__()
|
||||
|
|
Loading…
Reference in a new issue