1
0
Fork 0
mirror of synced 2024-06-29 11:40:37 +12:00

Use the tree view for the AppNameCompleter

* IndicatorLineEdit: Add hint label
* EGLSync: Send a list of app_names to update the game list.
* EGLSync: Show message with WINEPREFIX is unset in settings.
* WineResolver: Return empty string when WINEPREFIX is unset.
This commit is contained in:
Stelios Tsampas 2021-11-05 17:48:56 +02:00 committed by Dummerle
parent 5a0646cb87
commit 96144d9da5
No known key found for this signature in database
GPG key ID: AB68CC59CA39F2F1
4 changed files with 59 additions and 26 deletions

View file

@ -1,9 +1,9 @@
import os import os
import platform import platform
from logging import getLogger from logging import getLogger
from typing import List, Tuple, Iterable from typing import Tuple, Iterable
from PyQt5.QtCore import Qt, QThread, QThreadPool, QRunnable, pyqtSlot, QFileSystemWatcher from PyQt5.QtCore import Qt, QThreadPool, QRunnable, pyqtSlot, QFileSystemWatcher
from PyQt5.QtWidgets import QGroupBox, QListWidgetItem, QFileDialog from PyQt5.QtWidgets import QGroupBox, QListWidgetItem, QFileDialog
import rare.shared as shared import rare.shared as shared
@ -27,13 +27,12 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup):
self.threadpool = QThreadPool.globalInstance() self.threadpool = QThreadPool.globalInstance()
if platform.system() == 'Windows': if platform.system() == 'Windows':
estimated_path = os.path.expandvars(PathSpec.egl_programdata) self.egl_path_info.setText(os.path.expandvars(PathSpec.egl_programdata))
else: else:
estimated_path = self.tr('Updating...') self.egl_path_info.setText(self.tr('Updating...'))
wine_resolver = WineResolver(PathSpec.egl_programdata, 'default', shared.core) wine_resolver = WineResolver(PathSpec.egl_programdata, 'default', shared.core)
wine_resolver.signals.result_ready.connect(self.egl_path_info.setText) wine_resolver.signals.result_ready.connect(self.wine_resolver_cb)
self.threadpool.start(wine_resolver) self.threadpool.start(wine_resolver)
self.egl_path_info.setText(estimated_path)
egl_path = shared.core.egl.programdata_path egl_path = shared.core.egl.programdata_path
if egl_path is None: if egl_path is None:
@ -44,7 +43,7 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup):
self.egl_path_edit = PathEdit( self.egl_path_edit = PathEdit(
path=egl_path, path=egl_path,
ph_text=estimated_path, ph_text=self.tr('Path to the Wine prefix where EGL is installed, or the Manifests folder'),
file_type=QFileDialog.DirectoryOnly, file_type=QFileDialog.DirectoryOnly,
edit_func=self.egl_path_edit_cb, edit_func=self.egl_path_edit_cb,
save_func=self.egl_path_save_cb, save_func=self.egl_path_save_cb,
@ -72,6 +71,12 @@ class EGLSyncGroup(QGroupBox, Ui_EGLSyncGroup):
self.update_lists() self.update_lists()
def wine_resolver_cb(self, path):
self.egl_path_info.setText(path)
if not path:
self.egl_path_info.setText(
self.tr('Default Wine prefix is unset, configure it in Settings -> Linux'))
@staticmethod @staticmethod
def egl_path_edit_cb(path) -> Tuple[bool, str]: def egl_path_edit_cb(path) -> Tuple[bool, str]:
if not path: if not path:
@ -161,6 +166,14 @@ class EGLSyncListItem(QListWidgetItem):
else: else:
shared.core.egl_import(self.game.app_name) shared.core.egl_import(self.game.app_name)
@property
def app_name(self):
return self.game.app_name
@property
def app_title(self):
return self.game.app_title
class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup): class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup):
@ -214,12 +227,14 @@ class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup):
self.buttons_widget.setVisible(enabled and bool(self.list.count())) self.buttons_widget.setVisible(enabled and bool(self.list.count()))
def action(self): def action(self):
imported = list()
for item in self.items: for item in self.items:
if item.is_checked(): if item.is_checked():
item.action() item.action()
imported.append(item.app_name)
self.list.takeItem(self.list.row(item)) self.list.takeItem(self.list.row(item))
if not self.export: if not self.export and imported:
shared.signals.update_gamelist.emit(str()) shared.signals.update_gamelist.emit(imported)
self.populate(True) self.populate(True)
@property @property

View file

@ -1,12 +1,11 @@
import json import json
import os import os
from logging import getLogger from logging import getLogger
from typing import Tuple from typing import List, Tuple
from PyQt5.QtCore import Qt, QModelIndex, pyqtSignal from PyQt5.QtCore import Qt, QModelIndex, pyqtSignal
from PyQt5.QtGui import QStandardItemModel from PyQt5.QtGui import QStandardItemModel
from PyQt5.QtWidgets import QFileDialog, QGroupBox, QCompleter, QListView from PyQt5.QtWidgets import QFileDialog, QGroupBox, QCompleter, QListView, QTreeView, QHeaderView
from legendary.core import LegendaryCore
import rare.shared as shared import rare.shared as shared
from rare.ui.components.tabs.games.import_sync.import_group import Ui_ImportGroup from rare.ui.components.tabs.games.import_sync.import_group import Ui_ImportGroup
@ -19,11 +18,11 @@ logger = getLogger("Import")
class AppNameCompleter(QCompleter): class AppNameCompleter(QCompleter):
activated = pyqtSignal(str) activated = pyqtSignal(str)
def __init__(self, core: LegendaryCore, parent=None): def __init__(self, app_names: List, parent=None):
super(AppNameCompleter, self).__init__(parent) super(AppNameCompleter, self).__init__(parent)
# pylint: disable=E1136
super(AppNameCompleter, self).activated[QModelIndex].connect(self.__activated) super(AppNameCompleter, self).activated[QModelIndex].connect(self.__activated)
app_names = [(i.app_name, i.app_title) for i in core.get_game_list()]
model = QStandardItemModel(len(app_names), 2) model = QStandardItemModel(len(app_names), 2)
for idx, game in enumerate(app_names): for idx, game in enumerate(app_names):
app_name, app_title = game app_name, app_title = game
@ -31,16 +30,16 @@ class AppNameCompleter(QCompleter):
model.setData(model.index(idx, 1), app_name) model.setData(model.index(idx, 1), app_name)
self.setModel(model) self.setModel(model)
# treeview = QTreeView() treeview = QTreeView()
# treeview.setRootIsDecorated(False) self.setPopup(treeview)
# treeview.header().hide() treeview.setRootIsDecorated(False)
# treeview.header().setSectionResizeMode(0, QHeaderView.Stretch) treeview.header().hide()
# treeview.header().setSectionResizeMode(1, QHeaderView.ResizeToContents) treeview.header().setSectionResizeMode(0, QHeaderView.Stretch)
# self.setPopup(treeview) treeview.header().setSectionResizeMode(1, QHeaderView.Stretch)
listview = QListView() # listview = QListView()
# listview.setModelColumn(1) # self.setPopup(listview)
self.setPopup(listview) # # listview.setModelColumn(1)
self.setFilterMode(Qt.MatchContains) self.setFilterMode(Qt.MatchContains)
self.setCaseSensitivity(Qt.CaseInsensitive) self.setCaseSensitivity(Qt.CaseInsensitive)
@ -82,7 +81,7 @@ class ImportGroup(QGroupBox, Ui_ImportGroup):
self.app_name = IndicatorLineEdit( self.app_name = IndicatorLineEdit(
ph_text=self.tr("Use in case the app name was not found automatically"), ph_text=self.tr("Use in case the app name was not found automatically"),
completer=AppNameCompleter(self.core), completer=AppNameCompleter(app_names=[(i.app_name, i.app_title) for i in self.core.get_game_list()]),
edit_func=self.app_name_edit_cb, edit_func=self.app_name_edit_cb,
parent=self parent=self
) )

View file

@ -137,14 +137,23 @@ class IndicatorLineEdit(QWidget):
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("IndicatorTextEdit") self.setObjectName("IndicatorLineEdit")
self.layout = QHBoxLayout(self) self.layout = QHBoxLayout(self)
self.layout.setObjectName("layout") self.layout.setObjectName("layout")
self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setContentsMargins(0, 0, 0, 0)
# Add line_edit
self.line_edit = QLineEdit(self) self.line_edit = QLineEdit(self)
self.line_edit.setObjectName("line_edit") self.line_edit.setObjectName("line_edit")
self.line_edit.setPlaceholderText(ph_text) self.line_edit.setPlaceholderText(ph_text)
self.line_edit.setSizePolicy(horiz_policy, QSizePolicy.Fixed) self.line_edit.setSizePolicy(horiz_policy, QSizePolicy.Fixed)
# Add hint_label to line_edit
self.line_edit.setLayout(QHBoxLayout())
self.hint_label = QLabel()
self.hint_label.setObjectName('HintLabel')
self.hint_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
self.line_edit.layout().setContentsMargins(0, 0, 10, 0)
self.line_edit.layout().addWidget(self.hint_label)
# Add completer
if completer is not None: if completer is not None:
completer.popup().setItemDelegate(QStyledItemDelegate(self)) completer.popup().setItemDelegate(QStyledItemDelegate(self))
completer.popup().setAlternatingRowColors(True) completer.popup().setAlternatingRowColors(True)
@ -181,6 +190,10 @@ class IndicatorLineEdit(QWidget):
def setText(self, text: str): def setText(self, text: str):
self.line_edit.setText(text) self.line_edit.setText(text)
def setHintText(self, text: str):
self.hint_label.setFrameRect(self.line_edit.rect())
self.hint_label.setText(text)
def __indicator(self, res): def __indicator(self, res):
color = "green" if res else "red" color = "green" if res else "red"
self.indicator_label.setPixmap(qta_icon("ei.info-circle", color=color).pixmap(16, 16)) self.indicator_label.setPixmap(qta_icon("ei.info-circle", color=color).pixmap(16, 16))

View file

@ -445,6 +445,10 @@ class WineResolver(QRunnable):
@pyqtSlot() @pyqtSlot()
def run(self): def run(self):
if 'WINEPREFIX' not in self.wine_env:
# pylint: disable=E1136
self.signals.result_ready[str].emit(str())
return
path = self.path.strip().replace('/', '\\') path = self.path.strip().replace('/', '\\')
cmd = 'cd {} & cd'.format(path) cmd = 'cd {} & cd'.format(path)
# [self.wine_binary, 'cmd', '/c', 'echo', path] if path not exists alternative # [self.wine_binary, 'cmd', '/c', 'echo', path] if path not exists alternative
@ -459,4 +463,6 @@ class WineResolver(QRunnable):
env=self.wine_env, shell=False, text=True) env=self.wine_env, shell=False, text=True)
out, err = proc.communicate() out, err = proc.communicate()
real_path = os.path.realpath(out.strip()) real_path = os.path.realpath(out.strip())
self.signals.result_ready.emit(real_path) # pylint: disable=E1136
self.signals.result_ready[str].emit(real_path)
return