Fix displaying on unhandled exceptions
This commit is contained in:
parent
5aa718bea4
commit
37db3c1e01
@ -10,7 +10,7 @@ import pwd
|
|||||||
import signal
|
import signal
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt, QSocketNotifier
|
from PyQt5.QtCore import Qt, QSocketNotifier, pyqtSignal
|
||||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
|
||||||
|
|
||||||
from .config import load_config, validate_font
|
from .config import load_config, validate_font
|
||||||
@ -21,10 +21,13 @@ from .utils import fork_child
|
|||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
|
|
||||||
|
report_error = pyqtSignal(object)
|
||||||
|
|
||||||
def __init__(self, opts):
|
def __init__(self, opts):
|
||||||
QMainWindow.__init__(self)
|
QMainWindow.__init__(self)
|
||||||
self.setWindowTitle(appname)
|
self.setWindowTitle(appname)
|
||||||
sys.excepthook = self.on_unhandled_error
|
sys.excepthook = self.on_unhandled_error
|
||||||
|
self.report_error.connect(self.show_error, type=Qt.QueuedConnection)
|
||||||
self.handle_unix_signals()
|
self.handle_unix_signals()
|
||||||
self.boss = Boss(opts, self)
|
self.boss = Boss(opts, self)
|
||||||
self.setCentralWidget(self.boss.term)
|
self.setCentralWidget(self.boss.term)
|
||||||
@ -37,6 +40,9 @@ class MainWindow(QMainWindow):
|
|||||||
msg = str(value)
|
msg = str(value)
|
||||||
except Exception:
|
except Exception:
|
||||||
msg = repr(value)
|
msg = repr(value)
|
||||||
|
self.report_error.emit(msg)
|
||||||
|
|
||||||
|
def show_error(self, msg):
|
||||||
QMessageBox.critical(self, _('Unhandled exception'), msg)
|
QMessageBox.critical(self, _('Unhandled exception'), msg)
|
||||||
|
|
||||||
def handle_unix_signals(self):
|
def handle_unix_signals(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user