catch stderr and output to dialog in real time

This commit is contained in:
Damien Elmes 2008-11-28 20:03:01 +09:00
parent 37f96fb5a7
commit 6e885557f5
3 changed files with 52 additions and 31 deletions

View file

@ -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
##########################################################################

View file

@ -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:

View file

@ -189,14 +189,14 @@
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menu_Edit" >
<widget class="QMenu" name="menuEdit" >
<property name="title" >
<string>&amp;Edit</string>
</property>
<addaction name="actionSelectAll" />
<addaction name="actionSelectFacts" />
</widget>
<widget class="QMenu" name="menu_Actions" >
<widget class="QMenu" name="menuActions" >
<property name="title" >
<string>&amp;Actions</string>
</property>
@ -207,11 +207,9 @@
<addaction name="separator" />
<addaction name="actionResetProgress" />
<addaction name="actionDelete" />
<addaction name="separator" />
<addaction name="actionClose" />
</widget>
<addaction name="menu_Actions" />
<addaction name="menu_Edit" />
<addaction name="menuActions" />
<addaction name="menuEdit" />
</widget>
<widget class="QStatusBar" name="statusbar" >
<property name="geometry" >
@ -271,15 +269,6 @@
<string>Reset Progress</string>
</property>
</action>
<action name="actionClose" >
<property name="icon" >
<iconset resource="../icons.qrc" >
<normaloff>:/icons/fileclose.png</normaloff>:/icons/fileclose.png</iconset>
</property>
<property name="text" >
<string>Close</string>
</property>
</action>
<action name="actionSelectAll" >
<property name="text" >
<string>Select &amp;All</string>
@ -314,21 +303,5 @@
</hint>
</hints>
</connection>
<connection>
<sender>actionClose</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel" >
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel" >
<x>299</x>
<y>300</y>
</hint>
</hints>
</connection>
</connections>
</ui>