mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
plug new graphs code into GUI
Still some work to do. Feedback welcome!
This commit is contained in:
parent
d4cd4535e6
commit
52cd9fc4b8
2 changed files with 27 additions and 29 deletions
|
@ -2,12 +2,13 @@
|
||||||
# -*- 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
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.theme import theme_manager
|
|
||||||
from aqt.utils import (
|
from aqt.utils import (
|
||||||
addCloseShortcut,
|
addCloseShortcut,
|
||||||
getSaveFile,
|
getSaveFile,
|
||||||
|
@ -22,7 +23,7 @@ from aqt.utils import (
|
||||||
|
|
||||||
|
|
||||||
class DeckStats(QDialog):
|
class DeckStats(QDialog):
|
||||||
def __init__(self, mw):
|
def __init__(self, mw: aqt.main.AnkiQt):
|
||||||
QDialog.__init__(self, mw, Qt.Window)
|
QDialog.__init__(self, mw, Qt.Window)
|
||||||
mw.setupDialogGC(self)
|
mw.setupDialogGC(self)
|
||||||
self.mw = mw
|
self.mw = mw
|
||||||
|
@ -33,23 +34,15 @@ class DeckStats(QDialog):
|
||||||
self.wholeCollection = False
|
self.wholeCollection = False
|
||||||
self.setMinimumWidth(700)
|
self.setMinimumWidth(700)
|
||||||
f = self.form
|
f = self.form
|
||||||
if theme_manager.night_mode and not theme_manager.macos_dark_mode():
|
|
||||||
# the grouping box renders incorrectly in the fusion theme. 5.9+
|
|
||||||
# 5.13 behave differently to 5.14, but it looks bad in either case,
|
|
||||||
# and adjusting the top margin makes the 'save PDF' button show in
|
|
||||||
# the wrong place, so for now we just disable the border instead
|
|
||||||
self.setStyleSheet("QGroupBox { border: 0; }")
|
|
||||||
f.setupUi(self)
|
f.setupUi(self)
|
||||||
|
# no night mode support yet
|
||||||
|
f.web._page.setBackgroundColor(QColor("white"))
|
||||||
|
f.groupBox.setVisible(False)
|
||||||
|
f.groupBox_2.setVisible(False)
|
||||||
restoreGeom(self, self.name)
|
restoreGeom(self, self.name)
|
||||||
b = f.buttonBox.addButton(_("Save PDF"), QDialogButtonBox.ActionRole)
|
b = f.buttonBox.addButton(_("Save PDF"), QDialogButtonBox.ActionRole)
|
||||||
qconnect(b.clicked, self.saveImage)
|
qconnect(b.clicked, self.saveImage)
|
||||||
b.setAutoDefault(False)
|
b.setAutoDefault(False)
|
||||||
qconnect(f.groups.clicked, lambda: self.changeScope("deck"))
|
|
||||||
f.groups.setShortcut("g")
|
|
||||||
qconnect(f.all.clicked, lambda: self.changeScope("collection"))
|
|
||||||
qconnect(f.month.clicked, lambda: self.changePeriod(0))
|
|
||||||
qconnect(f.year.clicked, lambda: self.changePeriod(1))
|
|
||||||
qconnect(f.life.clicked, lambda: self.changePeriod(2))
|
|
||||||
maybeHideClose(self.form.buttonBox)
|
maybeHideClose(self.form.buttonBox)
|
||||||
addCloseShortcut(self)
|
addCloseShortcut(self)
|
||||||
self.show()
|
self.show()
|
||||||
|
@ -87,22 +80,11 @@ class DeckStats(QDialog):
|
||||||
tooltip(_("Saved."))
|
tooltip(_("Saved."))
|
||||||
|
|
||||||
def changePeriod(self, n):
|
def changePeriod(self, n):
|
||||||
self.period = n
|
pass
|
||||||
self.refresh()
|
|
||||||
|
|
||||||
def changeScope(self, type):
|
def changeScope(self, type):
|
||||||
self.wholeCollection = type == "collection"
|
pass
|
||||||
self.refresh()
|
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
self.mw.progress.start(parent=self)
|
self.form.web.set_open_links_externally(False)
|
||||||
stats = self.mw.col.stats()
|
self.form.web.load(QUrl(f"{self.mw.serverURL()}_anki/graphs.html"))
|
||||||
stats.wholeCollection = self.wholeCollection
|
|
||||||
self.report = stats.report(type=self.period)
|
|
||||||
self.form.web.title = "deck stats"
|
|
||||||
self.form.web.stdHtml(
|
|
||||||
"<html><body>" + self.report + "</body></html>",
|
|
||||||
js=["jquery.js", "plot.js"],
|
|
||||||
context=self,
|
|
||||||
)
|
|
||||||
self.mw.progress.finish()
|
|
||||||
|
|
|
@ -135,8 +135,24 @@
|
||||||
<property name="standardButtons">
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Close</set>
|
<set>QDialogButtonBox::Close</set>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="centerButtons">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|
Loading…
Reference in a new issue