# -*- coding: utf-8 -*- # Copyright (c) 2020 Lovac42 # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html from anki import version ANKI20 = version.startswith("2.0.") CCBC = version.endswith("ccbc") ANKI21 = not CCBC and version.startswith("2.1.") VERSION = version.split('_')[0] #rm ccbc m,n,p = VERSION.split('.') MAJOR_VERSION = int(m) MINOR_VERSION = int(n) PATCH_VERSION = int(p) POINT_VERSION = 0 if ANKI20 else PATCH_VERSION
from aqt import mw def gc(arg, fail=False): try: out = mw.addonManager.getConfig(__name__).get(arg, fail) except: return None else: return out from anki import version as anki_version _, _, point = anki_version.split(".") pointversion = int(point)
os.path.basename(f) for f in os.listdir(source_absolute) if f.endswith(".css") ]: with open(os.path.join(source_absolute, f)) as FO: filecontent = FO.read() for val in gc(): if val in filecontent: newval = gc(val) if not newval: newval = dc(val) filecontent = filecontent.replace(val, str(newval)) with open(os.path.join(web_absolute, f), "w") as FO: FO.write(filecontent) css_files_to_replace = [ os.path.basename(f) for f in os.listdir(web_absolute) if f.endswith(".css") ] def replace_css(web_content, context): for idx, filename in enumerate(web_content.css): if filename in css_files_to_replace: web_content.css[ idx] = f"/_addons/{addonfoldername}/web/css/{version_folder}/{filename}" old_anki = tuple(int(i) for i in anki_version.split(".")) < (2, 1, 22) if not old_anki and gc("editor_shrink"): gui_hooks.webview_will_set_content.append(replace_css)
from anki import version as ankiversion from anki.hooks import addHook, wrap from anki import hooks from anki.utils import htmlToTextLine from aqt import mw from aqt.editor import Editor from aqt.qt import QClipboard from aqt.reviewer import Reviewer from aqt.utils import showText, tooltip from .semieditor import semiEditorWebView config = mw.addonManager.getConfig(__name__) ankiver_minor = int(ankiversion.split('.')[2]) ankiver_major = ankiversion[0:3] # Get js files. def js_from_path(path): return "<script>" + path.read_text() + "</script>" def css_from_path(path): return "<style>" + path.read_text() + "</style>" DIRPATH = Path(__file__).parents[0] CARDJS = js_from_path(DIRPATH / "card.js") GLOBALCARDJS = js_from_path(DIRPATH / "global_card.js") RESIZEJS = js_from_path(DIRPATH / "resize.js")
def answerCard_before(self, ease) : # get the ease which was selected answerButtons = self._answerButtonList() cB = [item for item in answerButtons if item[0] == ease] #cB: clickedButtons, should always be just one # load the display time time = getUserOption("confirmation time") # determine the position for the label #idk why the +7 offset is needed, but only this brings exact values if getUserOption("button width") == "S": x1 = -125 + 7 + getUserOption("confirmation x-offset") x2 = -50 + 7 + getUserOption("confirmation x-offset") x3 = 25 + 7 + getUserOption("confirmation x-offset") x4 = 100 + 7 + getUserOption("confirmation x-offset") width = 62 elif getUserOption("button width") == "M": x1 = -162 + 7 + getUserOption("confirmation x-offset") x2 = -65.33 + 7 + getUserOption("confirmation x-offset") x3 = 31.33 + 7 + getUserOption("confirmation x-offset") x4 = 128 + 7 + getUserOption("confirmation x-offset") width = 87 elif getUserOption("button width") == "L": x1 = -224 + 7 + getUserOption("confirmation x-offset") x2 = -88.66 + 7 + getUserOption("confirmation x-offset") x3 = 46.66 + 7 + getUserOption("confirmation x-offset") x4 = 182 + 7 + getUserOption("confirmation x-offset") width = 125 if getUserOption("button height") == "S": height = 26 y = -36 - getUserOption("confirmation y-offset") elif getUserOption("button height") == "M": height = 41 y = -51 - getUserOption("confirmation y-offset") elif getUserOption("button height") == "L": height = 61 y = -71 - getUserOption("confirmation y-offset") aw = aqt.mw.app.activeWindow() or aqt.mw xref = 0 # apply values x1 = aw.mapToGlobal(QPoint(x1+int(round(aw.width()/2, 0)), 0)).x() x2 = aw.mapToGlobal(QPoint(x2+int(round(aw.width()/2, 0)), 0)).x() x3 = aw.mapToGlobal(QPoint(x3+int(round(aw.width()/2, 0)), 0)).x() x4 = aw.mapToGlobal(QPoint(x4+int(round(aw.width()/2, 0)), 0)).x() xref = 1 y = aw.mapToGlobal(QPoint(0, y+aw.height())).y() if (x1 < 0): x1 = 0 if (y < 0): y = 0 # Nightmode from anki import version as anki_version old_anki = tuple(int(i) for i in anki_version.split(".")) < (2, 1, 20) if old_anki: class Object(): pass theme_manager = Object() theme_manager.night_mode = False else: from aqt.theme import theme_manager if theme_manager.night_mode: AgainColor = getUserOption("Nightmode_AgainColor") HardColor = getUserOption("Nightmode_HardColor") GoodColor = getUserOption("Nightmode_GoodColor") EasyColor = getUserOption("Nightmode_EasyColor") else: AgainColor = getUserOption("AgainColor") HardColor = getUserOption("HardColor") GoodColor = getUserOption("GoodColor") EasyColor = getUserOption("EasyColor") #set font size options if getUserOption("button font size") == "S": FONTSIZE = "" elif getUserOption("button font size") == "M": FONTSIZE = "font-size: 16px;" elif getUserOption("button font size") == "L": FONTSIZE = "font-size: 20px;" # show tooltip in according color if len(cB) > 0 : # display the tooltip in an according color if (cB[0][1]=="Again" or "Again" in cB[0][1]): utils.tooltipWithColour(("<div style='color:#3a3a3a;%s'>Again</div>" % (FONTSIZE)), AgainColor, x=x1, y=y, xref=xref, period=time, width=width, height=height) elif (cB[0][1]=="Hard" or "Hard" in cB[0][1]): utils.tooltipWithColour(("<div style='color:#3a3a3a;%s'>Hard</div>" % (FONTSIZE)), HardColor, x=x2, y=y, xref=xref, period=time, width=width, height=height) elif (cB[0][1]=="Good" or "Good" in cB[0][1]): utils.tooltipWithColour(("<div style='color:#3a3a3a;%s'>Good</div>" % (FONTSIZE)), GoodColor, x=x3, y=y, xref=xref, period=time, width=width, height=height) elif (cB[0][1]=="Easy" or "Easy" in cB[0][1]): utils.tooltipWithColour(("<div style='color:#3a3a3a;%s'>Easy</div>" % (FONTSIZE)), EasyColor, x=x4, y=y, xref=xref, period=time, width=width, height=height) else: # default behavior for unforeseen cases tooltip(cB[0][1])
from anki import version as ankiversion from anki.hooks import addHook, wrap from anki.utils import htmlToTextLine from aqt import mw from aqt.editor import Editor from aqt.qt import QClipboard from aqt.reviewer import Reviewer from aqt.utils import showText, tooltip from .semieditor import semiEditorWebView from .config import config_make_valid ERROR_MSG = "ERROR - Edit Field During Review Cloze\n{}" config = mw.addonManager.getConfig(__name__) ankiver_minor = int(ankiversion.split(".")[2]) ankiver_major = ankiversion[0:3] editorwv = semiEditorWebView() # Get js files. def js_from_path(path): return "<script>" + path.read_text() + "</script>" def css_from_path(path): return "<style>" + path.read_text() + "</style>" DIRPATH = Path(__file__).parents[0]