mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32: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 -*-
|
||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
|
||||
import aqt
|
||||
from anki.lang import _
|
||||
from aqt.qt import *
|
||||
from aqt.theme import theme_manager
|
||||
from aqt.utils import (
|
||||
addCloseShortcut,
|
||||
getSaveFile,
|
||||
|
@ -22,7 +23,7 @@ from aqt.utils import (
|
|||
|
||||
|
||||
class DeckStats(QDialog):
|
||||
def __init__(self, mw):
|
||||
def __init__(self, mw: aqt.main.AnkiQt):
|
||||
QDialog.__init__(self, mw, Qt.Window)
|
||||
mw.setupDialogGC(self)
|
||||
self.mw = mw
|
||||
|
@ -33,23 +34,15 @@ class DeckStats(QDialog):
|
|||
self.wholeCollection = False
|
||||
self.setMinimumWidth(700)
|
||||
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)
|
||||
# no night mode support yet
|
||||
f.web._page.setBackgroundColor(QColor("white"))
|
||||
f.groupBox.setVisible(False)
|
||||
f.groupBox_2.setVisible(False)
|
||||
restoreGeom(self, self.name)
|
||||
b = f.buttonBox.addButton(_("Save PDF"), QDialogButtonBox.ActionRole)
|
||||
qconnect(b.clicked, self.saveImage)
|
||||
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)
|
||||
addCloseShortcut(self)
|
||||
self.show()
|
||||
|
@ -87,22 +80,11 @@ class DeckStats(QDialog):
|
|||
tooltip(_("Saved."))
|
||||
|
||||
def changePeriod(self, n):
|
||||
self.period = n
|
||||
self.refresh()
|
||||
pass
|
||||
|
||||
def changeScope(self, type):
|
||||
self.wholeCollection = type == "collection"
|
||||
self.refresh()
|
||||
pass
|
||||
|
||||
def refresh(self):
|
||||
self.mw.progress.start(parent=self)
|
||||
stats = self.mw.col.stats()
|
||||
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()
|
||||
self.form.web.set_open_links_externally(False)
|
||||
self.form.web.load(QUrl(f"{self.mw.serverURL()}_anki/graphs.html"))
|
||||
|
|
|
@ -135,8 +135,24 @@
|
|||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
Loading…
Reference in a new issue