try to work around the qbytearray issue

https://anki.tenderapp.com/discussions/ankidesktop/3369-bug-report-for-restoring-from-backup
This commit is contained in:
Damien Elmes 2013-10-18 07:48:45 +09:00
parent da1672d42f
commit 9cb1d19dc2

View file

@ -2,20 +2,29 @@
# -*- coding: utf-8 -*-
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import os, sys, re, traceback, signal
import os
import sys
import re
import traceback
import signal
import zipfile
from send2trash import send2trash
from aqt.qt import *
from anki import Collection
from anki.utils import isWin, isMac, intTime, splitFields, ids2str
from anki.hooks import runHook, addHook
import aqt, aqt.progress, aqt.webview, aqt.toolbar, aqt.stats
from anki.hooks import runHook, addHook
import aqt
import aqt.progress
import aqt.webview
import aqt.toolbar
import aqt.stats
from aqt.utils import restoreGeom, showInfo, showWarning,\
restoreState, getOnlyText, askUser, applyStyles, showText, tooltip, \
openHelp, openLink, checkInvalidFilename
class AnkiQt(QMainWindow):
def __init__(self, app, profileManager, args):
QMainWindow.__init__(self)
@ -159,7 +168,6 @@ class AnkiQt(QMainWindow):
return True
def profileNameOk(self, str):
from anki.utils import invalidFilename, invalidFilenameChars
return not checkInvalidFilename(str)
def onAddProfile(self):
@ -1051,6 +1059,8 @@ will be lost. Continue?"""))
elif isWin:
# make sure ctypes is bundled
from ctypes import windll, wintypes
_dummy = windll
_dummy = wintypes
def maybeHideAccelerators(self, tgt=None):
if not self.hideMenuAccels:
@ -1076,6 +1086,10 @@ will be lost. Continue?"""))
self.connect(self.app, SIGNAL("appMsg"), self.onAppMsg)
def onAppMsg(self, buf):
if not isinstance(buf, unicode):
# even though we're sending this as unicode up above,
# a bug report still came in that we were receiving a qbytearray
buf = unicode(buf, "utf8", "ignore")
if self.state == "startup":
# try again in a second
return self.progress.timer(1000, lambda: self.onAppMsg(buf), False)