From 9cb1d19dc23d6846da5be6ed1926dd60ab4f1a61 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 18 Oct 2013 07:48:45 +0900 Subject: [PATCH] try to work around the qbytearray issue https://anki.tenderapp.com/discussions/ankidesktop/3369-bug-report-for-restoring-from-backup --- aqt/main.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/aqt/main.py b/aqt/main.py index 3d703aa6b..645b39391 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -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)