def __init__(
        self,
        text: str,
        settings: NotificationSettings = NotificationSettings(),
        parent: Optional[QWidget] = None,
        **kwargs,
    ):
        super().__init__(text, parent=parent, **kwargs)
        self._settings = settings

        self.setFrameStyle(QFrame.Shape.Panel)
        self.setLineWidth(2)
        self.setWindowFlags(Qt.WindowType.ToolTip)
        self.setContentsMargins(10, 10, 10, 10)

        palette = QPalette()
        palette.setColor(QPalette.ColorRole.Window,
                         QColor(self._settings.bg_color))
        palette.setColor(QPalette.ColorRole.WindowText,
                         QColor(self._settings.fg_color))
        self.setPalette(palette)

        if parent and self._settings.focus_behavior != FocusBehavior.always_on_top:
            app: "AnkiApp" = QApplication.instance(
            )  # type: ignore[assignment]
            app.focusChanged.connect(self._on_app_focus_changed)
Beispiel #2
0
 def __init__(self, mw):
     self.mw = mw
     self.app = QApplication.instance()
     self.inDB = False
     self.blockUpdates = False
     self._win = None
     self._levels = 0
Beispiel #3
0
 def _setHtml(self, html):
     app = QApplication.instance()
     oldFocus = app.focusWidget()
     self._domDone = False
     self._page.setHtml(html)
     # work around webengine stealing focus on setHtml()
     if oldFocus:
         oldFocus.setFocus()
Beispiel #4
0
    def gotoLocalFile(self, rootHtmlPath):
        rootHtmlPath = getResourcePath(rootHtmlPath)

        # Code from AnkiWebView::_setHtml
        app = QApplication.instance()

        # work around webengine stealing focus on setHtml()
        oldFocus = app.focusWidget()
        self.web._page.setUrl(QUrl.fromLocalFile(rootHtmlPath))
        if oldFocus:
            oldFocus.setFocus()
Beispiel #5
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()