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 -*- # -*- coding: utf-8 -*-
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # 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 import zipfile
from send2trash import send2trash from send2trash import send2trash
from aqt.qt import * from aqt.qt import *
from anki import Collection from anki import Collection
from anki.utils import isWin, isMac, intTime, splitFields, ids2str 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,\ from aqt.utils import restoreGeom, showInfo, showWarning,\
restoreState, getOnlyText, askUser, applyStyles, showText, tooltip, \ restoreState, getOnlyText, askUser, applyStyles, showText, tooltip, \
openHelp, openLink, checkInvalidFilename openHelp, openLink, checkInvalidFilename
class AnkiQt(QMainWindow): class AnkiQt(QMainWindow):
def __init__(self, app, profileManager, args): def __init__(self, app, profileManager, args):
QMainWindow.__init__(self) QMainWindow.__init__(self)
@ -159,7 +168,6 @@ class AnkiQt(QMainWindow):
return True return True
def profileNameOk(self, str): def profileNameOk(self, str):
from anki.utils import invalidFilename, invalidFilenameChars
return not checkInvalidFilename(str) return not checkInvalidFilename(str)
def onAddProfile(self): def onAddProfile(self):
@ -1051,6 +1059,8 @@ will be lost. Continue?"""))
elif isWin: elif isWin:
# make sure ctypes is bundled # make sure ctypes is bundled
from ctypes import windll, wintypes from ctypes import windll, wintypes
_dummy = windll
_dummy = wintypes
def maybeHideAccelerators(self, tgt=None): def maybeHideAccelerators(self, tgt=None):
if not self.hideMenuAccels: if not self.hideMenuAccels:
@ -1076,6 +1086,10 @@ will be lost. Continue?"""))
self.connect(self.app, SIGNAL("appMsg"), self.onAppMsg) self.connect(self.app, SIGNAL("appMsg"), self.onAppMsg)
def onAppMsg(self, buf): 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": if self.state == "startup":
# try again in a second # try again in a second
return self.progress.timer(1000, lambda: self.onAppMsg(buf), False) return self.progress.timer(1000, lambda: self.onAppMsg(buf), False)