possible workaround for the win32 images issue

This commit is contained in:
Damien Elmes 2012-08-30 22:28:49 +09:00
parent 402aab88bf
commit f72a99abf4

View file

@ -6,7 +6,7 @@ import time, os, stat, shutil, difflib, re, cgi
import unicodedata as ucd import unicodedata as ucd
import HTMLParser import HTMLParser
from aqt.qt import * from aqt.qt import *
from anki.utils import fmtTimeSpan, stripHTML, isMac, json from anki.utils import fmtTimeSpan, stripHTML, isMac, json, isWin
from anki.hooks import addHook, runHook, runFilter from anki.hooks import addHook, runHook, runFilter
from anki.sound import playFromText, clearAudioQueue, hasSound, play from anki.sound import playFromText, clearAudioQueue, hasSound, play
from aqt.utils import mungeQA, getBase, shortcut, openLink, tooltip from aqt.utils import mungeQA, getBase, shortcut, openLink, tooltip
@ -110,6 +110,7 @@ class Reviewer(object):
<div id=qa></div> <div id=qa></div>
<script> <script>
var ankiPlatform = "desktop"; var ankiPlatform = "desktop";
var isWin = %s;
var typeans; var typeans;
function _updateQA (q, answerMode, klass) { function _updateQA (q, answerMode, klass) {
$("#qa").html(q); $("#qa").html(q);
@ -125,6 +126,7 @@ function _updateQA (q, answerMode, klass) {
if (klass) { if (klass) {
document.body.className = klass; document.body.className = klass;
} }
if (isWin) { setTimeout(200, function () { _imageLoadHack(0); }); }
}; };
function _toggleStar (show) { function _toggleStar (show) {
@ -140,13 +142,32 @@ function _getTypedText () {
py.link("typeans:"+typeans.value); py.link("typeans:"+typeans.value);
} }
}; };
function _typeAnsPress() { function _typeAnsPress() {
if (window.event.keyCode === 13) { if (window.event.keyCode === 13) {
py.link("ans"); py.link("ans");
} }
} }
function _imageLoadHack (tries) {
var spacing = [1000, 2000];
var checkAgain = false;
/* try to work around win32 intermittently failing to load images in qt4.7 */
$('img').each(function (idx) {
if (!this.complete) {
checkAgain = true;
this.src += '?'+(new Date().getTime());
}
});
if (checkAgain && tries < spacing.length) {
// check again later
console.log("resched for " + spacing[tries]);
setTimeout(function () { _imageLoadHack(tries+1); },
spacing[tries]);
}
}
</script> </script>
""" """ % json.dumps(isWin)
def _initWeb(self): def _initWeb(self):
self._reps = 0 self._reps = 0