refactor error handler to handle error messages in other threads, mention mplayer

This commit is contained in:
Damien Elmes 2009-04-25 02:38:16 +09:00
parent 29bbbe0416
commit 4fd65c37c5

View file

@ -126,29 +126,42 @@ class AnkiQt(QMainWindow):
self.parent = parent self.parent = parent
self.timer = None self.timer = None
self.pool = "" self.pool = ""
self.poolUpdated = 0
def write(self, data): def write(self, data):
print data.encode("utf-8"), print data.encode("utf-8"),
self.pool += data self.pool += data
self.updateTimer() self.poolUpdated = time.time()
def updateTimer(self): def haveError(self):
interval = 200 if self.pool:
if not self.timer: if (time.time() - self.poolUpdated) > 1:
self.timer = QTimer(self.parent) return True
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): def getError(self):
if "font_manager.py" in self.pool: p = self.pool
# hack for matplotlib errors on osx self.pool = ""
self.pool = "" return p
stdText = _("""\
self.errorPipe = ErrorPipe(self)
sys.stderr = self.errorPipe
self.errorTimer = QTimer(self)
self.errorTimer.start(1000)
self.connect(self.errorTimer,
SIGNAL("timeout()"),
self.onErrorTimer)
def onErrorTimer(self):
if self.errorPipe.haveError():
error = self.errorPipe.getError()
if "font_manager.py" in error:
# hack for matplotlib errors on osx
return
if "Audio player not found" in error:
ui.utils.showInfo(
_("Couldn't play sound. Please install mplayer."))
return
stdText = _("""\
An error occurred. Please:<p> An error occurred. Please:<p>
<ol> <ol>
<li><b>Restart Anki</b>. <li><b>Restart Anki</b>.
@ -157,21 +170,16 @@ An error occurred. Please:<p>
If it does not fix the problem, please copy the following<br> If it does not fix the problem, please copy the following<br>
into a bug report:<br><br> into a bug report:<br><br>
""") """)
pluginText = _("""\ pluginText = _("""\
An error occurred in a plugin. Please contact the plugin author.<br> An error occurred in a plugin. Please contact the plugin author.<br>
Please do not file a bug report with Anki.<br><br>""") Please do not file a bug report with Anki.<br><br>""")
if "plugin" in self.pool: if "plugin" in error:
txt = pluginText txt = pluginText
else: else:
txt = stdText txt = stdText
if self.pool: self.errorOccurred = True
self.parent.errorOccurred = True ui.utils.showText(txt + error[0:10000].replace(
ui.utils.showText(txt + self.pool[0:10000].replace(
"\n", "<br>")) "\n", "<br>"))
self.pool = ""
self.timer = None
pipe = ErrorPipe(self)
sys.stderr = pipe
def closeAllDeckWindows(self): def closeAllDeckWindows(self):
ui.dialogs.closeAll() ui.dialogs.closeAll()