def update_contents_of_sidebar(self): if not self.shown: return txt = "" card = self.mw.reviewer.card if card: if gc('show total cards studied today'): cutoff = (mw.col.sched.dayCutoff - 86400) * 1000 sqlstring = f"select count(id) from revlog where id > {cutoff}" total_today = mw.col.db.first(sqlstring)[0] txt += f'<div style="font-size:85%; text-align:left;"><b>{total_today}</b> cards studied today.</div>' p = current_card_deck_properties(card) txt += "<h3>Current Card</h3>" if gc('try_to_show_origvmod_scheduler') and pointVersion() < 45: # txt += '<h4>Scheduler Comparison</h4>' txt += text_for_scheduler_comparison(card, p) txt += "<hr>" # txt += "<h4>Deck Options</h4>" if gc('deck_options', "brief") == "brief": txt += text_for_short_options(card, p) txt += "<hr>" if gc('show_deck_names', True): txt += deck_name_and_source_for_filtered(card, p) if gc('deck_options', "brief") == "long": txt += long_deck_options(card, p) if gc('card_stats') == "detailed": txt += card_stats_as_in_browser(card, p) elif gc('card_stats') == "brief_with_ord": txt += mini_card_stats_with_ord(card, p, True) else: txt += mini_card_stats(card, p, True) txt += "<p>" txt += revlog_data_mod(self, card, gc('num_of_revs', 3)) try: lc = self.mw.reviewer.lastCard() except: lc = None if lc: txt += "<hr>" txt += "<h3>Last Card</h3>" if gc('show_detailed_card_stats_for_current_card'): txt += self.mw.col.cardStats(lc) else: lp = current_card_deck_properties(lc) txt += mini_card_stats(lc, lp, False) txt += "<p>" txt += revlog_data_mod(self, lc, gc('num_of_revs', 3)) if mw.state != 'review': txt = "No Card" if self.night_mode_on: style = sidebar_style("styling_dark.css") else: style = sidebar_style("styling.css") self.web.setHtml(""" <html> <head> <style> %s </style> </head> <body> <center> %s </center> </body> </html>""" % (style, txt))
from aqt import mw def gc(arg, fail=False): conf = mw.addonManager.getConfig(__name__.split(".")[0]) if conf: return conf.get(arg, fail) else: return fail pycmd_card = gc("prefix_cid") # "card_in_extra_window" pycmd_nid = gc("prefix_nid") # "note_in_extra_window" from anki.utils import pointVersion if pointVersion() <= 49: my_point_version = pointVersion else: from anki.utils import point_version my_point_version = point_version
sidebar_margin = config.get("sidebar_margin", None) if not sidebar_margin: return style = f"QTreeView::item {{margin: -{sidebar_margin}px;}}" self.sidebarTree.setStyleSheet(style) Browser.setupSidebar = wrap(Browser.setupSidebar, setupSidebar_wrapper) def updateFont_wrapper(self, *_): """Reduce row height in Browser table view""" reduce_row_height_by = config.get("reduce_row_height_by", None) if not reduce_row_height_by: return if pointVersion() < 45: vh = self.form.tableView.verticalHeader() else: vh = self._view.verticalHeader() original_height = vh.defaultSectionSize() new_height = original_height - reduce_row_height_by vh.setMinimumSectionSize(new_height) vh.setDefaultSectionSize(new_height) if pointVersion() < 45: Browser.updateFont = wrap(Browser.updateFont, updateFont_wrapper, "after") else: from aqt.browser.table import Table Table._setup_view = wrap(Table._setup_view, updateFont_wrapper, "after")
import os import random from anki.utils import pointVersion from aqt import mw from aqt import gui_hooks from .config import addon_path, addonfoldername, gc css_folder_for_anki_version = { "22": "22", "23": "22", # example: for Anki version 23 use the contents of the folder 22 } v = pointVersion() if v in css_folder_for_anki_version: version_folder = css_folder_for_anki_version[v] else: # for newer Anki versions try the latest version and hope for the best version_folder = css_folder_for_anki_version[max( css_folder_for_anki_version, key=int)] source_absolute = os.path.join(addon_path, "sources", "css", version_folder) web_absolute = os.path.join(addon_path, "web", "css") regex = r"(user_files.*|web.*)" mw.addonManager.setWebExports(__name__, regex) # on startup: combine template files with config and write into webexports folder change_copy = [ os.path.basename(f) for f in os.listdir(source_absolute)
def maybe_adjust_filename_for_2136(filename): if pointVersion() >= 36: filename = filename.lstrip("css/") return filename
def timespan(t): """for change from https://github.com/ankitects/anki/commit/89dde3aeb0c1f94b912b3cb2659ec0d4bffb4a1c""" if pointVersion() < 28: return mw.col.backend.format_time_span(t) else: return mw.col.format_timespan(t)