mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
fix: slowdowns after import; hard to read popup
QTextEdit() will pin the CPU at 100% for seconds to minutes when fed a large string to display - work around it by switching to QPlainTextEdit(). Also strip HTML before showing the user - easier to read, and less text to display. And turn off word wrap, as it makes it easier to skim, and further reduces the work the widget needs to do. https://forums.ankiweb.net/t/big-issue-where-anki-gets-slow-when-you-import-this-deck/7050
This commit is contained in:
parent
b7bfe58afe
commit
7fc32db0c9
3 changed files with 14 additions and 5 deletions
|
@ -10,7 +10,7 @@ from anki.consts import *
|
|||
from anki.decks import DeckManager
|
||||
from anki.importing.base import Importer
|
||||
from anki.lang import TR
|
||||
from anki.utils import intTime, joinFields, splitFields
|
||||
from anki.utils import intTime, joinFields, splitFields, stripHTMLMedia
|
||||
|
||||
GUID = 1
|
||||
MID = 2
|
||||
|
@ -71,7 +71,9 @@ class Anki2Importer(Importer):
|
|||
######################################################################
|
||||
|
||||
def _logNoteRow(self, action: str, noteRow: List[str]) -> None:
|
||||
self.log.append("[%s] %s" % (action, noteRow[6].replace("\x1f", ", ")))
|
||||
self.log.append(
|
||||
"[%s] %s" % (action, stripHTMLMedia(noteRow[6].replace("\x1f", ", ")))
|
||||
)
|
||||
|
||||
def _importNotes(self) -> None:
|
||||
# build guid -> (id,mod,mid) hash & map of existing note ids
|
||||
|
|
|
@ -398,7 +398,7 @@ def importFile(mw: AnkiQt, file: str) -> None:
|
|||
if "\n" not in log:
|
||||
tooltip(log)
|
||||
else:
|
||||
showText(log)
|
||||
showText(log, plain_text_edit=True)
|
||||
|
||||
mw.reset()
|
||||
|
||||
|
|
|
@ -204,6 +204,7 @@ def showText(
|
|||
minHeight: int = 400,
|
||||
title: str = "Anki",
|
||||
copyBtn: bool = False,
|
||||
plain_text_edit: bool = False,
|
||||
) -> Optional[Tuple[QDialog, QDialogButtonBox]]:
|
||||
if not parent:
|
||||
parent = aqt.mw.app.activeWindow() or aqt.mw
|
||||
|
@ -212,8 +213,14 @@ def showText(
|
|||
disable_help_button(diag)
|
||||
layout = QVBoxLayout(diag)
|
||||
diag.setLayout(layout)
|
||||
text = QTextBrowser()
|
||||
text.setOpenExternalLinks(True)
|
||||
if plain_text_edit:
|
||||
# used by the importer
|
||||
text = QPlainTextEdit()
|
||||
text.setReadOnly(True)
|
||||
text.setWordWrapMode(QTextOption.NoWrap)
|
||||
else:
|
||||
text = QTextBrowser()
|
||||
text.setOpenExternalLinks(True)
|
||||
if type == "text":
|
||||
text.setPlainText(txt)
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue