Exemplo n.º 1
0
 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))
Exemplo n.º 2
0
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
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
def get_grid_layout(form) -> QWidget:
    w = QWidget()

    gridLayout = QGridLayout()
    gridLayout.setColumnStretch(1, 5)
    gridLayout.setContentsMargins(0, 0, 0, 5)

    ##### STRAIGHT LENGTH
    form.straightLengthLabel = make_label(w, "Begin at straight of length")
    gridLayout.addWidget(form.straightLengthLabel, 1, 0, 1, 1)

    form.straightLengthSpinBox = make_spin_box(w, 0, 100, "")
    gridLayout.addWidget(form.straightLengthSpinBox, 1, 1, 1, 2)

    ##### BASE EASE
    form.straightBaseEaseLabel = make_label(w, "Base ease reward")
    gridLayout.addWidget(form.straightBaseEaseLabel, 2, 0, 1, 1)

    form.straightBaseEaseSpinBox = make_spin_box(w)
    gridLayout.addWidget(form.straightBaseEaseSpinBox, 2, 1, 1, 2)

    ##### STEP EASE
    form.straightStepEaseLabel = make_label(w, "Step ease reward")
    gridLayout.addWidget(form.straightStepEaseLabel, 3, 0, 1, 1)

    form.straightStepEaseSpinBox = make_spin_box(w)
    gridLayout.addWidget(form.straightStepEaseSpinBox, 3, 1, 1, 2)

    ##### START EASE
    form.straightStartEaseLabel = make_label(w, "Start at ease")
    gridLayout.addWidget(form.straightStartEaseLabel, 4, 0, 1, 1)

    form.straightStartEaseSpinBox = make_spin_box(w, 130)
    gridLayout.addWidget(form.straightStartEaseSpinBox, 4, 1, 1, 2)

    ##### STOP EASE
    form.straightStopEaseLabel = make_label(w, "Stop at ease")
    gridLayout.addWidget(form.straightStopEaseLabel, 5, 0, 1, 1)

    form.straightStopEaseSpinBox = make_spin_box(w, 130)
    gridLayout.addWidget(form.straightStopEaseSpinBox, 5, 1, 1, 2)

    w.setLayout(gridLayout)

    return w
Exemplo n.º 5
0
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())
Exemplo n.º 6
0
Arquivo: sync.py Projeto: rye761/anki
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())
Exemplo n.º 7
0
def _rebuildMap(self, key):
    """
    key -- either "t" or "f", for template or fields. What to edit.

    """
    map = getattr(self, key + "widg")
    lay = getattr(self, key + "layout")
    if map:
        lay.removeWidget(map)
        map.deleteLater()
        setattr(self, key + "MapWidget", None)
    map = QWidget()
    l = QGridLayout()
    combos = []
    targets = [template['name'] for template in getattr(self, key + "dst")]
    indices = {}
    sources = getattr(self, key + "src")
    sourcesNames = [template["name"] for template in sources]
    if getUserOption("Associate to same name"):
        assoc = eltToPos(sourcesNames, targets)
    else:
        assoc = enumerate(sourcesNames)
    for indexSrc, (indexDst, templateName) in enumerate(assoc):
        l.addWidget(QLabel(_("Change %s to:") % templateName), indexSrc, 0)
        cb = QComboBox()
        cb.addItems(targets + [_("Nothing")])
        idx = min(indexDst, len(targets))
        cb.setCurrentIndex(idx)
        indices[cb] = idx
        cb.currentIndexChanged.connect(
            lambda i, cb=cb, key=key: self.onComboChanged(i, cb, key))
        combos.append(cb)
        l.addWidget(cb, indexSrc, 1)
    map.setLayout(l)
    lay.addWidget(map)
    setattr(self, key + "widg", map)
    setattr(self, key + "layout", lay)
    setattr(self, key + "combos", combos)
    setattr(self, key + "indices", indices)
Exemplo n.º 8
0
    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 rebuild_template_map(self, key=None, attr=None):
     if not key:
         key = "t"
         attr = "tmpls"
     map_widget = getattr(self, key + "widg")
     layout = getattr(self, key + "layout")
     src = self.old_model[attr]
     dst = self.targetModel[attr]
     if map_widget:
         layout.removeWidget(map_widget)
         map_widget.deleteLater()
         setattr(self, key + "MapWidget", None)
     map_widget = QWidget()
     map_widget_layout = QGridLayout()
     combos = []
     targets = [entity['name'] for entity in dst] + [_("Nothing")]
     indices = {}
     for i, entity in enumerate(src):
         map_widget_layout.addWidget(
             QLabel(_("Change %s to:") % entity['name']), i, 0)
         combo_box = QComboBox()
         combo_box.addItems(targets)
         idx = min(i, len(targets) - 1)
         combo_box.setCurrentIndex(idx)
         indices[combo_box] = idx
         combo_box.currentIndexChanged.connect(
             lambda entry_id: self.on_combo_changed(entry_id, combo_box, key
                                                    ))
         combos.append(combo_box)
         map_widget_layout.addWidget(combo_box, i, 1)
     map_widget.setLayout(map_widget_layout)
     layout.addWidget(map_widget)
     setattr(self, key + "widg", map_widget)
     setattr(self, key + "layout", layout)
     setattr(self, key + "combos", combos)
     setattr(self, key + "indices", indices)
Exemplo n.º 10
0
 def __init__(self, parent, tags, alltags):
     QDialog.__init__(self, parent,
                      Qt.WindowType.Window)  # super().__init__(parent)
     self.basic_mode = gc("dialog type: basic_but_quick")
     self.parent = parent
     self.alltags = alltags
     self.gridLayout = QGridLayout(self)
     self.gridLayout.setObjectName("gridLayout")
     self.label = QLabel("Edit tags:")
     self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
     self.verticalLayout = QVBoxLayout()
     self.verticalLayout.setObjectName("verticalLayout")
     self.gridLayout.addLayout(self.verticalLayout, 1, 0, 1, 1)
     self.buttonBox = QDialogButtonBox(self)
     self.buttonBox.setOrientation(Qt.Orientation.Horizontal)
     self.buttonBox.setStandardButtons(
         QDialogButtonBox.StandardButton.Cancel
         | QDialogButtonBox.StandardButton.Ok)
     self.shortcut = QShortcut(QKeySequence("Ctrl+Return"), self)
     self.shortcut.activated.connect(self.accept)
     self.helpButton = QPushButton(
         "add empty line", clicked=lambda: self.maybe_add_line(force=True))
     self.buttonBox.addButton(self.helpButton,
                              QDialogButtonBox.ButtonRole.HelpRole)
     self.filterbutton = QPushButton("edit tag for current line",
                                     clicked=self.tagselector)
     self.buttonBox.addButton(self.filterbutton,
                              QDialogButtonBox.ButtonRole.ResetRole)
     self.searchButton = QPushButton(
         "search", clicked=lambda: self.do_browser_search(extra_search=""))
     self.buttonBox.addButton(self.searchButton,
                              QDialogButtonBox.ButtonRole.ResetRole)
     self.gridLayout.addWidget(self.buttonBox, 2, 0, 1, 1)
     self.buttonBox.accepted.connect(self.accept)
     self.buttonBox.rejected.connect(self.reject)
     self.setWindowTitle("Anki - Edit Tags")
     originalheight = self.height()
     restoreGeom(self, "TagDialogExtended")
     self.resize(self.width(), originalheight)
     if not tags:
         tags = [
             "",
         ]
     else:
         tags.append("")
     self.line_list = []
     for t in tags:
         self.maybe_add_line(t)
     self.cut = gc("in tag lines dialog: open filterdialog for single tag")
     if self.cut:
         self.filterbutton.setToolTip('shortcut: {}'.format(self.cut))
         self.selkey = QShortcut(QKeySequence(self.cut), self)
         self.selkey.activated.connect(self.tagselector)
     self.browser_scut = gc("in tag lines dialog: search browser for tag")
     if self.browser_scut:
         self.searchButton.setToolTip('shortcut: {}'.format(
             self.browser_scut))
         self.browser_scut_key = QShortcut(QKeySequence(self.browser_scut),
                                           self)
         self.browser_scut_key.activated.connect(
             lambda: self.do_browser_search(extra_search=""))
     # don't also set Ctrl+t,a/gc("editor: show filterdialog to add single tag") for
     # self.tagselector: What if the user has already set them to the same etc. I'd have
     # to do a lot of checking
     self.addnl = gc("in tag lines dialog: insert additional line")
     if self.addnl:
         self.helpButton.setToolTip('shortcut: {}'.format(self.addnl))
         self.addnlscut = QShortcut(QKeySequence(self.addnl), self)
         self.addnlscut.activated.connect(
             lambda: self.maybe_add_line(force=True))
Exemplo n.º 11
0
    def _setupUi(self):
        layout = QGridLayout()
        # remove margins
        layout.setContentsMargins(QMargins())
        self.setLayout(layout)

        row = 0

        # 1st row
        label = QLabel(self, text='Lettering:')
        layout.addWidget(label, row, 0, alignment=Qt.AlignRight)

        widget = QLineEdit(self)
        layout.addWidget(widget, row, 1)
        label.setBuddy(widget)
        self.letteringEdit = widget
        row += 1

        # 2nd row
        label = QLabel(self, text='Hint:')
        layout.addWidget(label, row, 0, alignment=Qt.AlignRight)

        widget = QLineEdit(self)
        layout.addWidget(widget, row, 1)
        label.setBuddy(widget)
        self.hintEdit = widget
        row += 1

        # 3rd row
        label = QLabel(self, text='Part of speech:')
        layout.addWidget(label, row, 0, alignment=Qt.AlignRight)

        widget = QLineEdit(self)
        layout.addWidget(widget, row, 1)
        label.setBuddy(widget)
        self.partOfSpeechEdit = widget
        row += 1

        #1-3 row second column
        widget = QTextEdit(self)
        layout.addWidget(widget, 0, 2, 3, 2)
        label.setBuddy(widget)
        self.definitionEdit = widget

        #4th row
        label = QLabel(self, text='Transcription:')
        layout.addWidget(label, row, 0, alignment=Qt.AlignRight | Qt.AlignTop)

        widget = TranscriptionsWidget(self)
        widget.setMaximumHeight(label.sizeHint().height() * 4)
        layout.addWidget(widget, row, 1, 1, 3)
        label.setBuddy(widget)
        self.transcriptionEdit = widget
        row += 2

        #5th row
        label = QLabel(self, text='Examples:')
        layout.addWidget(label, row, 0, 1, 1, alignment=Qt.AlignRight | Qt.AlignTop)

        widget = ExamplesWidget(self)
        layout.addWidget(widget, row, 1, 2, 3)
        label.setBuddy(widget)
        self.examplesEdit = widget
        row += 2