Ejemplo n.º 1
0
def showInfo(text, parent=False, help="", type="info", title="Anki", textFormat=None):
    "Show a small info window with an OK button."
    if parent is False:
        parent = aqt.mw.app.activeWindow() or aqt.mw
    if type == "warning":
        icon = QMessageBox.Warning
    elif type == "critical":
        icon = QMessageBox.Critical
    else:
        icon = QMessageBox.Information
    mb = QMessageBox(parent)
    if textFormat == "plain":
        mb.setTextFormat(Qt.PlainText)
    elif textFormat == "rich":
        mb.setTextFormat(Qt.RichText)
    elif textFormat is not None:
        raise Exception("unexpected textFormat type")
    mb.setText(text)
    mb.setIcon(icon)
    mb.setWindowTitle(title)
    b = mb.addButton(QMessageBox.Ok)
    b.setDefault(True)
    if help:
        b = mb.addButton(QMessageBox.Help)
        b.clicked.connect(lambda: openHelp(help))
        b.setAutoDefault(False)
    return mb.exec_()
Ejemplo n.º 2
0
def showInfo(message, parent=None, mode="info", title="Anki"):
    if mode == "info":
        icon = QMessageBox.Information
    elif mode == "warning":
        icon = QMessageBox.Warning
    elif mode == "critical":
        icon = QMessageBox.Critical

    return QMessageBox(icon, title, message, parent=parent)
Ejemplo n.º 3
0
    def unlockPopup(self, countryName, cityName):
        msgBox = QMessageBox()
        city = self.buildingAuthority.getCity(countryName, cityName)
        msgBox.setText("Do you want to unlock %s for %s Gold?" %
                       (city.getName(), city.getPrice()))
        msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
        msgBox.setDefaultButton(QMessageBox.Ok)
        choice = msgBox.exec_()

        if choice == QMessageBox.Ok:

            if self.buildingAuthority.unlockCity(city) is False:
                self.constructionView(countryName, cityName)
Ejemplo n.º 4
0
def showInfo(message,
             title="Anknotes: Evernote Importer for Anki",
             textFormat=0,
             cancelButton=False,
             richText=False,
             minHeight=None,
             minWidth=400,
             styleSheet=None,
             convertNewLines=True):
    global imgEvernoteWebMsgBox, icoEvernoteArtcore, icoEvernoteWeb
    msgDefaultButton = QPushButton(icoEvernoteArtcore, "Okay!", mw)

    if not styleSheet:
        styleSheet = file(FILES.ANCILLARY.CSS_QMESSAGEBOX, 'r').read()

    if not is_str_type(message):
        message = str(message)

    if richText:
        textFormat = 1
        message = '<style>\n%s</style>\n\n%s' % (styleSheet, message)
    global messageBox
    messageBox = QMessageBox()
    messageBox.addButton(msgDefaultButton, QMessageBox.AcceptRole)
    if cancelButton:
        msgCancelButton = QPushButton(icoTomato, "No Thanks", mw)
        messageBox.addButton(msgCancelButton, QMessageBox.RejectRole)
    messageBox.setDefaultButton(msgDefaultButton)
    messageBox.setIconPixmap(imgEvernoteWebMsgBox)
    messageBox.setTextFormat(textFormat)

    messageBox.setWindowIcon(icoEvernoteWeb)
    messageBox.setWindowIconText("Anknotes")
    messageBox.setText(message)
    messageBox.setWindowTitle(title)
    hSpacer = QSpacerItem(minWidth, 0, QSizePolicy.Minimum,
                          QSizePolicy.Expanding)

    layout = messageBox.layout()
    """:type : QGridLayout """
    layout.addItem(hSpacer, layout.rowCount() + 1, 0, 1, layout.columnCount())
    ret = messageBox.exec_()
    if not cancelButton:
        return True
    if messageBox.clickedButton(
    ) == msgCancelButton or messageBox.clickedButton() == 0:
        return False
    return True
Ejemplo n.º 5
0
def askAndUpdate(mw, ver):
    baseStr = (
        _('''<h1>Anki Updated</h1>Anki %s has been released.<br><br>''') % ver)
    msg = QMessageBox(mw)
    msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
    msg.setIcon(QMessageBox.Information)
    msg.setText(baseStr + _("Would you like to download it now?"))
    button = QPushButton(_("Ignore this update"))
    msg.addButton(button, QMessageBox.RejectRole)
    msg.setDefaultButton(QMessageBox.Yes)
    ret = msg.exec_()
    if msg.clickedButton() == button:
        # ignore this update
        mw.pm.meta['suppressUpdate'] = ver
    elif ret == QMessageBox.Yes:
        openLink(aqt.appWebsite)
Ejemplo n.º 6
0
    def answerCard(self, Reviewer, card, ease):

        if self.__options.getOption("pluginEnabled"):
            self.setQuality(ease)
            cardsAnsweredToday = self.__stats.cardAnswered(self.__lastQuality)
            self.__stats.save()

            # Update the building process
            self.__buildingAuthority.updateBuildingProgress(
                self.__lastQuality, cardsAnsweredToday)
            self.__buildingAuthority.save()

            # Update rank
            self.__ranks.updateRank(
                self.__treasureChest.getTotalGold(),
                self.__buildingAuthority.getActiveCountry().
                getCompletedObjectsPercentage(),
                False,
            )

            # Display popup and perform event action whenever a major event has occured
            event = self.__eventManager.getNextEvent()

            if event:
                msg = QMessageBox()
                msg.setIcon(QMessageBox.NoIcon)
                msg.setWindowTitle(getPluginName())
                msg.setText(event.performEventAndGetText())
                msg.addButton("OK", QMessageBox.AcceptRole)
                msg.exec_()

            # calculate earned gold
            self.__treasureChest.updateGold(card, self.__lastQuality,
                                            cardsAnsweredToday, False)
            self.__treasureChest.save()

            self.open_main()
Ejemplo n.º 7
0
def getAudio(parent, encode=True):
    "Record and return filename"
    # record first
    if not Recorder:
        showWarning("pyaudio not installed")
        return

    r = Recorder()
    mb = QMessageBox(parent)
    restoreGeom(mb, "audioRecorder")
    mb.setWindowTitle("Anki")
    mb.setIconPixmap(QPixmap(":/icons/media-record.png"))
    but = QPushButton(_("Save"))
    mb.addButton(but, QMessageBox.AcceptRole)
    but = QPushButton(_("Cancel"))
    mb.addButton(but, QMessageBox.RejectRole)
    mb.setEscapeButton(but)
    t = time.time()
    r.start()
    time.sleep(r.startupDelay)
    QApplication.instance().processEvents()
    while not mb.clickedButton():
        txt = _("Recording...<br>Time: %0.1f")
        mb.setText(txt % (time.time() - t))
        mb.show()
        QApplication.instance().processEvents()
    if mb.clickedButton() == mb.escapeButton():
        r.stop()
        return
    saveGeom(mb, "audioRecorder")
    # ensure at least a second captured
    while time.time() - t < 1:
        time.sleep(0.1)
    r.stop()
    # process
    r.postprocess(encode)
    return r.file()
Ejemplo n.º 8
0
 def links(self, handled, message, context):
     QMessageBox(self)
     raise Exception("HIDE")
     ret = self.process_request(json.loads(message), context)
     return (True, ret)