#// auth_ Mohamad Janati #// Copyright (c) 2019-2021 Mohamad Janati (freaking stupid, right? :|) import json from aqt import mw import aqt from aqt.qt import * from aqt.utils import downArrow, shortcut, showInfo from aqt.reviewer import Reviewer from anki.hooks import wrap from . import Card_Info from . import styles from .Skip import test from .Skip import burySkipped from .Skip import try_unburySkipped #// getting config information config = mw.addonManager.getConfig(__name__) speedFocus_addOn = config[' Speed Focus Add-on'] bottombarButtons_style = config[' Review_ Bottombar Buttons Style'] skipMethod = config[' Skip Method'] skip = config['Button_ Skip Button'] showSkipped = config['Button_ Show Skipped Button'] info = config['Button_ Info Button'] undo = config['Button_ Undo Button'] skip_shortcut = config ['Button_ Shortcut_ Skip Button'].lower() showSkipped_shortcut = config ['Button_ Shortcut_ Show Skipped Button'].lower() info_shortcut = config['Button_ Shortcut_ Info Button'].lower() undo_shortcut = config['Button_ Shortcut_ Undo Button'].lower() info_position = config['Button_ Position_ Info Button'].lower() skip_position = config['Button_ Position_ Skip Button'].lower() showSkipped_position = config['Button_ Position_ Show Skipped Button'].lower() undo_position = config['Button_ Position_ Undo Button'].lower() edit_label = config['Button Label_ Edit'] showAnswer_label = config['Button Label_ Show Answer'] more_label = config['Button Label_ More'] info_label = config['Button Label_ Info'] skip_label = config['Button Label_ Skip'] showSkipped_label = config['Button Label_ Show Skipped'] undo_label = config['Button Label_ Undo'] custom_buttonSize = config ['Button_ Custom Button Sizes'] buttons_height = config['Button_ Height_ All Bottombar Buttons'] answer_width = config['Button_ Width_ Show Answer Button'] text_size = config['Button_ Text Size'] custom_bottombarButtonBorderColor = config['Color_ Custom Bottombar Button Border Color'] bottombarButtonBorder_color = config['Color_ Bottombar Button Border Color'] showAnswerBorderColor_style = config['ShowAnswer_ Border Color Style'] showAnswerEase1 = config['ShowAnswer_ Ease1'] showAnswerEase2 = config['ShowAnswer_ Ease2'] showAnswerEase3 = config['ShowAnswer_ Ease3'] showAnswerEase4 = config['ShowAnswer_ Ease4'] showAnswerEase1_color = config['ShowAnswer_ Ease1 Color'] showAnswerEase2_color = config['ShowAnswer_ Ease2 Color'] showAnswerEase3_color = config['ShowAnswer_ Ease3 Color'] showAnswerEase4_color = config['ShowAnswer_ Ease4 Color'] # TODO: set the showSkipped styling and stuff edit_style = styles.edit_style info_style = styles.info_style skip_style = styles.skip_style showSkipped_style = styles.showSkipped_style undo_style = styles.undo_style more_style = styles.more_style min_buttonSize = styles.min_buttonSize bottombar_neon1 = styles.bottombar_neon1 bottombar_neon2 = styles.bottombar_neon2 bottombar_fill1 = styles.bottombar_fill1 bottombar_fill2 = styles.bottombar_fill2 #// adding shortcuts to _shortcutKeys function in anki def _shortcutKeys_wrap(self, _old): original = _old(self) sched_ver = mw.col.sched.version if sched_ver > 2 or skipMethod == 1: original.append((skip_shortcut, lambda: burySkipped())) original.append((showSkipped_shortcut, lambda: try_unburySkipped())) else: original.append((skip_shortcut, lambda: self.nextCard())) original.extend([ (info_shortcut, lambda: Card_Info._cs.toggle()), (undo_shortcut, lambda: mw.onUndo()) ]) return original #// adding button links to link handler function def linkHandler_wrap(reviewer, url): sched_ver = mw.col.sched.version if url == "card_info": Card_Info._cs.toggle() elif url == "skip": if sched_ver > 2 or skipMethod == 1: burySkipped() else: reviewer.nextCard() elif url == "showSkipped": if sched_ver > 2 or skipMethod == 1: try_unburySkipped() else: showInfo("Your skip method is not \"Bury\" Hence you don't have any skipped cards that can be shown using this button.") elif url == "undo": mw.onUndo() else: Review_linkHandelr_Original(reviewer, url) Review_linkHandelr_Original = Reviewer._linkHandler Reviewer._linkHandler = linkHandler_wrap #// 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 #// info button | written in a separate functions to preserve the original bottombar def info_button(): if info: return """""".format(info_shortcut.upper(), info_style, info_label) else: return "" #// skip button | written in a separate functions to preserve the original bottombar def skip_button(): if skip: return """""".format(skip_shortcut.upper(), skip_style, skip_label) else: return "" #// Show Skipped button def showSkipped_button(): if showSkipped: return """""".format(showSkipped_shortcut.upper(), showSkipped_style, showSkipped_label) else: return "" #// undo button def undo_button(): if undo: return """""".format(undo_shortcut, undo_style, undo_label) else: return "" #// Button Positions leftSide_button1 = "" leftSide_button2 = "" leftSide_button3 = "" leftSide_button4 = "" middleLeftSide_button1 = "" middleLeftSide_button2 = "" middleLeftSide_button3 = "" middleLeftSide_button4 = "" middleRightSide_button1 = "" middleRightSide_button2 = "" middleRightSide_button3 = "" middleRightSide_button4 = "" rightSide_button1 = "" rightSide_button2 = "" rightSide_button3 = "" rightSide_button4 = "" if info_position == "right": rightSide_button1 = info_button() elif info_position == "middle left": middleLeftSide_button1 = info_button() elif info_position == "middle right": middleRightSide_button1 = info_button() else: leftSide_button1 = info_button() if skip_position == "left": leftSide_button2 = skip_button() elif skip_position == "middle right": middleRightSide_button2 = skip_button() elif skip_position == "right": rightSide_button2 = skip_button() else: middleLeftSide_button2 = skip_button() if showSkipped_position == "left": leftSide_button3 = showSkipped_button() elif showSkipped_position == "middle right": middleRightSide_button3 = showSkipped_button() elif showSkipped_position == "right": rightSide_button3 = showSkipped_button() else: middleLeftSide_button3 = showSkipped_button() if undo_position == "left": leftSide_button4 = undo_button() elif undo_position == "middle right": middleRightSide_button4 = undo_button() elif undo_position == "right": rightSide_button4 = undo_button() else: middleLeftSide_button4 = undo_button() #// Speed focus remove conflicts if speedFocus_addOn: SF_bottomHTML = """ var autoAnswerTimeout = 0; var autoAgainTimeout = 0; var autoAlertTimeout = 0; var setAutoAnswer = function(ms) { clearTimeout(autoAnswerTimeout); autoAnswerTimeout = setTimeout(function () { pycmd('ans') }, ms); } var setAutoAgain = function(ms) { clearTimeout(autoAgainTimeout); autoAgainTimeout = setTimeout(function () { pycmd("ease1"); }, ms); } var setAutoAlert = function(ms) { clearTimeout(autoAlertTimeout); autoAlertTimeout = setTimeout(function () { pycmd("autoalert"); }, ms); }""" else: SF_bottomHTML = "" #// setting buttons based on their position if leftSide_button1 != "": left_side1 = "
|
%(left_side1)s
%(left_side2)s
%(left_side3)s
%(left_side4)s
%(right_side1)s %(right_side2)s %(right_side3)s %(right_side4)s |
|
%(remaining)s %(middleLeft_side1)s %(middleLeft_side2)s %(middleLeft_side3)s %(middleLeft_side4)s %(middleRight_side1)s %(middleRight_side2)s %(middleRight_side3)s %(middleRight_side4)s |