def setupTopArea(self): self.topArea = QWidget() self.topAreaForm = aqt.forms.clayout_top.Ui_Form() self.topAreaForm.setupUi(self.topArea) self.topAreaForm.templateOptions.setText(_("Options") + " "+downArrow()) self.topAreaForm.templateOptions.clicked.connect(self.onMore) self.topAreaForm.templatesBox.currentIndexChanged.connect(self.onCardSelected)
def _bottomHTML(self): return """ <center id=outer> <table id=innertable width=100%% cellspacing=0 cellpadding=0> <tr> <td align=left width=50 valign=top class=stat> <br> <button title="%(editkey)s" onclick="pycmd('edit');">%(edit)s</button></td> <td align=center valign=top id=middle> </td> <td width=50 align=right valign=top class=stat><span id=time class=stattxt> </span><br> <button onclick="pycmd('more');">%(more)s %(downArrow)s</button> </td> </tr> </table> </center> <script> time = %(time)d; </script> """ % dict(rem=self._remaining(), edit=_("Edit"), editkey=_("Shortcut key: %s") % "E", more=_("More"), downArrow=downArrow(), time=self.card.timeTaken() // 1000)
def __init__(self, mw, deck): QDialog.__init__(self, mw) self.mw = mw self.deck = deck self.childDids = [ d[1] for d in self.mw.col.decks.children(self.deck['id'])] self._origNewOrder = None self.form = aqt.forms.dconf.Ui_Dialog() self.form.setupUi(self) self.mw.checkpoint(_("Options")) self.setupCombos() self.setupConfs() self.setWindowModality(Qt.WindowModal) self.connect(self.form.buttonBox, SIGNAL("helpRequested()"), lambda: openHelp("deckoptions")) self.connect(self.form.confOpts, SIGNAL("clicked()"), self.confOpts) self.form.confOpts.setText(downArrow()) self.connect(self.form.buttonBox.button(QDialogButtonBox.RestoreDefaults), SIGNAL("clicked()"), self.onRestore) self.setWindowTitle(_("Options for %s") % self.deck['name']) # qt doesn't size properly with altered fonts otherwise restoreGeom(self, "deckconf", adjustSize=True) self.show() self.exec_() saveGeom(self, "deckconf")
def setupButtons(self): l = self.buttons = QHBoxLayout() help = QPushButton(_("Help")) help.setAutoDefault(False) l.addWidget(help) help.clicked.connect(self.onHelp) l.addStretch() addField = QPushButton(_("Add Field")) addField.setAutoDefault(False) l.addWidget(addField) addField.clicked.connect(self.onAddField) if self.model['type'] != MODEL_CLOZE: flip = QPushButton(_("Flip")) flip.setAutoDefault(False) l.addWidget(flip) flip.clicked.connect(self.onFlip) more = QPushButton(_("More") + " "+downArrow()) more.setAutoDefault(False) l.addWidget(more) more.clicked.connect(lambda: self.onMore(more)) l.addStretch() close = QPushButton(_("Close")) close.setAutoDefault(False) l.addWidget(close) close.clicked.connect(self.accept)
def setupButtons(self): l = self.buttons = QHBoxLayout() help = QPushButton(_("Help")) help.setAutoDefault(False) l.addWidget(help) help.clicked.connect(self.onHelp) l.addStretch() addField = QPushButton(_("Add Field")) addField.setAutoDefault(False) l.addWidget(addField) addField.clicked.connect(self.onAddField) if self.model['type'] != MODEL_CLOZE: flip = QPushButton(_("Flip")) flip.setAutoDefault(False) l.addWidget(flip) flip.clicked.connect(self.onFlip) more = QPushButton(_("More") + " " + downArrow()) more.setAutoDefault(False) l.addWidget(more) more.clicked.connect(lambda: self.onMore(more)) l.addStretch() close = QPushButton(_("Close")) close.setAutoDefault(False) l.addWidget(close) close.clicked.connect(self.accept)
def mySetupButtons(self): but = self._addButton("symbolButton", lambda s=self: onAnkiSymbols(self), text=unichr(945) + unichr(946) + unichr(947) + downArrow(), size=False) but.setShortcut(QKeySequence("Ctrl+S"))
def _bottomHTML(self) -> str: return """ <center id=outer> <table id=innertable width=100%% cellspacing=0 cellpadding=0> <tr> <td align=left width=50 valign=top class=stat> <br> <button title="%(editkey)s" onclick="pycmd('edit');">%(edit)s</button></td> <td align=center valign=top id=middle> </td> <td width=50 align=right valign=top class=stat><span id=time class=stattxt> </span><br> <button onclick="pycmd('more');">%(more)s %(downArrow)s</button> </td> </tr> </table> </center> <script> time = %(time)d; </script> """ % dict( rem=self._remaining(), edit=tr.studying_edit(), editkey=tr.actions_shortcut_key(val="E"), more=tr.studying_more(), downArrow=downArrow(), time=self.card.time_taken() // 1000, )
def setupButtons(self) -> None: bb = self.form.buttonBox ar = QDialogButtonBox.ActionRole # add self.addButton = bb.addButton(tr(TR.ACTIONS_ADD), ar) qconnect(self.addButton.clicked, self.addCards) self.addButton.setShortcut(QKeySequence("Ctrl+Return")) self.addButton.setToolTip( shortcut(tr(TR.ADDING_ADD_SHORTCUT_CTRLANDENTER))) # close self.closeButton = QPushButton(tr(TR.ACTIONS_CLOSE)) self.closeButton.setAutoDefault(False) bb.addButton(self.closeButton, QDialogButtonBox.RejectRole) # help self.helpButton = QPushButton( tr(TR.ACTIONS_HELP), clicked=self.helpRequested) # type: ignore self.helpButton.setAutoDefault(False) bb.addButton(self.helpButton, QDialogButtonBox.HelpRole) # history b = bb.addButton(tr(TR.ADDING_HISTORY) + " " + downArrow(), ar) if isMac: sc = "Ctrl+Shift+H" else: sc = "Ctrl+H" b.setShortcut(QKeySequence(sc)) b.setToolTip(tr(TR.ADDING_SHORTCUT, val=shortcut(sc))) qconnect(b.clicked, self.onHistory) b.setEnabled(False) self.historyButton = b
def _bottomHTML(self) -> str: return """ <center id=outer> <table id=innertable width=100%% cellspacing=0 cellpadding=0> <tr> <td align=left width=50 valign=top class=stat> <br> <button title="%(editkey)s" onclick="pycmd('edit');">%(edit)s</button></td> <td align=center valign=top id=middle> </td> <td width=50 align=right valign=top class=stat><span id=time class=stattxt> </span><br> <button onclick="pycmd('more');">%(more)s %(downArrow)s</button> </td> </tr> </table> </center> <script> time = %(time)d; </script> """ % dict( rem=self._remaining(), edit=tr(TR.STUDYING_EDIT), editkey=tr(TR.ACTIONS_SHORTCUT_KEY, val="E"), more=tr(TR.STUDYING_MORE), downArrow=downArrow(), time=self.card.timeTaken() // 1000, )
def setupButtons(self): bb = self.form.buttonBox ar = QDialogButtonBox.ActionRole # add self.addButton = bb.addButton(_("Add"), ar) self.addButton.clicked.connect(self.addCards) self.addButton.setShortcut(QKeySequence("Ctrl+Return")) self.addButton.setToolTip(shortcut(_("Add (shortcut: ctrl+enter)"))) # close self.closeButton = QPushButton(_("Close")) self.closeButton.setAutoDefault(False) bb.addButton(self.closeButton, QDialogButtonBox.RejectRole) # help self.helpButton = QPushButton(_("Help"), clicked=self.helpRequested) self.helpButton.setAutoDefault(False) bb.addButton(self.helpButton, QDialogButtonBox.HelpRole) # history b = bb.addButton( _("History")+ " "+downArrow(), ar) if isMac: sc = "Ctrl+Shift+H" else: sc = "Ctrl+H" b.setShortcut(QKeySequence(sc)) b.setToolTip(_("Shortcut: %s") % shortcut(sc)) b.clicked.connect(self.onHistory) b.setEnabled(False) self.historyButton = b
def setupTopArea(self): self.topArea = QWidget() self.topAreaForm = aqt.forms.clayout_top.Ui_Form() self.topAreaForm.setupUi(self.topArea) self.topAreaForm.templateOptions.setText(_("Options") + " " + downArrow()) self.topAreaForm.templateOptions.clicked.connect(self.onMore) self.topAreaForm.templatesBox.currentIndexChanged.connect(self.onCardSelected)
def setup_preview(self): pform = self.pform self.preview_web = AnkiWebView(title="card layout") pform.verticalLayout.addWidget(self.preview_web) pform.verticalLayout.setStretch(1, 99) pform.preview_front.isChecked() qconnect(pform.preview_front.clicked, self.on_preview_toggled) qconnect(pform.preview_back.clicked, self.on_preview_toggled) pform.preview_settings.setText( tr(TR.CARD_TEMPLATES_PREVIEW_SETTINGS) + " " + downArrow() ) qconnect(pform.preview_settings.clicked, self.on_preview_settings) jsinc = [ "jquery.js", "browsersel.js", "mathjax/conf.js", "mathjax/MathJax.js", "reviewer.js", ] self.preview_web.stdHtml( self.mw.reviewer.revHtml(), css=["reviewer.css"], js=jsinc, context=self, ) self.preview_web.set_bridge_command(self._on_bridge_cmd, self) if self._isCloze(): nums = list(self.note.cloze_numbers_in_fields()) if self.ord + 1 not in nums: # current card is empty nums.append(self.ord + 1) self.cloze_numbers = sorted(nums) self.setup_cloze_number_box() else: self.cloze_numbers = [] self.pform.cloze_number_combo.setHidden(True)
def setupButtons(self) -> None: bb = self.form.buttonBox ar = QDialogButtonBox.ActionRole # add self.addButton = bb.addButton(_("Add"), ar) self.addButton.clicked.connect(self.addCards) self.addButton.setShortcut(QKeySequence("Ctrl+Return")) self.addButton.setToolTip(shortcut(_("Add (shortcut: ctrl+enter)"))) # close self.closeButton = QPushButton(_("Close")) self.closeButton.setAutoDefault(False) bb.addButton(self.closeButton, QDialogButtonBox.RejectRole) # help self.helpButton = QPushButton( _("Help"), clicked=self.helpRequested) # type: ignore self.helpButton.setAutoDefault(False) bb.addButton(self.helpButton, QDialogButtonBox.HelpRole) # history b = bb.addButton(_("History") + " " + downArrow(), ar) if isMac: sc = "Ctrl+Shift+H" else: sc = "Ctrl+H" b.setShortcut(QKeySequence(sc)) b.setToolTip(_("Shortcut: %s") % shortcut(sc)) b.clicked.connect(self.onHistory) b.setEnabled(False) self.historyButton = b
def __init__(self, mw, deck): QDialog.__init__(self, mw) self.mw = mw self.deck = deck self.childDids = [ d[1] for d in self.mw.col.decks.children(self.deck['id']) ] self._origNewOrder = None self.form = aqt.forms.dconf.Ui_Dialog() self.form.setupUi(self) self.mw.checkpoint(_("Options")) self.setupCombos() self.setupConfs() self.setWindowModality(Qt.WindowModal) self.form.buttonBox.helpRequested.connect( lambda: openHelp("deckoptions")) self.form.confOpts.clicked.connect(self.confOpts) self.form.confOpts.setText(downArrow()) self.form.buttonBox.button( QDialogButtonBox.RestoreDefaults).clicked.connect(self.onRestore) self.setWindowTitle(_("Options for %s") % self.deck['name']) # qt doesn't size properly with altered fonts otherwise restoreGeom(self, "deckconf", adjustSize=True) self.show() self.exec_() saveGeom(self, "deckconf")
def _deckRow(self, node, depth, cnt): name, did, due, lrn, new, children = node deck = self.mw.col.decks.get(did) if did == 1 and cnt > 1 and not children: # if the default deck is empty, hide it if not self.mw.col.db.scalar("select 1 from cards where did = 1"): return "" # parent toggled for collapsing for parent in self.mw.col.decks.parents(did): if parent['collapsed']: buff = "" return buff prefix = "-" if self.mw.col.decks.get(did)['collapsed']: prefix = "+" due += lrn def indent(): return " " * 6 * depth if did == self.mw.col.conf['curDeck']: klass = 'deck current' else: klass = 'deck' buf = "<tr class='%s' id='%d'>" % (klass, did) # deck link if children: collapse = "<a class=collapse href='collapse:%d'>%s</a>" % (did, prefix) else: collapse = "<span class=collapse></span>" if deck['dyn']: extraclass = "filtered" else: extraclass = "" buf += """ <td class=decktd colspan=5>%s%s<a class="deck %s" href='open:%d'>%s</a></td>""" % ( indent(), collapse, extraclass, did, name) # due counts def nonzeroColour(cnt, colour): if not cnt: colour = "#e0e0e0" if cnt >= 1000: cnt = "1000+" return "<font color='%s'>%s</font>" % (colour, cnt) buf += "<td align=right>%s</td><td align=right>%s</td>" % ( nonzeroColour(due, "#007700"), nonzeroColour(new, "#000099")) # options buf += "<td align=right class=opts>%s</td></tr>" % self.mw.button( link="opts:%d" % did, name="<img class='gears' valign=bottom src='qrc:/icons/gears.png'>" + downArrow()) # children buf += self._renderDeckTree(children, depth + 1) return buf
def _bottomHTML(self): return ccbc.html.rev_bottombar % dict( rem=self._remaining(), edit=_("Edit"), editkey=_("Shortcut key: %s") % "E", more=_("More"), downArrow=downArrow(), time=self.card.timeTaken() // 1000 )
def _bottomHTMLNew(self): return """ <table width=100%% cellspacing=0 cellpadding=0> <tr> <td align=left width=50 valign=top class=stat> <br> <button title="%(editkey)s" onclick="py.link('edit');">%(edit)s</button></td> <td align=center valign=top id=middle> </td> <td width=50 align=right valign=top class=stat><span id=time class=stattxt> </span><br> <button onclick="py.link('more');">%(more)s %(downArrow)s</button> </td> </tr> </table> <script> var time = %(time)d; var maxTime = 0; $(function () { $("#ansbut").focus(); updateTime(); setInterval(function () { time += 1; updateTime() }, 1000); }); var updateTime = function () { if (!maxTime) { $("#time").text(""); return; } time = Math.min(maxTime, time); var m = Math.floor(time / 60); var s = time %% 60; if (s < 10) { s = "0" + s; } var e = $("#time"); if (maxTime == time) { e.html("<font color=red>" + m + ":" + s + "</font>"); } else { e.text(m + ":" + s); } } function showQuestion(txt, maxTime_) { // much faster than jquery's .html() $("#middle")[0].innerHTML = txt; $("#ansbut").focus(); time = 0; maxTime = maxTime_; } function showAnswer(txt) { $("#middle")[0].innerHTML = txt; } </script> """ % dict(rem=self._remaining(), edit=_("Edit"), editkey=_("Shortcut key: %s") % "E", more=_("More"), downArrow=downArrow(), time=self.card.timeTaken() // 1000)
def bottomHTML(self) -> str: return open(os.path.join(thisScriptDir, "bottom.html"), "r").read() % dict( rem=self._remaining(), edit=tr(TR.STUDYING_EDIT), editkey=tr(TR.ACTIONS_SHORTCUT_KEY, val="E"), more=tr(TR.STUDYING_MORE), downArrow=downArrow(), time=self.card.timeTaken() // 1000, )
def setupTopArea(self): self.topArea = QWidget() self.topAreaForm = aqt.forms.clayout_top.Ui_Form() self.topAreaForm.setupUi(self.topArea) self.topAreaForm.templateOptions.setText(_("Options") + " " + downArrow()) qconnect(self.topAreaForm.templateOptions.clicked, self.onMore) qconnect( self.topAreaForm.templatesBox.currentIndexChanged, self.update_current_ordinal_and_redraw, ) self.topAreaForm.card_type_label.setText(tr(TR.CARD_TEMPLATES_CARD_TYPE))
def makeRow(self, col, depth, cnt): "Generate the HTML table cells for this row of the deck tree." node = self did = node.did children = node.children deck = col.mw.col.decks.get(did) if did == 1 and cnt > 1 and not children: # if the default deck is empty, hide it if not col.mw.col.db.scalar("select 1 from cards where did = 1"): return "" # parent toggled for collapsing for parent in col.mw.col.decks.parents(did): if parent['collapsed']: buff = "" return buff prefix = "-" if deck['collapsed']: prefix = "+" if did == col.mw.col.conf['curDeck']: klass = 'deck current' else: klass = 'deck' buf = start_line(klass,did) # deck link if children: collapse = collapse_children_html(did,deck["name"],prefix) else: collapse = collapse_no_child if deck['dyn']: extraclass = " filtered" else: extraclass = "" cssStyle = "" for name, value in node.style.items(): cssStyle +="%s:%s;" %(name,value) buf += deck_name(depth,collapse,extraclass,did,cssStyle,node.name) for (name, _, colour, description, number, deck) in userOption["columns"]: contents = self.text[number][deck][name] if contents == 0 or contents == "0": colour = "#e0e0e0" buf +=number_cell(colour, contents, description) # options button=col.mw.button(link="opts:%d"%did, name=deck_button_image+downArrow()) buf += deck_button(button) if userOption["option"]: buf += deck_option_name(self.param["confName"]) # children buf += end_line buf += col._renderDeckTree(children, depth+1) return buf
def add_query_button(self): ''' add a button in add card window ''' bb = self.form.buttonBox ar = QDialogButtonBox.ActionRole # button fastwqBtn = QPushButton(_("QUERY") + u" " + downArrow()) fastwqBtn.setShortcut(QKeySequence(my_shortcut)) fastwqBtn.setToolTip(_(u"Shortcut: %s") % shortcut(my_shortcut)) bb.addButton(fastwqBtn, ar) # signal def onQuery(e): if isinstance(e, QMouseEvent): if e.buttons() & Qt.LeftButton: menu = QMenu(self) menu.addAction( _("ALL_FIELDS"), lambda: query_from_editor_fields(self.editor), QKeySequence(my_shortcut)) # default options mid = self.editor.note.model()['id'] conf = config.get_maps(mid) conf = { 'list': [conf], 'def': 0 } if isinstance(conf, list) else conf maps_list = conf['list'] if len(maps_list) > 1: menu.addSeparator() for i, maps in enumerate(maps_list): menu.addAction( _OK_ICON if i == conf['def'] else _NULL_ICON, _('CONFIG_INDEX') % (i + 1) if isinstance( maps, list) else maps['name'], lambda mid=mid, i=i: set_options_def(mid, i)) menu.addSeparator() # end default options menu.addAction( _("OPTIONS"), lambda: show_options(self, self.editor.note.model()['id'])) menu.exec_( fastwqBtn.mapToGlobal(QPoint(0, fastwqBtn.height()))) else: query_from_editor_fields(self.editor) fastwqBtn.mousePressEvent = onQuery fastwqBtn.clicked.connect(onQuery)
def setupTopArea(self) -> None: self.topArea = QWidget() self.topArea.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) self.topAreaForm = aqt.forms.clayout_top.Ui_Form() self.topAreaForm.setupUi(self.topArea) self.topAreaForm.templateOptions.setText( tr(TR.ACTIONS_OPTIONS) + " " + downArrow() ) qconnect(self.topAreaForm.templateOptions.clicked, self.onMore) qconnect( self.topAreaForm.templatesBox.currentIndexChanged, self.update_current_ordinal_and_redraw, ) self.topAreaForm.card_type_label.setText(tr(TR.CARD_TEMPLATES_CARD_TYPE))
def _bottomHTML(self): time_color = "" if custom_bottombarButtonBorderColor: time_color = bottombarButtonBorder_color return """%(bottomHTML_style)s %(min_buttonSize)s <center id=outer> <table id=innertable width=100%% cellspacing=0 cellpadding=0> <tr> <td align=left width=50 valign=top class=stat> <br> <button title="Shortcut key: E" onclick="pycmd('edit');" %(edit_style)s>Edit</button></td> %(left_side1)s %(left_side2)s %(left_side3)s <td align=center valign=top id=middle> </td> %(right_side1)s %(right_side2)s %(right_side3)s <td width=50 align=right valign=top class=stat style='color: %(time_color)s'><span id=time class=stattxt> </span><br> <button onclick="pycmd('more');" %(more_style)s>More %(downArrow)s</button> </td> </tr> </table> </center> <script> time = %(time)d; %(SF_bottomHTML)s </script> """ % dict(bottomHTML_style=bottomHTML_style, min_buttonSize=min_buttonSize, rem=self._remaining(), downArrow=downArrow(), time=self.card.timeTaken() // 1000, edit_style=edit_style, left_side1=left_side1, left_side2=left_side2, left_side3=left_side3, right_side1=right_side1, right_side2=right_side2, right_side3=right_side3, more_style=more_style, SF_bottomHTML=SF_bottomHTML, time_color=time_color)
def setupButtons(self): bb = self.form.buttonBox ar = QDialogButtonBox.ActionRole #Addon: AddOnlyOnce cbState = self.mw.pm.profile.get("AddOnceOnlyCKBOX", False) self.addOnceChkBox = QCheckBox(_("Once")) self.addOnceChkBox.setCheckState(cbState) self.addOnceChkBox.setTristate(False) self.form.buttonBox.addButton(self.addOnceChkBox, QDialogButtonBox.ActionRole) self.addOnceChkBox.clicked.connect(self.onAddOnceChange) self.addOnceChkBox.setShortcut(QKeySequence("Ctrl+o")) self.addOnceChkBox.setToolTip(shortcut(_("Add (shortcut: Ctrl+o)"))) # add self.addButton = bb.addButton(_("Add"), ar) self.addButton.setShortcut(QKeySequence("Ctrl+Return")) self.addButton.setToolTip(shortcut(_("Add (shortcut: Ctrl+Enter)"))) self.addButton.clicked.connect(self.addCards) # close self.closeButton = QPushButton(_("Close")) self.closeButton.setAutoDefault(False) bb.addButton(self.closeButton, QDialogButtonBox.RejectRole) # history b = bb.addButton(_("History") + u" " + downArrow(), ar) if isMac: sc = "Ctrl+Shift+H" else: sc = "Ctrl+H" b.setShortcut(QKeySequence(sc)) b.setToolTip(_("Shortcut: %s") % shortcut(sc)) b.clicked.connect(self.onHistory) self.historyButton = b
def _bottomHTML(self): return """ <table width=100%% cellspacing=0 cellpadding=0> <tr> <td align=left width=50 valign=top class=stat> <br> <button title="%(editkey)s" onclick="py.link('edit');">%(edit)s</button></td> <td align=center valign=top id=middle> </td> <td width=50 align=right valign=top class=stat><span id=time class=stattxt> </span><br> <button onclick="py.link('more');">%(more)s %(downArrow)s</button> </td> </tr> </table> <script> var time = %(time)d; var maxTime = 0; $(function () { $("#ansbut").focus(); updateTime(); setInterval(function () { time += 1; updateTime() }, 1000); }); var updateTime = function () { if (!maxTime) { $("#time").text(""); return; } time = Math.min(maxTime, time); var m = Math.floor(time / 60); var s = time %% 60; if (s < 10) { s = "0" + s; } var e = $("#time"); if (maxTime == time) { e.html("<font color=red>" + m + ":" + s + "</font>"); } else { e.text(m + ":" + s); } } function showQuestion(txt, maxTime_) { // much faster than jquery's .html() $("#middle")[0].innerHTML = txt; $("#ansbut").focus(); time = 0; maxTime = maxTime_; } function showAnswer(txt) { $("#middle")[0].innerHTML = txt; $("#defease").focus(); } </script> """ % dict(rem=self._remaining(), edit=_("Edit"), editkey=_("Shortcut key: %s") % "E", more=_("More"), downArrow=downArrow(), time=self.card.timeTaken() // 1000)
def _deckRow(self, node, depth, cnt): name, did, due, lrn, new, children = node deck = self.mw.col.decks.get(did) if did == 1 and cnt > 1 and not children: # if the default deck is empty, hide it if not self.mw.col.db.scalar("select 1 from cards where did = 1"): return "" # parent toggled for collapsing for parent in self.mw.col.decks.parents(did): if parent['collapsed']: buff = "" return buff prefix = "-" if self.mw.col.decks.get(did)['collapsed']: prefix = "+" due += lrn def indent(): return " "*6*depth if did == self.mw.col.conf['curDeck']: klass = 'deck current' else: klass = 'deck' buf = "<tr class='%s' id='%d'>" % (klass, did) # deck link if children: collapse = "<a class=collapse href='collapse:%d'>%s</a>" % (did, prefix) else: collapse = "<span class=collapse></span>" if deck['dyn']: extraclass = "filtered" else: extraclass = "" buf += """ <td class=decktd colspan=5>%s%s<a class="deck %s" href='open:%d'>%s</a></td>"""% ( indent(), collapse, extraclass, did, name) # due counts def nonzeroColour(cnt, colour): if not cnt: colour = "#e0e0e0" if cnt >= 1000: cnt = "1000+" return "<font color='%s'>%s</font>" % (colour, cnt) buf += "<td align=right>%s</td><td align=right>%s</td>" % ( nonzeroColour(due, "#007700"), nonzeroColour(new, "#000099")) # options buf += "<td align=right class=opts>%s</td></tr>" % self.mw.button( link="opts:%d"%did, name="<img valign=bottom src='qrc:/icons/gears.png'>"+downArrow()) # children buf += self._renderDeckTree(children, depth+1) return buf
def mySetupButtons(self): but = self._addButton("mybutton", lambda s=self: onAnkiSymbols(self), text="Greek Letters " + downArrow(), size=False)
def makeRow(self, col, depth, cnt): "Generate the HTML table cells for this row of the deck tree." node = self did = node.did children = node.children deck = col.mw.col.decks.get(did) if did == 1 and cnt > 1 and not children: # if the default deck is empty, hide it if not col.mw.col.db.scalar("select 1 from cards where did = 1"): return "" # parent toggled for collapsing for parent in col.mw.col.decks.parents(did): if parent['collapsed']: buff = "" return buff prefix = "-" if col.mw.col.decks.get(did)['collapsed']: prefix = "+" def indent(): return " " * 6 * depth if did == col.mw.col.conf['curDeck']: klass = 'deck current' else: klass = 'deck' buf = "<tr class='%s' id='%d'>" % (klass, did) # deck link if children: collapse = "<a class=collapse href='collapse:%d'>%s</a>" % (did, prefix) else: collapse = "<span class=collapse></span>" if deck['dyn']: extraclass = "filtered" else: extraclass = "" buf += """ <td class=decktd colspan=5>%s%s<a class="deck %s" href='open:%d'><font color='%s'>%s</font></a></td>""" % ( indent(), collapse, extraclass, did, node.color, node.name) for (name, _, present, colour, description) in userOption["columns"]: if present: contents = self.count["flat" if userOption[ "Do not count subdeck's card"] else "rec"][name] if contents == 0 or contents == "0": colour = "#e0e0e0" buf += ( "<td align='right' class='tooltip'><font color='%s'>%s</font><span class='tooltiptext'>%s</span></td>" % (colour, contents, description)) # options buf += "<td align=right class=opts>%s</td>" % col.mw.button( link="opts:%d" % did, name="<img valign=bottom src='qrc:/icons/gears.png'>" + downArrow()) if userOption["option"]: buf += "<td>%s</td>" % self.confName # children buf += "</tr>" buf += col._renderDeckTree(children, depth + 1) return buf
def setupButtons(self): self._buttons = {} # button styles for mac if not isMac: self.plastiqueStyle = QStyleFactory.create("plastique") if not self.plastiqueStyle: # plastique was removed in qt5 self.plastiqueStyle = QStyleFactory.create("fusion") self.widget.setStyle(self.plastiqueStyle) else: self.plastiqueStyle = None # icons self.iconsBox = QHBoxLayout() if not isMac: self.iconsBox.setMargin(6) self.iconsBox.setSpacing(0) else: self.iconsBox.setMargin(0) self.iconsBox.setSpacing(14) self.outerLayout.addLayout(self.iconsBox) b = self._addButton b("fields", self.onFields, "", shortcut(_("Customize Fields")), size=False, text=_("Fields..."), native=True, canDisable=False) self.iconsBox.addItem(QSpacerItem(6,1, QSizePolicy.Fixed)) b("layout", self.onCardLayout, _("Ctrl+L"), shortcut(_("Customize Cards (Ctrl+L)")), size=False, text=_("Cards..."), native=True, canDisable=False) # align to right self.iconsBox.addItem(QSpacerItem(20,1, QSizePolicy.Expanding)) b("text_bold", self.toggleBold, _("Ctrl+B"), _("Bold text (Ctrl+B)"), check=True) b("text_italic", self.toggleItalic, _("Ctrl+I"), _("Italic text (Ctrl+I)"), check=True) b("text_under", self.toggleUnderline, _("Ctrl+U"), _("Underline text (Ctrl+U)"), check=True) b("text_super", self.toggleSuper, _("Ctrl+Shift+="), _("Superscript (Ctrl+Shift+=)"), check=True) b("text_sub", self.toggleSub, _("Ctrl+="), _("Subscript (Ctrl+=)"), check=True) b("text_clear", self.removeFormat, _("Ctrl+R"), _("Remove formatting (Ctrl+R)")) but = b("foreground", self.onForeground, _("F7"), text=" ") but.setToolTip(_("Set foreground colour (F7)")) self.setupForegroundButton(but) but = b("change_colour", self.onChangeCol, _("F8"), _("Change colour (F8)"), text=downArrow()) but.setFixedWidth(12) but = b("cloze", self.onCloze, _("Ctrl+Shift+C"), _("Cloze deletion (Ctrl+Shift+C)"), text="[...]") but.setFixedWidth(24) s = self.clozeShortcut2 = QShortcut( QKeySequence(_("Ctrl+Alt+Shift+C")), self.parentWindow) s.connect(s, SIGNAL("activated()"), self.onCloze) # fixme: better image names b("mail-attachment", self.onAddMedia, _("F3"), _("Attach pictures/audio/video (F3)")) b("media-record", self.onRecSound, _("F5"), _("Record audio (F5)")) b("adv", self.onAdvanced, text=downArrow()) s = QShortcut(QKeySequence("Ctrl+T, T"), self.widget) s.connect(s, SIGNAL("activated()"), self.insertLatex) s = QShortcut(QKeySequence("Ctrl+T, E"), self.widget) s.connect(s, SIGNAL("activated()"), self.insertLatexEqn) s = QShortcut(QKeySequence("Ctrl+T, M"), self.widget) s.connect(s, SIGNAL("activated()"), self.insertLatexMathEnv) s = QShortcut(QKeySequence("Ctrl+Shift+X"), self.widget) s.connect(s, SIGNAL("activated()"), self.onHtmlEdit) # tags s = QShortcut(QKeySequence("Ctrl+Shift+T"), self.widget) s.connect(s, SIGNAL("activated()"), lambda: self.tags.setFocus()) runHook("setupEditorButtons", self)
def mySetupButtons(buttons, self): self._addButton("AutoDefine", lambda s=self: button_pressed(self), text="D" + downArrow(), tip="AutoDefine Word (Ctrl+E)", key="Ctrl+e")
def makeRow(self, col, depth, cnt): "Generate the HTML table cells for this row of the deck tree." node = self did = node.did children = node.children deck = col.mw.col.decks.get(did) if did == 1 and cnt > 1 and not children: # if the default deck is empty, hide it if not col.mw.col.db.scalar("select 1 from cards where did = 1"): return "" # parent toggled for collapsing for parent in col.mw.col.decks.parents(did): if parent['collapsed']: buff = "" return buff prefix = "-" if deck['collapsed']: prefix = "+" if did == col.mw.col.conf['curDeck']: klass = 'deck current' else: klass = 'deck' buf = "<tr class='%s' id='%d'>" % (klass, did) # deck link if children: collapse = """<a class=collapse onclick='pycmd("collapse:%d")' id="%s" href="#%s" >%s</a>""" % ( did, deck["name"], deck["name"], prefix) else: collapse = "<span class=collapse></span>" if deck['dyn']: extraclass = " filtered" else: extraclass = "" cssStyle = "" for name, value in node.style.items(): cssStyle += "%s:%s;" % (name, value) buf += f""" <td class=decktd colspan=5>{" "*6*depth}{collapse}<a class="deck{extraclass}" onclick="pycmd('open:{did}')">""" # buf+=f"""debug<font style='{cssStyle}' class='tooltip'>{node.name}<span class='tooltiptext'>{self.objectDescription()}</span></font>""" buf += f"""<font style='{cssStyle}'>{node.name}</font>""" buf += """</a></td>""" for (name, _, colour, description, number, deck) in userOption["columns"]: contents = self.text[number][deck][name] if contents == 0 or contents == "0": colour = "#e0e0e0" buf += ( "<td align='right' class='tooltip'><font color='%s'>%s</font><span class='tooltiptext'>%s</span></td>" % (colour, contents, description)) # options button = col.mw.button( link="opts:%d" % did, name="<img valign=bottom src='/_anki/imgs/gears.svg' class=gears>" + downArrow()) buf += f"<td align=right class=opts>{button}</td>" if userOption["option"]: buf += "<td>%s</td>" % self.param["confName"] # children buf += "</tr>" buf += col._renderDeckTree(children, depth + 1) return buf
def setupButtons(self): self._buttons = {} # button styles for mac if not isMac: self.plastiqueStyle = QStyleFactory.create("plastique") if not self.plastiqueStyle: # plastique was removed in qt5 self.plastiqueStyle = QStyleFactory.create("fusion") self.widget.setStyle(self.plastiqueStyle) else: self.plastiqueStyle = None # icons self.iconsBox = QHBoxLayout() if not isMac: self.iconsBox.setMargin(6) self.iconsBox.setSpacing(0) else: self.iconsBox.setMargin(0) self.iconsBox.setSpacing(14) self.outerLayout.addLayout(self.iconsBox) b = self._addButton b("fields", self.onFields, "", shortcut(_("Customize Fields")), size=False, text=_("Fields..."), native=True, canDisable=False) self.iconsBox.addItem(QSpacerItem(6, 1, QSizePolicy.Fixed)) b("layout", self.onCardLayout, _("Ctrl+L"), shortcut(_("Customize Cards (Ctrl+L)")), size=False, text=_("Cards..."), native=True, canDisable=False) # align to right self.iconsBox.addItem(QSpacerItem(20, 1, QSizePolicy.Expanding)) b("text_bold", self.toggleBold, _("Ctrl+B"), _("Bold text (Ctrl+B)"), check=True) b("text_italic", self.toggleItalic, _("Ctrl+I"), _("Italic text (Ctrl+I)"), check=True) b("text_under", self.toggleUnderline, _("Ctrl+U"), _("Underline text (Ctrl+U)"), check=True) b("text_super", self.toggleSuper, _("Ctrl+Shift+="), _("Superscript (Ctrl+Shift+=)"), check=True) b("text_sub", self.toggleSub, _("Ctrl+="), _("Subscript (Ctrl+=)"), check=True) b("text_clear", self.removeFormat, _("Ctrl+R"), _("Remove formatting (Ctrl+R)")) but = b("foreground", self.onForeground, _("F7"), text=" ") but.setToolTip(_("Set foreground colour (F7)")) self.setupForegroundButton(but) but = b("change_colour", self.onChangeCol, _("F8"), _("Change colour (F8)"), text=downArrow()) but.setFixedWidth(12) but = b("cloze", self.onCloze, _("Ctrl+Shift+C"), _("Cloze deletion (Ctrl+Shift+C)"), text="[...]") but.setFixedWidth(24) s = self.clozeShortcut2 = QShortcut( QKeySequence(_("Ctrl+Alt+Shift+C")), self.parentWindow) s.connect(s, SIGNAL("activated()"), self.onCloze) # fixme: better image names b("mail-attachment", self.onAddMedia, _("F3"), _("Attach pictures/audio/video (F3)")) b("media-record", self.onRecSound, _("F5"), _("Record audio (F5)")) b("adv", self.onAdvanced, text=downArrow()) s = QShortcut(QKeySequence("Ctrl+T, T"), self.widget) s.connect(s, SIGNAL("activated()"), self.insertLatex) s = QShortcut(QKeySequence("Ctrl+T, E"), self.widget) s.connect(s, SIGNAL("activated()"), self.insertLatexEqn) s = QShortcut(QKeySequence("Ctrl+T, M"), self.widget) s.connect(s, SIGNAL("activated()"), self.insertLatexMathEnv) s = QShortcut(QKeySequence("Ctrl+Shift+X"), self.widget) s.connect(s, SIGNAL("activated()"), self.onHtmlEdit) # tags s = QShortcut(QKeySequence("Ctrl+Shift+T"), self.widget) s.connect(s, SIGNAL("activated()"), lambda: self.tags.setFocus()) runHook("setupEditorButtons", self)