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

EGLSyncListGroup: Move message box outside of thread to prevent "parent in other thread" crash

This commit is contained in:
loathingKernel 2022-07-02 11:48:33 +03:00
parent 667ca0ecb6
commit 76cd33054a

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 Tuple, Iterable from typing import Tuple, Iterable, List
from PyQt5.QtCore import Qt, QThreadPool, QRunnable, pyqtSlot from PyQt5.QtCore import Qt, QThreadPool, QRunnable, pyqtSlot, pyqtSignal
from PyQt5.QtWidgets import QGroupBox, QListWidgetItem, QFileDialog, QMessageBox from PyQt5.QtWidgets import QGroupBox, QListWidgetItem, QFileDialog, QMessageBox
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton
@ -200,12 +200,16 @@ class EGLSyncListItem(QListWidgetItem):
class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup): class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup):
action_errors = pyqtSignal(list)
def __init__(self, export: bool, parent=None): def __init__(self, export: bool, parent=None):
super(EGLSyncListGroup, self).__init__(parent=parent) super(EGLSyncListGroup, self).__init__(parent=parent)
self.setupUi(self) self.setupUi(self)
self.core = LegendaryCoreSingleton() self.core = LegendaryCoreSingleton()
self.signals = GlobalSignalsSingleton() self.signals = GlobalSignalsSingleton()
self.list.setProperty("noBorder", 1) self.list.setProperty("noBorder", 1)
# TODO: Convert the CSS and the code to adhere to NoFrame
# self.list.setFrameShape(self.list.NoFrame)
self.export = export self.export = export
@ -232,6 +236,8 @@ class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup):
self.action_button.clicked.connect(self.action) self.action_button.clicked.connect(self.action)
self.action_errors.connect(self.show_errors)
def has_selected(self): def has_selected(self):
for item in self.items: for item in self.items:
if item.is_checked(): if item.is_checked():
@ -258,8 +264,8 @@ 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() imported: List = []
errors = list() errors: List = []
for item in self.items: for item in self.items:
if item.is_checked(): if item.is_checked():
if e := item.action(): if e := item.action():
@ -271,13 +277,17 @@ class EGLSyncListGroup(QGroupBox, Ui_EGLSyncListGroup):
self.signals.update_gamelist.emit(imported) self.signals.update_gamelist.emit(imported)
self.populate(True) self.populate(True)
if errors: if errors:
QMessageBox.warning( self.action_errors.emit(errors)
self.parent(),
self.tr("The following errors occurred while {}.").format( @pyqtSlot(list)
self.tr("exporting") if self.export else self.tr("importing") def show_errors(self, errors: List):
), QMessageBox.warning(
"\n".join(errors), self.parent(),
) self.tr("The following errors occurred while {}.").format(
self.tr("exporting") if self.export else self.tr("importing")
),
"\n".join(errors),
)
@property @property
def items(self) -> Iterable[EGLSyncListItem]: def items(self) -> Iterable[EGLSyncListItem]: