apply standard zoom and background to graphs; prevent FOUC

This commit is contained in:
Damien Elmes 2020-08-27 18:39:27 +10:00
parent 0564d4cf86
commit 5520163bf7
2 changed files with 18 additions and 1 deletions

View file

@ -91,8 +91,9 @@ class NewDeckStats(QDialog):
extra = "#night"
else:
extra = ""
self.form.web.hide_while_preserving_layout()
self.form.web.load(QUrl(f"{self.mw.serverURL()}_anki/graphs.html" + extra))
self.form.web.inject_dynamic_style_and_show()
class DeckStats(QDialog):
"""Legacy deck stats, used by some add-ons."""

View file

@ -587,3 +587,19 @@ body {{ zoom: {zoom}; background: {background}; direction: {lang_dir}; {font} }}
aqt.reviewer.Reviewer or aqt.deckbrowser.DeckBrowser."""
self.onBridgeCmd = func
self._bridge_context = context
def hide_while_preserving_layout(self):
"Hide but keep existing size."
sp = self.sizePolicy()
sp.setRetainSizeWhenHidden(True)
self.setSizePolicy(sp)
self.hide()
def inject_dynamic_style_and_show(self):
"Add dynamic styling, and reveal."
css = self.standard_css()
self.evalWithCallback(f"""
const style = document.createElement('style');
style.innerHTML = `{css}`;
document.head.appendChild(style);
""", lambda arg: self.show())