mirror of
https://github.com/ankitects/anki.git
synced 2025-12-30 23:32:57 -05: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
576f0043e4
commit
5a54d5e07d
3 changed files with 26 additions and 16 deletions
|
|
@ -10,7 +10,7 @@ from anki.consts import *
|
||||||
from anki.decks import DeckManager
|
from anki.decks import DeckManager
|
||||||
from anki.importing.base import Importer
|
from anki.importing.base import Importer
|
||||||
from anki.rsbackend import TR
|
from anki.rsbackend import TR
|
||||||
from anki.utils import intTime, joinFields, splitFields
|
from anki.utils import intTime, joinFields, splitFields, stripHTMLMedia
|
||||||
|
|
||||||
GUID = 1
|
GUID = 1
|
||||||
MID = 2
|
MID = 2
|
||||||
|
|
@ -71,7 +71,9 @@ class Anki2Importer(Importer):
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def _logNoteRow(self, action: str, noteRow: List[str]) -> None:
|
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:
|
def _importNotes(self) -> None:
|
||||||
# build guid -> (id,mod,mid) hash & map of existing note ids
|
# build guid -> (id,mod,mid) hash & map of existing note ids
|
||||||
|
|
|
||||||
|
|
@ -391,7 +391,7 @@ def importFile(mw, file):
|
||||||
if "\n" not in log:
|
if "\n" not in log:
|
||||||
tooltip(log)
|
tooltip(log)
|
||||||
else:
|
else:
|
||||||
showText(log)
|
showText(log, plain_text_edit=True)
|
||||||
|
|
||||||
mw.reset()
|
mw.reset()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from typing import TYPE_CHECKING, Any, List, Optional, Union
|
from typing import TYPE_CHECKING, Any, List, Optional, Tuple, Union
|
||||||
|
|
||||||
import anki
|
import anki
|
||||||
import aqt
|
import aqt
|
||||||
|
|
@ -113,24 +113,31 @@ def showInfo(
|
||||||
|
|
||||||
|
|
||||||
def showText(
|
def showText(
|
||||||
txt,
|
txt: str,
|
||||||
parent=None,
|
parent: Optional[QWidget] = None,
|
||||||
type="text",
|
type: str = "text",
|
||||||
run=True,
|
run: bool = True,
|
||||||
geomKey=None,
|
geomKey: Optional[str] = None,
|
||||||
minWidth=500,
|
minWidth: int = 500,
|
||||||
minHeight=400,
|
minHeight: int = 400,
|
||||||
title="Anki",
|
title: str = "Anki",
|
||||||
copyBtn=False,
|
copyBtn: bool = False,
|
||||||
):
|
plain_text_edit: bool = False,
|
||||||
|
) -> Optional[Tuple[QDialog, QDialogButtonBox]]:
|
||||||
if not parent:
|
if not parent:
|
||||||
parent = aqt.mw.app.activeWindow() or aqt.mw
|
parent = aqt.mw.app.activeWindow() or aqt.mw
|
||||||
diag = QDialog(parent)
|
diag = QDialog(parent)
|
||||||
diag.setWindowTitle(title)
|
diag.setWindowTitle(title)
|
||||||
layout = QVBoxLayout(diag)
|
layout = QVBoxLayout(diag)
|
||||||
diag.setLayout(layout)
|
diag.setLayout(layout)
|
||||||
text = QTextBrowser()
|
if plain_text_edit:
|
||||||
text.setOpenExternalLinks(True)
|
# used by the importer
|
||||||
|
text = QPlainTextEdit()
|
||||||
|
text.setReadOnly(True)
|
||||||
|
text.setWordWrapMode(QTextOption.NoWrap)
|
||||||
|
else:
|
||||||
|
text = QTextBrowser()
|
||||||
|
text.setOpenExternalLinks(True)
|
||||||
if type == "text":
|
if type == "text":
|
||||||
text.setPlainText(txt)
|
text.setPlainText(txt)
|
||||||
else:
|
else:
|
||||||
|
|
@ -165,6 +172,7 @@ def showText(
|
||||||
restoreGeom(diag, geomKey)
|
restoreGeom(diag, geomKey)
|
||||||
if run:
|
if run:
|
||||||
diag.exec_()
|
diag.exec_()
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
return diag, box
|
return diag, box
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue