def init_layout(self): self.setWindowTitle(" Prestudy") vbox = QVBoxLayout() vbox.addWidget(QLabel("Select deck to add notes to:")) self.combo_box = QComboBox(self) self.combo_box.addItems(self.deck_names) vbox.addWidget(self.combo_box) vbox.addWidget( QLabel( "(Optional) Enter tag(s) to add to notes, separated by spaces:" )) self.tags_box = QLineEdit() vbox.addWidget(self.tags_box) hbox = QHBoxLayout() self.finish_button = QPushButton("Add Notes") hbox.addStretch(1) hbox.addWidget(self.finish_button) vbox.addLayout(hbox) self.finish_button.clicked.connect(lambda: self.add_notes_action()) self.setLayout(vbox)
def senseiButtons(editor): editor.upperIcondsBox = editor.iconsBox editor.iconsBox = QHBoxLayout() if not isMac: editor.iconsBox.setMargin(6) else: editor.iconsBox.setMargin(0) editor.iconsBox.setSpacing(0) editor.outerLayout.addLayout(editor.iconsBox) editor._addButton("generateRuby", lambda: doIt(editor, generateRuby), key=_("Ctrl+F"), tip=_(u"Automatically generate furigana (Ctrl+F)"), text=_(u"Generate readings"), size=False) editor._addButton("deleteRuby", lambda: doIt(editor, deleteRuby), tip=_(u"Mass delete furigana"), text=_(u"Delete readings"), size=False) editor._addButton("preRender", lambda: doIt(editor, preRender), tip=_(u"Show furigana or markup"), text=_(u"Visual/Code"), size=False) editor._addButton("extractKanji", lambda: extract(editor), tip=_(u"Strip everything but base-clozed kanji"), text=_(u"Extract clozed kanji"), size=False) runHook("senseiButtons", editor) editor.iconsBox.addItem(QSpacerItem(20,1, QSizePolicy.Expanding)) editor.iconsBox.addWidget(QLabel('Furigana ')) editor._addButton("clozeRuby", lambda: doIt(editor, clozeRuby), key=_("Ctrl+H"), tip=_(u"Create a reading excercise (Ctrl+H)"), text=_(u"Cloze/Uncloze"), size=False) editor._addButton("hideRuby", lambda: doIt(editor, hideRuby), tip=_(u"Make ruby texts hidden so they show only up when being asked."), text=_(u"Hide/Show"), size=False) editor.iconsBox.addItem(QSpacerItem(20,1, QSizePolicy.Expanding)) editor.iconsBox.addWidget(QLabel('Kanji ')) editor._addButton("clozeKanji", lambda: doIt(editor, clozeKanji), key=_("Ctrl+J"), tip=_(u"Create a writing excercise (Ctrl+J)"), text=_(u"Cloze/Uncloze"), size=False) editor._addButton("hideBase", lambda: doIt(editor, hideBase), tip=_(u"Make base texts hidden so they are replaced with ◯ signs unless asked."), text=_(u"Hide/Show"), size=False)
def onTargetDeck(self): from aqt.tagedit import TagEdit t = self.card.template() d = QDialog(self) d.setWindowTitle("Anki") d.setMinimumWidth(400) l = QVBoxLayout() lab = QLabel(_("""\ Enter deck to place new %s cards in, or leave blank:""") % self.card.template()['name']) lab.setWordWrap(True) l.addWidget(lab) te = TagEdit(d, type=1) te.setCol(self.col) l.addWidget(te) if t['did']: te.setText(self.col.decks.get(t['did'])['name']) te.selectAll() bb = QDialogButtonBox(QDialogButtonBox.Close) bb.rejected.connect(d.close) l.addWidget(bb) d.setLayout(l) d.exec_() if not te.text().strip(): t['did'] = None else: t['did'] = self.col.decks.id(te.text())
def setup_evernote(self): global evernote_default_deck global evernote_default_tag global evernote_tags_to_import global keep_evernote_tags global update_existing_notes widget = QWidget() layout = QVBoxLayout() # Default Deck evernote_default_deck_label = QLabel("Default Deck for imported Cards:") evernote_default_deck = QLineEdit() evernote_default_deck.setText(mw.col.conf.get(SETTING_DEFAULT_DECK, "")) layout.insertWidget(int(layout.count()) + 1, evernote_default_deck_label) layout.insertWidget(int(layout.count()) + 2, evernote_default_deck) evernote_default_deck.connect(evernote_default_deck, SIGNAL("editingFinished()"), update_evernote_default_deck) # Default Tag evernote_default_tag_label = QLabel("Default Tag for imported Cards:") evernote_default_tag = QLineEdit() evernote_default_tag.setText(mw.col.conf.get(SETTING_DEFAULT_TAG, "")) layout.insertWidget(int(layout.count()) + 1, evernote_default_tag_label) layout.insertWidget(int(layout.count()) + 2, evernote_default_tag) evernote_default_tag.connect(evernote_default_tag, SIGNAL("editingFinished()"), update_evernote_default_tag) # Tags to Import evernote_tags_to_import_label = QLabel("Evernote Tags to Import:") evernote_tags_to_import = QLineEdit() evernote_tags_to_import.setText(mw.col.conf.get(SETTING_TAGS_TO_IMPORT, "")) layout.insertWidget(int(layout.count()) + 1, evernote_tags_to_import_label) layout.insertWidget(int(layout.count()) + 2, evernote_tags_to_import) evernote_tags_to_import.connect(evernote_tags_to_import, SIGNAL("editingFinished()"), update_evernote_tags_to_import) # Keep Evernote Tags keep_evernote_tags = QCheckBox("Keep Evernote Tags", self) keep_evernote_tags.setChecked(mw.col.conf.get(SETTING_KEEP_TAGS, False)) keep_evernote_tags.stateChanged.connect(update_evernote_keep_tags) layout.insertWidget(int(layout.count()) + 1, keep_evernote_tags) # Update Existing Notes update_existing_notes = QComboBox() update_existing_notes.addItems(["Ignore Existing Notes", "Update Existing Notes In-Place", "Delete and Re-Add Existing Notes"]) update_existing_notes.setCurrentIndex(mw.col.conf.get(SETTING_UPDATE_EXISTING_NOTES, UpdateExistingNotes.UpdateNotesInPlace)) update_existing_notes.activated.connect(update_evernote_update_existing_notes) layout.insertWidget(int(layout.count()) + 1, update_existing_notes) # Vertical Spacer vertical_spacer = QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Expanding) layout.addItem(vertical_spacer) # Parent Widget widget.setLayout(layout) # New Tab self.form.tabWidget.addTab(widget, "Evernote2AnkiMac")
def showMapping(self, keepMapping=False, hook=None): if hook: hook() if not keepMapping: self.mapping = self.importer.mapping self.frm.mappingGroup.show() assert self.importer.fields() # set up the mapping grid if self.mapwidget: self.mapbox.removeWidget(self.mapwidget) self.mapwidget.deleteLater() self.mapwidget = QWidget() self.mapbox.addWidget(self.mapwidget) self.grid = QGridLayout(self.mapwidget) self.mapwidget.setLayout(self.grid) self.grid.setContentsMargins(3, 3, 3, 3) self.grid.setSpacing(6) fields = self.importer.fields() for num in range(len(self.mapping)): text = _("Field <b>%d</b> of file is:") % (num + 1) self.grid.addWidget(QLabel(text), num, 0) if self.mapping[num] == "_tags": text = _("mapped to <b>Tags</b>") elif self.mapping[num]: text = _("mapped to <b>%s</b>") % self.mapping[num] else: text = _("<ignored>") self.grid.addWidget(QLabel(text), num, 1) button = QPushButton(_("Change")) self.grid.addWidget(button, num, 2) button.clicked.connect( lambda _, s=self, n=num: s.changeMappingNum(n))
def _setupUI(self): """Basic UI setup""" mainLayout = QVBoxLayout() self.label = QLabel("Please press the key combination\n" "you would like to assign") self.label.setAlignment(Qt.AlignCenter) mainLayout.addWidget(self.label) self.setLayout(mainLayout) self.setWindowTitle("Grab key combination")
def __init__(self, editor, parent_window, selected_text, selected_is_url=False): QDialog.__init__(self, parent_window, Qt.Window) self.editor_instance = editor self.parent_window = parent_window self.selected_text = selected_text self.selected_is_url = selected_is_url self.setWindowTitle("Anki: Create a hyperlink") self.resize(DIALOG_SIZE_X, DIALOG_SIZE_Y) restoreGeom(self, "318752047__add_hyperlink") self.pb_ok = QPushButton("&OK", self) self.pb_ok.setEnabled(False) self.pb_ok.clicked.connect( lambda: self.insert_anchor(url_edit.text(), urltext_edit.text())) self.pb_cancel = QPushButton("&Cancel", self) self.pb_cancel.clicked.connect(self.reject) url_label = QLabel("Link to:") url_edit = QLineEdit() url_edit.setPlaceholderText("URL") url_edit.textChanged.connect(lambda: self.enable_ok_button( self.pb_ok, url_edit.text(), urltext_edit.text())) urltext_label = QLabel("Text to display:") urltext_edit = QLineEdit() urltext_edit.setPlaceholderText("Text") urltext_edit.textChanged.connect(lambda: self.enable_ok_button( self.pb_ok, url_edit.text(), urltext_edit.text())) self.button_bar = QHBoxLayout() self.button_bar.addStretch(1) self.button_bar.addWidget(self.pb_cancel) self.button_bar.addWidget(self.pb_ok) self.dialog_vbox = QVBoxLayout() self.dialog_vbox.addWidget(url_label) self.dialog_vbox.addWidget(url_edit) self.dialog_vbox.addWidget(urltext_label) self.dialog_vbox.addWidget(urltext_edit) self.dialog_vbox.addLayout(self.button_bar) self.setLayout(self.dialog_vbox) # if user already selected text, put it in urltext_edit if self.selected_text: if self.selected_is_url: url_edit.setText(self.selected_text) urltext_edit.setFocus() else: urltext_edit.setText(self.selected_text) url_edit.setFocus()
def downloadMedia(url, editor): # Local file : just read the file content if url.startswith("file://"): try: url = url[7:] # On windows, paths tend to be prefixed by file:/// # rather than file://, so we remove redundant slash. if re.match(r'^/[A-Za-z]:\\', url): url = url[1:] return open(url, 'rb').read() except OSError: pass app = editor.mw.app # Show download dialog d = QDialog(editor.parentWindow) d.setWindowTitle("Downloading media (0.0%)") d.setWindowModality(Qt.WindowModal) vbox = QVBoxLayout() label = QLabel(url) label.setWordWrap(True) vbox.addWidget(label) d.setLayout(vbox) d.show() # Download chunk by chunk for progress bar try: response = urllib2.urlopen(url) totSize = int(response.info().getheader('Content-Length').strip()) currentRead = 0 chunk_size = 16384 chunks = [] while True: chunk = response.read(chunk_size) currentRead += len(chunk) if not chunk: break d.setWindowTitle("Downloading media (%.1f%%)" % (currentRead * 100.0 / totSize)) app.processEvents() chunks.append(chunk) return ''.join(chunks) except urllib2.URLError: return None finally: d.close() del d
def validate_label(self): label = QLabel('Not a valid format!') label.setStyleSheet("QLabel {color : red}") policy = label.sizePolicy() policy.setRetainSizeWhenHidden(True) label.setSizePolicy(policy) label.hide() return label
def show_words_window(self): """ Show the second window of the utility. This window shows the new words that were extracted from the text. """ self.words_window = QWidget(mw, flags=QtCore.Qt.Window) vbox = QVBoxLayout() vbox.addWidget(QLabel("Enter your vocab size target:")) self.vocab_recommended_radio = QRadioButton( "{} (Recommended)".format(RECOMMENDED_TARGET_VOCAB_SIZE)) self.vocab_custom_radio = QRadioButton("Custom: ") self.vocab_custom_box = LineEditWithFocusedSignal() radio_hbox = QHBoxLayout() radio_hbox.addStretch(1) radio_hbox.addWidget(self.vocab_recommended_radio) radio_hbox.addStretch(2) radio_hbox.addWidget(self.vocab_custom_radio) radio_hbox.addWidget(self.vocab_custom_box) radio_hbox.addStretch(1) vbox.addLayout(radio_hbox) vbox.addWidget(QLabel("These are the new words you should learn:")) self.words_table = self.init_words_table() vbox.addWidget(self.words_table) continue_hbox = QHBoxLayout() continue_hbox.addStretch(1) continue_button = QPushButton("Continue") continue_hbox.addWidget(continue_button) vbox.addLayout(continue_hbox) self.words_window.setLayout(vbox) self.update_words_table() # TODO: for some reason, this disables the blinking cursor in `vocab_custom_box` self.vocab_custom_box.focused.connect( lambda: self.vocab_custom_radio.click()) self.vocab_recommended_radio.clicked.connect( lambda: self.update_words_table()) self.vocab_custom_radio.clicked.connect( lambda: self.update_words_table()) self.vocab_custom_box.textChanged.connect( lambda: self.update_words_table()) continue_button.clicked.connect( lambda: self.words_window_continue_action()) self.words_window.show()
def hyperlink_dialog(self): dialog = QDialog(self.parent_window) dialog.setWindowTitle("Create a hyperlink") dialog.resize(DIALOG_SIZE_X, DIALOG_SIZE_Y) ok_button_anchor = QPushButton("&OK", dialog) ok_button_anchor.setEnabled(False) ok_button_anchor.clicked.connect( lambda: self.insert_anchor(url_edit.text(), urltext_edit.text())) ok_button_anchor.clicked.connect(dialog.hide) ok_button_anchor.setAutoDefault(True) cancel_button_anchor = QPushButton("&Cancel", dialog) cancel_button_anchor.clicked.connect(dialog.hide) cancel_button_anchor.setAutoDefault(True) url_label = QLabel("Link to:") url_edit = QLineEdit() url_edit.setPlaceholderText("URL") url_edit.textChanged.connect(lambda: self.enable_ok_button( ok_button_anchor, url_edit.text(), urltext_edit.text())) urltext_label = QLabel("Text to display:") urltext_edit = QLineEdit() urltext_edit.setPlaceholderText("Text") urltext_edit.textChanged.connect(lambda: self.enable_ok_button( ok_button_anchor, url_edit.text(), urltext_edit.text())) button_box = QHBoxLayout() button_box.addStretch(1) button_box.addWidget(cancel_button_anchor) button_box.addWidget(ok_button_anchor) dialog_vbox = QVBoxLayout() dialog_vbox.addWidget(url_label) dialog_vbox.addWidget(url_edit) dialog_vbox.addWidget(urltext_label) dialog_vbox.addWidget(urltext_edit) dialog_vbox.addLayout(button_box) dialog.setLayout(dialog_vbox) # if user already selected text, put it in urltext_edit if self.selected_text: if self.selected_is_url: url_edit.setText(self.selected_text) urltext_edit.setFocus() else: urltext_edit.setText(self.selected_text) url_edit.setFocus() dialog.exec()
def _ui_join_keys_row(self): def _fix_width(cb): width = cb.minimumSizeHint().width() cb.view().setMinimumWidth(width) # first row consists of join keys for notes and file hbox = QHBoxLayout() hbox.setAlignment(Qt.AlignLeft) # file join key hbox.addWidget(QLabel("File Join Key:")) self.file_join_key_selection = QComboBox() self.file_join_key_selection.addItems(self.file_field_names) _fix_width(self.file_join_key_selection) if "nid" in self.file_field_names: self.file_join_key_selection.setCurrentText("nid") else: self.file_join_key_selection.setCurrentText( self.file_field_names[0]) self.file_join_key_selection.currentIndexChanged.connect( lambda _: self._combobox_changed(self.file_join_key_selection)) hbox.addWidget(self.file_join_key_selection) # note join key hbox.addWidget(QLabel("Note Join Key:")) self.note_join_key_selection = QComboBox() expanded_note_field_names = ["nid"] + self.note_field_names self.note_join_key_selection.addItems(expanded_note_field_names) _fix_width(self.note_join_key_selection) self.note_join_key_selection_default_value = "nid" if self.file_join_key_selection.currentText( ) in expanded_note_field_names: self.note_join_key_selection.setCurrentText( self.file_join_key_selection.currentText()) else: self.note_join_key_selection.setCurrentText( self.note_join_key_selection_default_value) self.note_join_key_selection.currentIndexChanged.connect( lambda _: self._combobox_changed(self.note_join_key_selection)) hbox.addWidget(self.note_join_key_selection) yield hbox hbox = QHBoxLayout() hbox.addWidget( QLabel("Define the mapping from file fields to note fields. " "Any file fields mapping to nothing will be ignored.")) yield hbox
def _ui_field_select_rows(self): # combo boxes to select mapping for remaining fields self.mapping_field_selections = [] for field_name in self.file_field_names: # nid can only be used as a join key if field_name == "nid": continue hbox = QHBoxLayout() hbox.setAlignment(Qt.AlignLeft) hbox.addWidget(QLabel("{} -> ".format(field_name))) field_selection = QComboBox() field_selection.addItems([NOTHING_VALUE] + self.note_field_names) width = field_selection.minimumSizeHint().width() field_selection.view().setMinimumWidth(width) if field_name in self.note_field_names and \ field_name != self.note_join_key_selection.currentText(): field_selection.setCurrentText(field_name) else: field_selection.setCurrentText(NOTHING_VALUE) field_selection.currentIndexChanged.connect( lambda _, fs=field_selection: self._combobox_changed(fs)) hbox.addWidget(field_selection) self.mapping_field_selections.append(field_selection) yield hbox
def show_text_entry_window(self): """ Show the first window of the utility. This window prompts the user to paste in some text. """ self.text_entry_window = w = QWidget(mw, flags=QtCore.Qt.Window) w.setWindowTitle(" Prestudy") vbox = QVBoxLayout() vbox.addWidget(QLabel("Paste in the text you want to read:")) self.input_text_box = QTextEdit() vbox.addWidget(self.input_text_box) continue_button = QPushButton("Continue") # TODO not sure why a lambda is needed here continue_button.clicked.connect( lambda: self.text_entry_continue_action()) hbox = QHBoxLayout() hbox.addStretch(1) hbox.addWidget(continue_button) vbox.addLayout(hbox) w.setLayout(vbox) w.show()
def _setupUi(self): flabel = QLabel("In this field:") self.fsel = QComboBox() fields = self._getFields() self.fsel.addItems(fields) self.cb = QCheckBox() self.cb.setText("transform to plain text") f_hbox = QHBoxLayout() f_hbox.addWidget(flabel) f_hbox.addWidget(self.fsel) f_hbox.addWidget(self.cb) f_hbox.setAlignment(Qt.AlignLeft) button_box = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, orientation=Qt.Horizontal, parent=self, ) bottom_hbox = QHBoxLayout() bottom_hbox.addWidget(button_box) vbox_main = QVBoxLayout() vbox_main.addLayout(f_hbox) vbox_main.addLayout(bottom_hbox) self.setLayout(vbox_main) self.setWindowTitle("Batch Clean Selected Notes") button_box.rejected.connect(self.reject) button_box.accepted.connect(self.accept) self.rejected.connect(self.reject) self.accepted.connect(self.accept) self.fsel.setFocus()
def __init__(self, parent, question, help=None, edit=None, default="", \ title="Anki", minWidth=400): QDialog.__init__(self, parent) self.setWindowTitle(title) self.question = question self.help = help self.qlabel = QLabel(question) self.setMinimumWidth(minWidth) v = QVBoxLayout() v.addWidget(self.qlabel) if not edit: edit = QLineEdit() self.l = edit if default: self.l.setText(default) self.l.selectAll() v.addWidget(self.l) buts = QDialogButtonBox.Ok | QDialogButtonBox.Cancel if help: buts |= QDialogButtonBox.Help b = QDialogButtonBox(buts) v.addWidget(b) self.setLayout(v) b.button(QDialogButtonBox.Ok).clicked.connect(self.accept) b.button(QDialogButtonBox.Cancel).clicked.connect(self.reject) if help: b.button(QDialogButtonBox.Help).clicked.connect(self.helpRequested)
def setupDecks(self): if self.label: self.deckLabel = QLabel(_("Deck")) self.addWidget(self.deckLabel) # decks box self.deck = QPushButton(clicked=self.onDeckChange) self.deck.setToolTip(shortcut(_("Target Deck (Ctrl+D)"))) s = QShortcut(QKeySequence(_("Ctrl+D")), self.widget, activated=self.onDeckChange) self.addWidget(self.deck) # starting label if self.mw.col.conf.get("addToCur", True): col = self.mw.col did = col.conf['curDeck'] if col.decks.isDyn(did): # if they're reviewing, try default to current card c = self.mw.reviewer.card if self.mw.state == "review" and c: if not c.odid: did = c.did else: did = c.odid else: did = 1 self.setDeckName(self.mw.col.decks.nameOrNone( did) or _("Default")) else: self.setDeckName(self.mw.col.decks.nameOrNone( self.mw.col.models.current()['did']) or _("Default")) # layout sizePolicy = QSizePolicy( QSizePolicy.Policy(7), QSizePolicy.Policy(0)) self.deck.setSizePolicy(sizePolicy)
def create_menu_entry(editor, e, parentmenu): if e.get('IconInMenu', False): y = QLabel() path = join(icon_path, e['IconInMenu']) # never defined!!!! pixmap = QPixmap(path) y.setPixmap(pixmap) else: t = editor.my_label_text(e, True) y = QLabel(t) # https://stackoverflow.com/a/6876509 y.setAutoFillBackground(True) stylesheet = editor.return_stylesheet(e) y.setStyleSheet(stylesheet) x = QWidgetAction(parentmenu) x.setDefaultWidget(y) cat = e["Category"] se = e.get("Setting", e.get("Category", False)) x.triggered.connect( lambda _, a=cat, b=se: my_highlight_helper(editor, a, b)) return x
def setRowMod(self, row, *args): for i, text in enumerate(args): label = QLabel() label.setText(text) label.setAlignment(Qt.AlignCenter) self.ui.scriptsTable.setCellWidget(row, i, label)
def setRowMod(self, row, name, frontEnabled, frontText, backEnabled, backText): for i, text in enumerate([name, frontEnabled, frontText, backEnabled, backText]): label = QLabel() label.setText(text) label.setAlignment(Qt.AlignCenter) self.ui.iterationsTable.setCellWidget(row, i, label)
def setRowMod(self, row, name, enabled, conditions): for i, text in enumerate([name, enabled, conditions]): label = QLabel() label.setText(text) label.setAlignment(Qt.AlignCenter) self.ui.injectionsTable.setCellWidget(row, i, label)
def _ui_field_select_row(self): hbox = QHBoxLayout() hbox.setAlignment(Qt.AlignLeft) hbox.addWidget(QLabel("Field:")) model = self.browser.mw.col.getNote(self.nids[0]).model() field_names = self.browser.mw.col.models.fieldNames(model) self.field_selection = QComboBox() self.field_selection.addItems(field_names) hbox.addWidget(self.field_selection) return hbox
def setupTags(self): import aqt.tagedit g = QGroupBox(self.widget) g.setFlat(True) tb = QGridLayout() tb.setSpacing(12) tb.setContentsMargins(6,6,6,6) # tags l = QLabel(_("Tags")) tb.addWidget(l, 1, 0) self.tags = aqt.tagedit.TagEdit(self.widget) self.tags.lostFocus.connect(self.saveTags) self.tags.setToolTip(shortcut(_("Jump to tags with Ctrl+Shift+T"))) tb.addWidget(self.tags, 1, 1) g.setLayout(tb) self.outerLayout.addWidget(g)
def get_id_and_pass_from_user(mw: aqt.main.AnkiQt, username: str = "", password: str = "") -> tuple[str, str]: diag = QDialog(mw) diag.setWindowTitle("Anki") disable_help_button(diag) diag.setWindowModality(Qt.WindowModality.WindowModal) vbox = QVBoxLayout() info_label = QLabel( without_unicode_isolation( tr.sync_account_required( link="https://ankiweb.net/account/register"))) info_label.setOpenExternalLinks(True) info_label.setWordWrap(True) vbox.addWidget(info_label) vbox.addSpacing(20) g = QGridLayout() l1 = QLabel(tr.sync_ankiweb_id_label()) g.addWidget(l1, 0, 0) user = QLineEdit() user.setText(username) g.addWidget(user, 0, 1) l2 = QLabel(tr.sync_password_label()) g.addWidget(l2, 1, 0) passwd = QLineEdit() passwd.setText(password) passwd.setEchoMode(QLineEdit.EchoMode.Password) g.addWidget(passwd, 1, 1) vbox.addLayout(g) bb = QDialogButtonBox( QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) # type: ignore bb.button(QDialogButtonBox.StandardButton.Ok).setAutoDefault(True) qconnect(bb.accepted, diag.accept) qconnect(bb.rejected, diag.reject) vbox.addWidget(bb) diag.setLayout(vbox) diag.show() accepted = diag.exec() if not accepted: return ("", "") return (user.text().strip(), passwd.text())
def get_id_and_pass_from_user(mw: aqt.main.AnkiQt, username="", password="") -> Tuple[str, str]: diag = QDialog(mw) diag.setWindowTitle("Anki") diag.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore diag.setWindowModality(Qt.WindowModal) vbox = QVBoxLayout() info_label = QLabel( without_unicode_isolation( tr(TR.SYNC_ACCOUNT_REQUIRED, link="https://ankiweb.net/account/register"))) info_label.setOpenExternalLinks(True) info_label.setWordWrap(True) vbox.addWidget(info_label) vbox.addSpacing(20) g = QGridLayout() l1 = QLabel(tr(TR.SYNC_ANKIWEB_ID_LABEL)) g.addWidget(l1, 0, 0) user = QLineEdit() user.setText(username) g.addWidget(user, 0, 1) l2 = QLabel(tr(TR.SYNC_PASSWORD_LABEL)) g.addWidget(l2, 1, 0) passwd = QLineEdit() passwd.setText(password) passwd.setEchoMode(QLineEdit.Password) g.addWidget(passwd, 1, 1) vbox.addLayout(g) bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) # type: ignore bb.button(QDialogButtonBox.Ok).setAutoDefault(True) qconnect(bb.accepted, diag.accept) qconnect(bb.rejected, diag.reject) vbox.addWidget(bb) diag.setLayout(vbox) diag.show() accepted = diag.exec_() if not accepted: return ("", "") return (user.text().strip(), passwd.text())
def setupModels(self): if self.label: self.modelLabel = QLabel(_("Type")) self.addWidget(self.modelLabel) # models box self.models = QPushButton() #self.models.setStyleSheet("* { text-align: left; }") self.models.setToolTip(shortcut(_("Change Note Type (Ctrl+N)"))) s = QShortcut(QKeySequence(_("Ctrl+N")), self.widget, activated=self.onModelChange) self.models.setAutoDefault(False) self.addWidget(self.models) self.models.clicked.connect(self.onModelChange) # layout sizePolicy = QSizePolicy(QSizePolicy.Policy(7), QSizePolicy.Policy(0)) self.models.setSizePolicy(sizePolicy) self.updateModels()
def chooseList(prompt, choices, startrow=0, parent=None): if not parent: parent = aqt.mw.app.activeWindow() d = QDialog(parent) d.setWindowModality(Qt.WindowModal) l = QVBoxLayout() d.setLayout(l) t = QLabel(prompt) l.addWidget(t) c = QListWidget() c.addItems(choices) c.setCurrentRow(startrow) l.addWidget(c) bb = QDialogButtonBox(QDialogButtonBox.Ok) bb.accepted.connect(d.accept) l.addWidget(bb) d.exec_() return c.currentRow()
def create_menu_entry(view, e, parentmenu): t = my_label_text(e, True) y = QLabel(t) # https://stackoverflow.com/a/6876509 y.setAutoFillBackground(True) stylesheet = return_stylesheet(e) y.setStyleSheet(stylesheet) x = QWidgetAction(parentmenu) x.setDefaultWidget(y) cat = e["Category"] se = e.get("Setting", e.get("Category", False)) x.triggered.connect( lambda _, a=cat, b=se: my_highlight_helper(view, a, b)) # ??? return x
def _getUserPass(self): d = QDialog(self.mw) d.setWindowTitle("Anki") d.setWindowModality(Qt.WindowModal) vbox = QVBoxLayout() l = QLabel( _("""\ <h1>Account Required</h1> A free account is required to keep your collection synchronized. Please \ <a href="%s">sign up</a> for an account, then \ enter your details below.""") % "https://ankiweb.net/account/login") l.setOpenExternalLinks(True) l.setWordWrap(True) vbox.addWidget(l) vbox.addSpacing(20) g = QGridLayout() l1 = QLabel(_("AnkiWeb ID:")) g.addWidget(l1, 0, 0) user = QLineEdit() g.addWidget(user, 0, 1) l2 = QLabel(_("Password:")) g.addWidget(l2, 1, 0) passwd = QLineEdit() passwd.setEchoMode(QLineEdit.Password) g.addWidget(passwd, 1, 1) vbox.addLayout(g) bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) bb.button(QDialogButtonBox.Ok).setAutoDefault(True) bb.accepted.connect(d.accept) bb.rejected.connect(d.reject) vbox.addWidget(bb) d.setLayout(vbox) d.show() accepted = d.exec_() u = user.text() p = passwd.text() if not accepted or not u or not p: return return (u, p)
def getDefinitionChoiceDialog(aw, entries): d = QDialog(aw) grid = QGridLayout() # adds found definitions to dialog window for x in range(len(entries)): button = QPushButton(entries[x].word) button.clicked.connect(partial(buttonPressed, entries[x],d)) label = QLabel() label.setText(entries[x].shortDef) label.setWordWrap(True) grid.addWidget(button,x,0) grid.addWidget(label,x,1,1,5) d.setLayout(grid) return d
def setup_evernote(self): global icoEvernoteWeb global imgEvernoteWeb global elements global evernote_query_last_updated global evernote_pagination_current_page_spinner def update_checkbox(setting): if setting is DECKS.EVERNOTE_NOTEBOOK_INTEGRATION and not elements[DECKS.BASE].text(): return if setting.get.startswith(QUERY.get): update_evernote_query_visibilities() setting.save(elements[setting].isChecked()) # mw.col.conf[setting] = if setting is QUERY.USE_TAGS: update_evernote_query_visibilities() if setting is QUERY.LAST_UPDATED.USE: evernote_query_last_updated_value_set_visibilities() def create_checkbox(setting, label=" ", default_value=False, is_fixed_size=False, fixed_width=None): if isinstance(label, bool): default_value = label label = " " checkbox = QCheckBox(label, self) sval = setting.fetch() if not isinstance(sval, bool): sval = default_value checkbox.setChecked(sval) # noinspection PyUnresolvedReferences checkbox.stateChanged.connect(lambda: update_checkbox(setting)) if is_fixed_size or fixed_width: checkbox.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) if fixed_width: checkbox.setFixedWidth(fixed_width) elements[setting] = checkbox return checkbox def create_checked_checkbox(*a, **kw): kw['default_value'] = True return create_checkbox(*a, **kw) def update_text(setting, text): text = text.strip() setting.save(text) if setting is DECKS.BASE: update_anki_deck_visibilities() if setting.get.startswith(QUERY.get): if text: use_key = getattr(QUERY, 'USE_' + setting.label.name) elements[use_key].setChecked(True) evernote_query_text_changed() if setting is QUERY.SEARCH_TERMS: update_evernote_query_visibilities() def create_textbox(setting, default_value=""): textbox = QLineEdit() textbox.setText(setting.fetch(default_value)) textbox.connect(textbox, SIGNAL("textEdited(QString)"), lambda text: update_text(setting, text)) elements[setting] = textbox return textbox def add_query_row(setting, is_checked=False, **kw): try: default_value = setting.val except: default_value = '' row_label = ' '.join(x.capitalize() for x in setting.replace('_', ' ').split()) hbox = QHBoxLayout() hbox.addWidget(create_checkbox(getattr(QUERY, 'USE_' + setting), default_value=is_checked, **kw)) hbox.addWidget(create_textbox(getattr(QUERY, setting), default_value)) form.addRow(row_label, hbox) def gen_qt_hr(): vbox = QVBoxLayout() hr = QFrame() hr.setAutoFillBackground(True) hr.setFrameShape(QFrame.HLine) hr.setStyleSheet("QFrame { background-color: #0060bf; color: #0060bf; }") hr.setFixedHeight(2) vbox.addWidget(hr) vbox.addSpacing(4) return vbox # Begin setup_evernote() widget = QWidget() layout = QVBoxLayout() elements = {} rm_log_path('Dicts\\') evernote_query_last_updated = DictCaseInsensitive() ########################## QUERY ########################## ##################### QUERY: TEXTBOXES #################### group = QGroupBox("EVERNOTE SEARCH OPTIONS:") group.setStyleSheet('QGroupBox{ font-size: 10px; font-weight: bold; color: rgb(105, 170, 53);}') form = QFormLayout() form.addRow(gen_qt_hr()) # Show Generated Evernote Query Button button_show_generated_evernote_query = QPushButton(icoEvernoteWeb, "Show Full Query", self) button_show_generated_evernote_query.setAutoDefault(False) button_show_generated_evernote_query.connect(button_show_generated_evernote_query, SIGNAL("clicked()"), handle_show_generated_evernote_query) # Add Form Row for Match Any Terms hbox = QHBoxLayout() hbox.addWidget(create_checked_checkbox(QUERY.ANY, " Match Any Terms", is_fixed_size=True)) hbox.addWidget(button_show_generated_evernote_query) form.addRow("<b>Search Parameters:</b>", hbox) # Add Form Rows for Evernote Query Textboxes for el in QUERY_TEXTBOXES: add_query_row(el, 'TAGS' in el) ################### QUERY: LAST UPDATED ################### # Evernote Query: Last Updated Type evernote_query_last_updated.type = QComboBox() evernote_query_last_updated.type.setStyleSheet(' QComboBox { color: rgb(45, 79, 201); font-weight: bold; } ') evernote_query_last_updated.type.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) evernote_query_last_updated.type.addItems([u"Δ Day", u"Δ Week", u"Δ Month", u"Δ Year", "Date", "+ Time"]) evernote_query_last_updated.type.setCurrentIndex(QUERY.LAST_UPDATED.TYPE.fetch(EvernoteQueryLocationType.RelativeDay)) evernote_query_last_updated.type.activated.connect(update_evernote_query_last_updated_type) # Evernote Query: Last Updated Type: Relative Date evernote_query_last_updated.value.relative.spinner = EvernoteQueryLocationValueQSpinBox() evernote_query_last_updated.value.relative.spinner.setVisible(False) evernote_query_last_updated.value.relative.spinner.setStyleSheet( " QSpinBox, EvernoteQueryLocationValueQSpinBox { font-weight: bold; color: rgb(173, 0, 0); } ") evernote_query_last_updated.value.relative.spinner.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) evernote_query_last_updated.value.relative.spinner.connect(evernote_query_last_updated.value.relative.spinner, SIGNAL("valueChanged(int)"), update_evernote_query_last_updated_value_relative_spinner) # Evernote Query: Last Updated Type: Absolute Date evernote_query_last_updated.value.absolute.date = QDateEdit() evernote_query_last_updated.value.absolute.date.setDisplayFormat('M/d/yy') evernote_query_last_updated.value.absolute.date.setCalendarPopup(True) evernote_query_last_updated.value.absolute.date.setVisible(False) evernote_query_last_updated.value.absolute.date.setStyleSheet( "QDateEdit { font-weight: bold; color: rgb(173, 0, 0); } ") evernote_query_last_updated.value.absolute.date.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) evernote_query_last_updated.value.absolute.date.connect(evernote_query_last_updated.value.absolute.date, SIGNAL("dateChanged(QDate)"), update_evernote_query_last_updated_value_absolute_date) # Evernote Query: Last Updated Type: Absolute DateTime evernote_query_last_updated.value.absolute.datetime = QDateTimeEdit() evernote_query_last_updated.value.absolute.datetime.setDisplayFormat('M/d/yy h:mm AP') evernote_query_last_updated.value.absolute.datetime.setCalendarPopup(True) evernote_query_last_updated.value.absolute.datetime.setVisible(False) evernote_query_last_updated.value.absolute.datetime.setStyleSheet( "QDateTimeEdit { font-weight: bold; color: rgb(173, 0, 0); } ") evernote_query_last_updated.value.absolute.datetime.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) evernote_query_last_updated.value.absolute.datetime.connect(evernote_query_last_updated.value.absolute.datetime, SIGNAL("dateTimeChanged(QDateTime)"), update_evernote_query_last_updated_value_absolute_datetime) # Evernote Query: Last Updated Type: Absolute Time evernote_query_last_updated.value.absolute.time = QTimeEdit() evernote_query_last_updated.value.absolute.time.setDisplayFormat('h:mm AP') evernote_query_last_updated.value.absolute.time.setVisible(False) evernote_query_last_updated.value.absolute.time.setStyleSheet( "QTimeEdit { font-weight: bold; color: rgb(143, 0, 30); } ") evernote_query_last_updated.value.absolute.time.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) evernote_query_last_updated.value.absolute.time.connect(evernote_query_last_updated.value.absolute.time, SIGNAL("timeChanged(QTime)"), update_evernote_query_last_updated_value_absolute_time) # Create HBox for Separated Date & Time hbox_datetime = QHBoxLayout() hbox_datetime.addWidget(evernote_query_last_updated.value.absolute.date) hbox_datetime.addWidget(evernote_query_last_updated.value.absolute.time) # Evernote Query: Last Updated Type evernote_query_last_updated.value.stacked_layout = QStackedLayout() evernote_query_last_updated.value.stacked_layout.addWidget(evernote_query_last_updated.value.relative.spinner) evernote_query_last_updated.value.stacked_layout.addItem(hbox_datetime) # Add Form Row for Evernote Query: Last Updated hbox = QHBoxLayout() label = QLabel("Last Updated: ") label.setMinimumWidth(SETTINGS.FORM.LABEL_MINIMUM_WIDTH.val) hbox.addWidget(create_checkbox(QUERY.LAST_UPDATED.USE, is_fixed_size=True)) hbox.addWidget(evernote_query_last_updated.type) hbox.addWidget(evernote_query_last_updated.value.relative.spinner) hbox.addWidget(evernote_query_last_updated.value.absolute.date) hbox.addWidget(evernote_query_last_updated.value.absolute.time) form.addRow(label, hbox) # Add Horizontal Row Separator form.addRow(gen_qt_hr()) ############################ PAGINATION ########################## # Evernote Pagination: Current Page evernote_pagination_current_page_spinner = QSpinBox() evernote_pagination_current_page_spinner.setStyleSheet("QSpinBox { font-weight: bold; color: rgb(173, 0, 0); } ") evernote_pagination_current_page_spinner.setPrefix("PAGE: ") evernote_pagination_current_page_spinner.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) evernote_pagination_current_page_spinner.setValue(EVERNOTE.PAGINATION_CURRENT_PAGE.fetch(1)) evernote_pagination_current_page_spinner.connect(evernote_pagination_current_page_spinner, SIGNAL("valueChanged(int)"), update_evernote_pagination_current_page_spinner) # Evernote Pagination: Automation hbox = QHBoxLayout() hbox.addWidget(create_checked_checkbox(EVERNOTE.AUTO_PAGING, " Automate", fixed_width=105)) hbox.addWidget(evernote_pagination_current_page_spinner) # Add Form Row for Evernote Pagination form.addRow("<b>Pagination:</b>", hbox) # Add Query Form to Group Box group.setLayout(form) # Add Query Group Box to Main Layout layout.addWidget(group) ########################## DECK ########################## # Setup Group Box and Form group = QGroupBox("ANKI NOTE OPTIONS:") group.setStyleSheet('QGroupBox{ font-size: 10px; font-weight: bold; color: rgb(105, 170, 53);}') form = QFormLayout() # Add Horizontal Row Separator form.addRow(gen_qt_hr()) # Add Form Row for Default Anki Deck hbox = QHBoxLayout() hbox.insertSpacing(0, 33) hbox.addWidget(create_textbox(DECKS.BASE, DECKS.BASE_DEFAULT_VALUE)) label_deck = QLabel("<b>Anki Deck:</b>") label_deck.setMinimumWidth(SETTINGS.FORM.LABEL_MINIMUM_WIDTH.val) form.addRow(label_deck, hbox) # Add Form Row for Evernote Notebook Integration label_deck = QLabel("Evernote Notebook:") label_deck.setMinimumWidth(SETTINGS.FORM.LABEL_MINIMUM_WIDTH.val) form.addRow("", create_checked_checkbox(DECKS.EVERNOTE_NOTEBOOK_INTEGRATION, " Append Evernote Notebook")) # Add Horizontal Row Separator form.addRow(gen_qt_hr()) ############################ TAGS ########################## # Add Form Row for Evernote Tag Options label = QLabel("<b>Evernote Tags:</b>") label.setMinimumWidth(SETTINGS.FORM.LABEL_MINIMUM_WIDTH.val) # Tags: Save To Anki Note form.addRow(label, create_checkbox(TAGS.KEEP_TAGS, " Save To Anki Note", TAGS.KEEP_TAGS_DEFAULT_VALUE)) hbox = QHBoxLayout() hbox.insertSpacing(0, 33) hbox.addWidget(create_textbox(TAGS.TO_DELETE)) # Tags: Tags To Delete form.addRow("Tags to Delete:", hbox) form.addRow(" ", create_checkbox(TAGS.DELETE_EVERNOTE_QUERY_TAGS, " Also Delete Search Tags")) # Add Horizontal Row Separator form.addRow(gen_qt_hr()) ############################ NOTE UPDATING ########################## # Note Update Method update_existing_notes = QComboBox() update_existing_notes.setStyleSheet( ' QComboBox { color: #3b679e; font-weight: bold; } QComboBoxItem { color: #A40F2D; font-weight: bold; } ') update_existing_notes.addItems(["Ignore Existing Notes", "Update In-Place", "Delete and Re-Add"]) sval = ANKI.UPDATE_EXISTING_NOTES.fetch() if not isinstance(sval, int): sval = ANKI.UPDATE_EXISTING_NOTES.val update_existing_notes.setCurrentIndex(sval) update_existing_notes.activated.connect(update_update_existing_notes) # Add Form Row for Note Update Method hbox = QHBoxLayout() hbox.insertSpacing(0, 33) hbox.addWidget(update_existing_notes) form.addRow("<b>Note Updating:</b>", hbox) # Add Note Update Method Form to Group Box group.setLayout(form) # Add Note Update Method Group Box to Main Layout layout.addWidget(group) ######################### UPDATE VISIBILITIES ####################### # Update Visibilities of Anki Deck Options update_anki_deck_visibilities() # Update Visibilities of Query Options evernote_query_text_changed() update_evernote_query_visibilities() ######################## ADD TO SETTINGS PANEL ###################### # Vertical Spacer vertical_spacer = QSpacerItem(20, 0, QSizePolicy.Minimum, QSizePolicy.Expanding) layout.addItem(vertical_spacer) # Parent Widget widget.setLayout(layout) # New Tab self.form.tabWidget.addTab(widget, "Anknotes")