diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index d91fda249..f2dabf4e4 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -69,6 +69,7 @@ class AnkiQt(QMainWindow): traceback.format_exc()) # check for updates self.setupAutoUpdate() + self.setupErrorHandler() def setupMainWindow(self): self.mainWin = ankiqt.forms.main.Ui_MainWindow() @@ -95,6 +96,36 @@ class AnkiQt(QMainWindow): def setupTray(self): self.trayIcon = ui.tray.AnkiTrayIcon(self) + def setupErrorHandler(self): + class ErrorPipe(object): + def __init__(self, parent): + self.parent = parent + self.timer = None + self.pool = "" + + def write(self, data): + self.pool += data + self.updateTimer() + + def updateTimer(self): + interval = 200 + if not self.timer: + self.timer = QTimer(self.parent) + self.timer.setSingleShot(True) + self.timer.start(interval) + self.parent.connect(self.timer, + SIGNAL("timeout()"), + self.onTimeout) + else: + self.timer.setInterval(interval) + + def onTimeout(self): + ui.utils.showText(_("""\ +An error occurred. Please copy the following message into a bug report.\n\n""" + self.pool)) + self.pool = "" + self.timer = None + pipe = ErrorPipe(self) + sys.stderr = pipe # State machine ########################################################################## diff --git a/ankiqt/ui/utils.py b/ankiqt/ui/utils.py index ca1b0ec32..8169f6c78 100644 --- a/ankiqt/ui/utils.py +++ b/ankiqt/ui/utils.py @@ -36,6 +36,23 @@ def showInfo(text, parent=None, help=""): else: break +def showText(text, parent=None): + if not parent: + parent = ankiqt.mw + d = QDialog(parent) + d.setWindowTitle("Anki") + v = QVBoxLayout() + l = QLabel(text) + l.setTextInteractionFlags(Qt.TextSelectableByMouse) + v.addWidget(l) + buts = QDialogButtonBox.Ok + b = QDialogButtonBox(buts) + v.addWidget(b) + d.setLayout(v) + d.connect(b.button(QDialogButtonBox.Ok), + SIGNAL("clicked()"), d.accept) + d.exec_() + def askUser(text, parent=None): "Show a yes/no question. Return true if yes." if not parent: diff --git a/designer/cardlist.ui b/designer/cardlist.ui index c751fe374..35cfec9e2 100644 --- a/designer/cardlist.ui +++ b/designer/cardlist.ui @@ -189,14 +189,14 @@ 23 - + &Edit - + &Actions @@ -207,11 +207,9 @@ - - - - + + @@ -271,15 +269,6 @@ Reset Progress - - - - :/icons/fileclose.png:/icons/fileclose.png - - - Close - - Select &All @@ -314,21 +303,5 @@ - - actionClose - triggered() - MainWindow - close() - - - -1 - -1 - - - 299 - 300 - - -