ElideLabel: Enable word-wrapping for elided labels.
Word wrapping allows ElideLabel to resize first inside flexible sized areas such as the contents widget of a scrollarea. This allows the contents widget to properly resize itself to avoid horizontal scrolling. Word-wrapping also enables the widget to resize vertically. To avoid that ElideLabel is set to a fixed height based on font metrics. An overloaded method `setFixedHeight` has been added to disable it when desired. EglSyncGroup: Replace estimated path label with a ElideLabel because the displayed message was expanding the scrollarea.
This commit is contained in:
parent
76068014b8
commit
3e827f4ece
|
@ -180,7 +180,8 @@ class LaunchDialog(QDialog):
|
|||
self.ui.setupUi(self)
|
||||
|
||||
self.progress_info = ElideLabel(parent=self)
|
||||
self.layout().addWidget(self.progress_info)
|
||||
self.progress_info.setFixedHeight(False)
|
||||
self.ui.launch_dialog_layout.addWidget(self.progress_info)
|
||||
|
||||
self.core = LegendaryCoreSingleton()
|
||||
self.args = ArgumentsSingleton()
|
||||
|
|
|
@ -5,7 +5,7 @@ from logging import getLogger
|
|||
from typing import Tuple, Iterable, List, Union
|
||||
|
||||
from PyQt5.QtCore import Qt, QThreadPool, QRunnable, pyqtSlot, pyqtSignal
|
||||
from PyQt5.QtWidgets import QGroupBox, QListWidgetItem, QFileDialog, QMessageBox, QFrame
|
||||
from PyQt5.QtWidgets import QGroupBox, QListWidgetItem, QFileDialog, QMessageBox, QFrame, QLabel
|
||||
from legendary.models.egl import EGLManifest
|
||||
from legendary.models.game import InstalledGame
|
||||
|
||||
|
@ -16,6 +16,7 @@ from rare.shared.workers.wine_resolver import WineResolver
|
|||
from rare.ui.components.tabs.games.integrations.egl_sync_group import Ui_EGLSyncGroup
|
||||
from rare.ui.components.tabs.games.integrations.egl_sync_list_group import Ui_EGLSyncListGroup
|
||||
from rare.widgets.indicator_edit import PathEdit, IndicatorReasonsCommon
|
||||
from rare.widgets.elide_label import ElideLabel
|
||||
|
||||
logger = getLogger("EGLSync")
|
||||
|
||||
|
@ -26,14 +27,19 @@ class EGLSyncGroup(QGroupBox):
|
|||
self.ui = Ui_EGLSyncGroup()
|
||||
self.ui.setupUi(self)
|
||||
self.core = RareCore.instance().core()
|
||||
self.ui.egl_path_info.setProperty("infoLabel", 1)
|
||||
|
||||
self.thread_pool = QThreadPool.globalInstance()
|
||||
self.egl_path_info_label = QLabel(self.tr("Estimated path"), self)
|
||||
self.egl_path_info = ElideLabel("", parent=self)
|
||||
self.egl_path_info.setProperty("infoLabel", 1)
|
||||
self.ui.egl_sync_layout.insertRow(
|
||||
self.ui.egl_sync_layout.indexOf(self.ui.egl_path_edit_label) + 1,
|
||||
self.egl_path_info_label, self.egl_path_info
|
||||
)
|
||||
|
||||
if platform.system() == "Windows":
|
||||
self.ui.egl_path_edit_label.setVisible(False)
|
||||
self.ui.egl_path_info_label.setVisible(False)
|
||||
self.ui.egl_path_info.setVisible(False)
|
||||
self.egl_path_info_label.setVisible(False)
|
||||
self.egl_path_info.setVisible(False)
|
||||
else:
|
||||
self.egl_path_edit = PathEdit(
|
||||
path=self.core.egl.programdata_path,
|
||||
|
@ -49,15 +55,15 @@ class EGLSyncGroup(QGroupBox):
|
|||
self.ui.egl_path_edit_layout.addWidget(self.egl_path_edit)
|
||||
|
||||
if not self.core.egl.programdata_path:
|
||||
self.ui.egl_path_info.setText(self.tr("Updating..."))
|
||||
self.egl_path_info.setText(self.tr("Updating..."))
|
||||
wine_resolver = WineResolver(
|
||||
self.core, PathSpec.egl_programdata, "default"
|
||||
)
|
||||
wine_resolver.signals.result_ready.connect(self.wine_resolver_cb)
|
||||
self.thread_pool.start(wine_resolver)
|
||||
QThreadPool.globalInstance().start(wine_resolver)
|
||||
else:
|
||||
self.ui.egl_path_info_label.setVisible(False)
|
||||
self.ui.egl_path_info.setVisible(False)
|
||||
self.egl_path_info_label.setVisible(False)
|
||||
self.egl_path_info.setVisible(False)
|
||||
|
||||
self.ui.egl_sync_check.setChecked(self.core.egl_sync_enabled)
|
||||
self.ui.egl_sync_check.stateChanged.connect(self.egl_sync_changed)
|
||||
|
@ -73,16 +79,16 @@ class EGLSyncGroup(QGroupBox):
|
|||
self.update_lists()
|
||||
|
||||
def wine_resolver_cb(self, path):
|
||||
self.ui.egl_path_info.setText(path)
|
||||
self.egl_path_info.setText(path)
|
||||
if not path:
|
||||
self.ui.egl_path_info.setText(
|
||||
self.egl_path_info.setText(
|
||||
self.tr(
|
||||
"Default Wine prefix is unset, or path does not exist. "
|
||||
"Create it or configure it in Settings -> Linux."
|
||||
)
|
||||
)
|
||||
elif not os.path.exists(path):
|
||||
self.ui.egl_path_info.setText(
|
||||
self.egl_path_info.setText(
|
||||
self.tr(
|
||||
"Default Wine prefix is set but EGL manifests path does not exist. "
|
||||
"Your configured default Wine prefix might not be where EGL is installed."
|
||||
|
@ -148,7 +154,7 @@ class EGLSyncGroup(QGroupBox):
|
|||
self.import_list.mark(Qt.Checked)
|
||||
self.export_list.mark(Qt.Checked)
|
||||
sync_worker = EGLSyncWorker(self.import_list, self.export_list)
|
||||
self.thread_pool.start(sync_worker)
|
||||
QThreadPool.globalInstance().start(sync_worker)
|
||||
self.import_list.setEnabled(False)
|
||||
self.export_list.setEnabled(False)
|
||||
# self.update_lists()
|
||||
|
@ -365,6 +371,7 @@ class EGLSyncImportGroup(EGLSyncListGroup):
|
|||
if errors:
|
||||
self.action_errors.emit(errors)
|
||||
|
||||
|
||||
class EGLSyncWorker(QRunnable):
|
||||
def __init__(self, import_list: EGLSyncListGroup, export_list: EGLSyncListGroup):
|
||||
super(EGLSyncWorker, self).__init__()
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'rare/ui/components/tabs/games/import_sync/egl_sync_group.ui'
|
||||
# Form implementation generated from reading ui file 'rare/ui/components/tabs/games/integrations/egl_sync_group.ui'
|
||||
#
|
||||
# Created by: PyQt5 UI code generator 5.15.6
|
||||
# Created by: PyQt5 UI code generator 5.15.9
|
||||
#
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
|
@ -14,7 +14,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
|||
class Ui_EGLSyncGroup(object):
|
||||
def setupUi(self, EGLSyncGroup):
|
||||
EGLSyncGroup.setObjectName("EGLSyncGroup")
|
||||
EGLSyncGroup.resize(478, 106)
|
||||
EGLSyncGroup.resize(217, 88)
|
||||
EGLSyncGroup.setWindowTitle("EGLSyncGroup")
|
||||
EGLSyncGroup.setCheckable(False)
|
||||
EGLSyncGroup.setChecked(False)
|
||||
|
@ -27,24 +27,16 @@ class Ui_EGLSyncGroup(object):
|
|||
self.egl_path_edit_layout = QtWidgets.QHBoxLayout()
|
||||
self.egl_path_edit_layout.setObjectName("egl_path_edit_layout")
|
||||
self.egl_sync_layout.setLayout(0, QtWidgets.QFormLayout.FieldRole, self.egl_path_edit_layout)
|
||||
self.egl_path_info_label = QtWidgets.QLabel(EGLSyncGroup)
|
||||
self.egl_path_info_label.setObjectName("egl_path_info_label")
|
||||
self.egl_sync_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.egl_path_info_label)
|
||||
self.egl_path_info = QtWidgets.QLabel(EGLSyncGroup)
|
||||
self.egl_path_info.setText("error")
|
||||
self.egl_path_info.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextSelectableByMouse)
|
||||
self.egl_path_info.setObjectName("egl_path_info")
|
||||
self.egl_sync_layout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.egl_path_info)
|
||||
self.egl_sync_check_label = QtWidgets.QLabel(EGLSyncGroup)
|
||||
self.egl_sync_check_label.setObjectName("egl_sync_check_label")
|
||||
self.egl_sync_layout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.egl_sync_check_label)
|
||||
self.egl_sync_check = QtWidgets.QCheckBox(EGLSyncGroup)
|
||||
self.egl_sync_check.setText("")
|
||||
self.egl_sync_check.setObjectName("egl_sync_check")
|
||||
self.egl_sync_layout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.egl_sync_check)
|
||||
self.egl_sync_layout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.egl_sync_check)
|
||||
self.import_export_layout = QtWidgets.QVBoxLayout()
|
||||
self.import_export_layout.setObjectName("import_export_layout")
|
||||
self.egl_sync_layout.setLayout(3, QtWidgets.QFormLayout.SpanningRole, self.import_export_layout)
|
||||
self.egl_sync_check_label = QtWidgets.QLabel(EGLSyncGroup)
|
||||
self.egl_sync_check_label.setObjectName("egl_sync_check_label")
|
||||
self.egl_sync_layout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.egl_sync_check_label)
|
||||
self.egl_sync_layout.setLayout(2, QtWidgets.QFormLayout.SpanningRole, self.import_export_layout)
|
||||
|
||||
self.retranslateUi(EGLSyncGroup)
|
||||
|
||||
|
@ -52,7 +44,6 @@ class Ui_EGLSyncGroup(object):
|
|||
_translate = QtCore.QCoreApplication.translate
|
||||
EGLSyncGroup.setTitle(_translate("EGLSyncGroup", "Sync with Epic Games Launcher"))
|
||||
self.egl_path_edit_label.setText(_translate("EGLSyncGroup", "Prefix/Manifest path"))
|
||||
self.egl_path_info_label.setText(_translate("EGLSyncGroup", "Estimated path"))
|
||||
self.egl_sync_check_label.setText(_translate("EGLSyncGroup", "Enable automatic sync"))
|
||||
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>478</width>
|
||||
<height>106</height>
|
||||
<width>217</width>
|
||||
<height>88</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -37,39 +37,22 @@
|
|||
<layout class="QHBoxLayout" name="egl_path_edit_layout"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="egl_path_info_label">
|
||||
<property name="text">
|
||||
<string>Estimated path</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="egl_path_info">
|
||||
<property name="text">
|
||||
<string notr="true">error</string>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="egl_sync_check">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<layout class="QVBoxLayout" name="import_export_layout"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="egl_sync_check_label">
|
||||
<property name="text">
|
||||
<string>Enable automatic sync</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="egl_sync_check">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<layout class="QVBoxLayout" name="import_export_layout"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
|
|
@ -1,28 +1,38 @@
|
|||
from typing import Union
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QFontMetrics, QResizeEvent
|
||||
from PyQt5.QtWidgets import QLabel
|
||||
from PyQt5.QtWidgets import QLabel, QWIDGETSIZE_MAX
|
||||
|
||||
|
||||
class ElideLabel(QLabel):
|
||||
__text: str = ""
|
||||
|
||||
def __init__(self, text="", parent=None, flags=Qt.WindowFlags()):
|
||||
super(ElideLabel, self).__init__(parent=parent, flags=flags)
|
||||
if text:
|
||||
self.setText(text)
|
||||
def __init__(self, text="", parent=None):
|
||||
super(ElideLabel, self).__init__(parent=parent)
|
||||
self.__text = text
|
||||
self.__fm = QFontMetrics(self.font())
|
||||
self.setFixedHeight(True)
|
||||
self.setWordWrap(True)
|
||||
self.setText(text)
|
||||
|
||||
def setText(self, a0: str) -> None:
|
||||
self.__text = a0
|
||||
self.__setElideText(a0)
|
||||
|
||||
def __setElideText(self, a0: str):
|
||||
metrics = QFontMetrics(self.font())
|
||||
elided_text = metrics.elidedText(
|
||||
elided_text = self.__fm.elidedText(
|
||||
a0, Qt.ElideRight,
|
||||
self.width() - self.contentsMargins().left() - self.contentsMargins().right()
|
||||
self.width() - (self.contentsMargins().left() + self.contentsMargins().right())
|
||||
)
|
||||
self.setToolTip(self.__text if elided_text != self.__text else "")
|
||||
super(ElideLabel, self).setText(elided_text)
|
||||
|
||||
def resizeEvent(self, a0: QResizeEvent) -> None:
|
||||
self.__setElideText(self.__text)
|
||||
super(ElideLabel, self).resizeEvent(a0)
|
||||
|
||||
def setFixedHeight(self, h: Union[int, bool]) -> None:
|
||||
if isinstance(h, bool):
|
||||
super(ElideLabel, self).setFixedHeight(self.__fm.height() if h else QWIDGETSIZE_MAX)
|
||||
elif isinstance(h, int):
|
||||
super(ElideLabel, self).setFixedHeight(h)
|
||||
|
|
Loading…
Reference in a new issue