Example #1
0
    def accept(self):
        self.hide()
        n = 0
        yes = []
        no = []
        for c in range(self.dialog.activeList.count()):
            # active
            item = self.dialog.activeList.item(c)
            idx = self.dialog.activeList.indexFromItem(item)
            if self.dialog.activeList.selectionModel().isSelected(idx):
                yes.append(self.tags[c])
            # inactive
            item = self.dialog.inactiveList.item(c)
            idx = self.dialog.inactiveList.indexFromItem(item)
            if self.dialog.inactiveList.selectionModel().isSelected(idx):
                no.append(self.tags[c])

        if self.dialog.activeCheck.isChecked():
            self.deck.setVar(self.active, joinTags(yes))
        else:
            self.deck.setVar(self.active, "")
        if self.dialog.inactiveCheck.isChecked():
            self.deck.setVar(self.inactive, joinTags(no))
        else:
            self.deck.setVar(self.inactive, "")
        self.parent.reset()
        saveGeom(self, "activeTags")
        QDialog.accept(self)
Example #2
0
def getAudio(parent, string=""):
    "Record and return filename"
    # record first
    r = Recorder()
    mb = QMessageBox(parent)
    restoreGeom(mb, "audioRecorder")
    mb.setWindowTitle("Anki")
    mb.setIconPixmap(QPixmap(":/icons/media-record.png"))
    but = QPushButton(_("  Stop"))
    but.setIcon(QIcon(":/icons/media-playback-stop.png"))
    #but.setIconSize(QSize(32, 32))
    mb.addButton(but, QMessageBox.RejectRole)
    t = time.time()
    r.start()
    QApplication.instance().processEvents()
    while not mb.clickedButton():
        txt =_("Recording...<br>Time: %0.1f")
        mb.setText(txt % (time.time() - t))
        mb.show()
        QApplication.instance().processEvents()
    # ensure at least a second captured
    saveGeom(mb, "audioRecorder")
    while time.time() - t < 1:
        time.sleep(0.1)
    r.stop()
    # process
    r.postprocess()
    return r.file()
Example #3
0
 def reject(self):
     modified = False
     self.deck.startProgress()
     self.deck.updateProgress(_("Applying changes..."))
     reset = True
     if self.needFormatRebuild:
         # need to generate q/a templates
         self.deck.updateCardsFromModel(self.fact.model)
         self.deck.finishProgress()
         modified = True
     if len(self.fieldOrdinalUpdatedIds) > 0:
         self.deck.rebuildFieldOrdinals(self.model.id, self.fieldOrdinalUpdatedIds)
         modified = True
     if self.needFieldRebuild:
         modified = True
     if modified:
         self.fact.model.setModified()
         self.deck.flushMod()
         if self.factedit and self.factedit.onChange:
             self.factedit.onChange("all")
             reset = False
     if reset:
         self.mw.reset()
     self.deck.finishProgress()
     saveGeom(self, "CardLayout")
     saveSplitter(self.form.splitter, "clayout")
     QDialog.reject(self)
Example #4
0
    def accept(self):
        self.hide()
        n = 0
        yes = []
        no = []
        for c in range(self.dialog.activeList.count()):
            # active
            item = self.dialog.activeList.item(c)
            idx = self.dialog.activeList.indexFromItem(item)
            if self.dialog.activeList.selectionModel().isSelected(idx):
                yes.append(self.tags[c])
            # inactive
            item = self.dialog.inactiveList.item(c)
            idx = self.dialog.inactiveList.indexFromItem(item)
            if self.dialog.inactiveList.selectionModel().isSelected(idx):
                no.append(self.tags[c])

        if self.dialog.activeCheck.isChecked():
            self.deck.setVar(self.active, joinTags(yes))
        else:
            self.deck.setVar(self.active, "")
        if self.dialog.inactiveCheck.isChecked():
            self.deck.setVar(self.inactive, joinTags(no))
        else:
            self.deck.setVar(self.inactive, "")
        self.parent.reset()
        saveGeom(self, "activeTags")
        QDialog.accept(self)
Example #5
0
def getAudio(parent, string="", encode=True):
    "Record and return filename"
    # record first
    r = Recorder()
    mb = QMessageBox(parent)
    restoreGeom(mb, "audioRecorder")
    mb.setWindowTitle("Anki")
    mb.setIconPixmap(QPixmap(":/icons/media-record.png"))
    but = QPushButton(_("  Stop"))
    but.setIcon(QIcon(":/icons/media-playback-stop.png"))
    #but.setIconSize(QSize(32, 32))
    mb.addButton(but, QMessageBox.RejectRole)
    t = time.time()
    r.start()
    QApplication.instance().processEvents()
    while not mb.clickedButton():
        txt = _("Recording...<br>Time: %0.1f")
        mb.setText(txt % (time.time() - t))
        mb.show()
        QApplication.instance().processEvents()
    # ensure at least a second captured
    saveGeom(mb, "audioRecorder")
    while time.time() - t < 1:
        time.sleep(0.1)
    r.stop()
    # process
    r.postprocess(encode)
    return r.file()
Example #6
0
 def accept(self):
     self.hide()
     n = 0
     yes = []
     no = []
     for c in range(self.dialog.activeList.count()):
         # active
         item = self.dialog.activeList.item(c)
         idx = self.dialog.activeList.indexFromItem(item)
         if self.dialog.activeList.selectionModel().isSelected(idx):
             yes.append(self.tags[c])
         # inactive
         item = self.dialog.inactiveList.item(c)
         idx = self.dialog.inactiveList.indexFromItem(item)
         if self.dialog.inactiveList.selectionModel().isSelected(idx):
             no.append(self.tags[c])
     types = []
     if (self.dialog.newButton.isChecked() or
         self.dialog.bothButton.isChecked()):
         types.append(["newActive", "newInactive"])
     if (self.dialog.revButton.isChecked() or
         self.dialog.bothButton.isChecked()):
         types.append(["revActive", "revInactive"])
     for (active, inactive) in types:
         if self.dialog.activeCheck.isChecked():
             self.deck.setVar(active, joinTags(yes))
         else:
             self.deck.setVar(active, "")
         if self.dialog.inactiveCheck.isChecked():
             self.deck.setVar(inactive, joinTags(no))
         else:
             self.deck.setVar(inactive, "")
     self.parent.reset()
     saveGeom(self, "activeTags")
     QDialog.accept(self)
Example #7
0
 def reject(self):
     modified = False
     self.deck.startProgress()
     self.deck.updateProgress(_("Applying changes..."))
     reset = True
     if self.needFormatRebuild:
         # need to generate q/a templates
         self.deck.updateCardsFromModel(self.fact.model)
         self.deck.finishProgress()
         modified = True
     if len(self.fieldOrdinalUpdatedIds) > 0:
         self.deck.rebuildFieldOrdinals(self.model.id,
                                        self.fieldOrdinalUpdatedIds)
         modified = True
     if self.needFieldRebuild:
         modified = True
     if modified:
         self.fact.model.setModified()
         self.deck.flushMod()
         if self.factedit and self.factedit.onChange:
             self.factedit.onChange("all")
             reset = False
     if reset:
         self.mw.reset()
     self.deck.finishProgress()
     saveGeom(self, "CardLayout")
     saveSplitter(self.form.splitter, "clayout")
     QDialog.reject(self)
Example #8
0
 def accept(self):
     self.selectedCms = []
     for i, item in enumerate(self.items):
         idx = self.dialog.list.indexFromItem(item)
         if self.dialog.list.selectionModel().isSelected(idx):
             self.selectedCms.append(self.cms[i][0])
     saveGeom(self, "addCardModels")
     QDialog.accept(self)
Example #9
0
 def accept(self):
     saveGeom(self, "changeModel")
     self.parent.deck.currentModel = self.origModel
     # check maps
     fmap = self.getFieldMap()
     cmap = self.getTemplateMap()
     if not cmap or (self.targetModel != self.oldModel and
                     not fmap):
         return ui.utils.showInfo(
             _("Targets must be unique."), parent=self)
     if self.targetModel == self.oldModel:
         self.ret = (self.targetModel, None, cmap)
         return QDialog.accept(self)
     self.modelChooser.deinit()
     self.ret = (self.targetModel, fmap, cmap)
     return QDialog.accept(self)
Example #10
0
 def onClose(self):
     removeHook('guiReset', self.modelChanged)
     # stop anything playing
     clearAudioQueue()
     if (self.forceClose or self.editor.fieldsAreBlank() or
         ui.utils.askUser(_("Close and lose current input?"),
                         self)):
         self.editor.close()
         ui.dialogs.close("AddCards")
         self.parent.deck.s.flush()
         self.parent.deck.rebuildCSS()
         self.parent.moveToState("auto")
         saveGeom(self, "add")
         saveSplitter(self.dialog.splitter, "add")
         return True
     else:
         return False
Example #11
0
 def accept(self):
     self.hide()
     self.deck.startProgress()
     n = 0
     suspended = []
     for item in self.items:
         idx = self.dialog.list.indexFromItem(item)
         if self.dialog.list.selectionModel().isSelected(idx):
             suspended.append(self.tags[n])
         n += 1
     self.deck.suspended = canonifyTags(joinTags(suspended + ["Suspended"]))
     self.deck.setModified()
     self.deck.updateAllPriorities(partial=True)
     self.parent.reset()
     saveGeom(self, "activeTags")
     self.deck.finishProgress()
     QDialog.accept(self)
Example #12
0
 def onClose(self):
     removeHook('guiReset', self.modelChanged)
     # stop anything playing
     clearAudioQueue()
     if (self.forceClose or self.editor.fieldsAreBlank() or
         ui.utils.askUser(_("Close and lose current input?"),
                         self)):
         self.modelChooser.deinit()
         self.editor.close()
         ui.dialogs.close("AddCards")
         self.parent.deck.s.flush()
         self.parent.deck.rebuildCSS()
         self.parent.reset()
         saveGeom(self, "add")
         saveSplitter(self.dialog.splitter, "add")
         return True
     else:
         return False
Example #13
0
 def onClose(self):
     saveSplitter(self.dialog.splitter, "editor")
     self.editor.saveFieldsNow()
     if not self.forceClose:
         if not self.factValid:
             ui.utils.showInfo(_(
                 "Some fields are missing or not unique."),
                               parent=self, help="AddItems#AddError")
             return
     self.editor.setFact(None)
     self.editor.close()
     saveGeom(self, "editor")
     saveHeader(self.dialog.tableView.horizontalHeader(), "editor")
     self.hide()
     ui.dialogs.close("CardList")
     if self.parent.currentCard:
         self.parent.moveToState("showQuestion")
     else:
         self.parent.moveToState("auto")
     self.teardownHooks()
     return True
Example #14
0
 def reject(self):
     saveGeom(self, "preview")
     QDialog.reject(self)
Example #15
0
 def reject(self):
     saveGeom(self, "graphs")
     ui.dialogs.close("Graphs")
     QDialog.reject(self)
Example #16
0
 def reject(self):
     saveGeom(self, "graphs")
     ui.dialogs.close("Graphs")
     QDialog.reject(self)