import time
from datetime import date, timedelta
from aqt import mw
from copy import deepcopy
from aqt.utils import shortcut, showInfo, tr
from anki import version
anki_version = int(version.replace('.', ''))
if anki_version > 2119:
from aqt.deckbrowser import DeckBrowserBottomBar
from aqt.overview import OverviewBottomBar
from aqt.deckbrowser import DeckBrowser
from aqt.overview import Overview
from . import styles
config = mw.addonManager.getConfig(__name__)
studyNow_label = config['Button Label_ Study Now']
more_overviewStats = config[' More Overview Stats']
bottombarButtons_style = config[' Review_ Bottombar Buttons Style']
style_mainScreenButtons = config[' Style Main Screen Buttons']
bottombar_neon1 = styles.bottombar_neon1
bottombar_neon2 = styles.bottombar_neon2
bottombar_fill1 = styles.bottombar_fill1
bottombar_fill2 = styles.bottombar_fill2
#// Chosing stylinhg for review other buttons in reviewer bottombar based on chosen style
if bottombarButtons_style == 0:
bottomHTML_style = ""
elif bottombarButtons_style == 1:
bottomHTML_style = bottombar_neon1
elif bottombarButtons_style == 2:
bottomHTML_style = bottombar_neon2
elif bottombarButtons_style == 3:
bottomHTML_style = bottombar_fill1
elif bottombarButtons_style == 4:
bottomHTML_style = bottombar_fill2
#// Main Screen Bottombar Buttons
def _drawButtons(self):
buf = "{}".format(bottomHTML_style)
if style_mainScreenButtons:
#// style='height: px' -> to prevent changing main screen buttons heights
# based on height defined in #main {}
mainScreen_style = """id=main style='height: px' """
else:
mainScreen_style = ""
drawLinks = deepcopy(self.drawLinks)
for b in drawLinks:
b.insert(0, "{}".format(mainScreen_style))
if b[0]:
b[0] = ("Shortcut key: %s") % shortcut(b[0])
buf += """
""" % (tuple(b))
if anki_version > 2121:
self.bottom.draw(
buf=buf,
link_handler=self._linkHandler,
web_context=DeckBrowserBottomBar(self),
)
else:
self.bottom.draw(buf)
self.bottom.web.onBridgeCmd = self._linkHandler
#// Deck Overview Bottombar Buttons
def _renderBottom(self):
links = [
["O", "opts", tr.actions_options()],
]
if self.mw.col.decks.current()["dyn"]:
links.append(["R", "refresh", tr.actions_rebuild()])
links.append(["E", "empty", tr.studying_empty()])
else:
links.append(["C", "studymore", tr.actions_custom_study()])
# links.append(["F", "cram", ("Filter/Cram")])
if self.mw.col.sched.haveBuried():
links.append(["U", "unbury", tr.studying_unbury()])
links.append(["", "description", tr.scheduling_description()])
buf = "{}".format(bottomHTML_style)
if style_mainScreenButtons:
#// style='height: px' -> to prevent changing main screen buttons heights
# based on height defined in #main {}
mainScreen_style = """id=main style='height: px' """
else:
mainScreen_style = ""
for b in links:
b.insert(0, "{}".format(mainScreen_style))
if b[0]:
b[0] = ("Shortcut key: %s") % shortcut(b[0])
buf += """
""" % tuple(b)
if anki_version > 2121:
self.bottom.draw(
buf=buf,
link_handler=self._linkHandler,
web_context=OverviewBottomBar(self)
)
else:
self.bottom.draw(buf)
self.bottom.web.onBridgeCmd = self._linkHandler
#// Deck Overview Study Now Button | code from more overview stats to add more overview stats, OBVIOUSLY
if more_overviewStats == 1:
def _table(self):
"""Returns html table with more statistics than before."""
sched = self.mw.col.sched
deck = self.mw.col.decks.current()
dconf = self.mw.col.decks.confForDid(deck.get('id'))
but = self.mw.button
# Get default counts
# 0 = new, 1 = learn, 2 = review
counts = list(sched.counts())
finished = not sum(counts)
counts = _limit(counts)
totals = [
#new
sched.col.db.scalar("""
select count() from (select id from cards where did = %s
and queue = 0)""" % deck.get('id')),
# learn
sched.col.db.scalar("""
select count() from (select id from cards where did = %s
and queue in (1,3))""" % deck.get('id')),
# review
sched.col.db.scalar("""
select count() from (select id from cards where did = %s
and queue = 2)""" % deck.get('id')),
# suspended
sched.col.db.scalar("""
select count() from (select id from cards where did = %s
and queue = -1)""" % deck.get('id')),
# buried
sched.col.db.scalar("""
select count() from (select id from cards where did = %s
and queue = -2)""" % deck.get('id')),
]
if (dconf.get('new')):
dueTomorrow = _limit([
# new
min(dconf.get('new').get('perDay'), totals[0]),
# review
sched.col.db.scalar("""
select count() from cards where did = %s and queue = 3
and due = ?""" % deck.get('id'), sched.today + 1),
sched.col.db.scalar("""
select count() from cards where did = %s and queue = 2
and due = ?""" % deck.get('id'), sched.today + 1)
])
html = ''
# Style if less than 2.1.20
if (int(version.replace('.', '')) < 2120):
html += '''
'''
# No need to show due if we have finished collection today
if finished:
mssg = sched.finishedMsg()
html += '''
%s
''' % mssg
else:
html +='''%s
%s:
%s%s%s
''' % (bottomHTML_style, tr.browsing_sidebar_due_today(), counts[0], counts[1], counts[2])
if (dconf.get('new')):
html += '''
%s:
%s%s%s
''' % (tr.statistics_due_tomorrow(), dueTomorrow[0],
dueTomorrow[1], dueTomorrow[2])
html += '''
%s:
%s%s%s%s%s
''' % (tr.statistics_counts_total_cards(), totals[0], totals[1], totals[2], totals[4],
totals[3])
if not finished:
if style_mainScreenButtons:
#// style='height: px' -> to prevent changing main screen buttons heights
# based on height defined in #main {}
mainScreen_style = """id=main style='height: px' """
else:
mainScreen_style = ""
if style_mainScreenButtons:
studyButton_id = "main"
else:
studyButton_id = "study"
html += '''
%s
''' % (but("study", ("{}".format(studyNow_label)), id="{}".format(studyButton_id), extra="autofocus"))
return html
elif more_overviewStats == 2:
def _table(self):
stat_colors = {
"New" : "#00a",
"Learning" : "#a00",
"Review" : "#080",
"Percent" : "#888",
"Mature" : "#0051ff",
"Young" : "#0051ff",
"Learned" : "#080",
"Unseen" : "#a00",
"Suspended" : "#e7a100",
"Done on Date" : "#ddd",
"Days until done" : "#ddd",
"Total" : "#ddd",
}
date_format = "%d.%m.%Y"
correction_for_notes = 1
last_match_length = 0
current_deck_name = self.mw.col.decks.current()['name']
date_format = "%m/%d/%Y"
try:
learn_per_day = self.mw.col.decks.confForDid(self.mw.col.decks.current()['id'])['new']['perDay']
except:
learn_per_day = 0
total, mature, young, unseen, suspended, due = self.mw.col.db.first(
u'''
select
-- total
count(id),
-- mature
sum(case when queue = 2 and ivl >= 21
then 1 else 0 end),
-- young / learning
sum(case when queue in (1, 3) or (queue = 2 and ivl < 21)
then 1 else 0 end),
-- unseen
sum(case when queue = 0
then 1 else 0 end),
-- suspended
sum(case when queue < 0
then 1 else 0 end),
-- due
sum(case when queue = 1 and due <= ?
then 1 else 0 end)
from cards where did in {:s}
'''.format(self.mw.col.sched._deckLimit()), round(time.time())
)
if not total:
return u'
'''.format(label=labels, cards=cards, percent=cards_percent, percent2=cards_percent_without_suspended)
output = ''
if deck_is_finished:
if (config == None or not 'options' in config) or (config['options'].get('Show table for finished decks', True)):
output += output_table
output += u'''
'''
output += u'''
{:s}
'''.format(self.mw.col.sched.finishedMsg())
else:
if style_mainScreenButtons:
#// style='height: px' -> to prevent changing main screen buttons heights
# based on height defined in #main {}
mainScreen_style = """id=main style='height: px' """
else:
mainScreen_style = ""
if style_mainScreenButtons:
studyButton_id = "main"
else:
studyButton_id = "study"
output += output_table
output += bottomHTML_style
output += u'''
{button:s}
'''.format(button=button('study', tr.studying_study_now(), id='{}'.format(studyButton_id), extra="autofocus"))
return output
else:
def _table(self):
counts = list(self.mw.col.sched.counts())
finished = not sum(counts)
if self.mw.col.sched_ver() == 1:
for n in range(len(counts)):
if counts[n] >= 1000:
counts[n] = "1000+"
but = self.mw.button
if finished:
return '
%s
' % (
self.mw.col.sched.finishedMsg()
)
else:
if style_mainScreenButtons:
#// style='height: px' -> to prevent changing main screen buttons heights
# based on height defined in #main {}
mainScreen_style = """id=main style='height: px' """
else:
mainScreen_style = ""
if style_mainScreenButtons:
studyButton_id = "main"
else:
studyButton_id = "study"
return """%s
%s:
%s
%s:
%s
%s:
%s
%s
""" % (
bottomHTML_style,
tr.actions_new(),
counts[0],
tr.scheduling_learning(),
counts[1],
tr.studying_to_review(),
counts[2],
but("study", tr.studying_study_now(), id="{}".format(studyButton_id), extra="autofocus"),
)
def _limit(counts):
for i, count in enumerate(counts):
if count >= 1000:
counts[i] = "1000+"
return counts
Overview._renderBottom = _renderBottom
DeckBrowser._drawButtons = _drawButtons
Overview._table = _table