Exemple #1
0
 def show_devtools(self):
     if not hasattr(self, '_devtools_page'):
         self._devtools_page = QWebEnginePage()
         self._devtools_view = QWebEngineView(self)
         self._devtools_view.setPage(self._devtools_page)
         self._page.setDevToolsPage(self._devtools_page)
         self._devtools_dialog = d = QDialog(self)
         d.setWindowTitle('Inspect Lookup page')
         v = QVBoxLayout(d)
         v.addWidget(self._devtools_view)
         d.bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
         d.bb.rejected.connect(d.reject)
         v.addWidget(d.bb)
         d.resize(QSize(800, 600))
         d.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose, False)
     self._devtools_dialog.show()
     self._page.triggerAction(QWebEnginePage.WebAction.InspectElement)
Exemple #2
0
    def test_qt(self):
        if is_sanitized:
            raise unittest.SkipTest('Skipping Qt build test as sanitizer is enabled')
        from qt.core import QTimer
        from qt.core import QApplication
        from qt.webengine import QWebEnginePage
        from qt.core import QImageReader, QFontDatabase
        from qt.core import QNetworkAccessManager
        from calibre.utils.img import image_from_data, image_to_data, test
        # Ensure that images can be read before QApplication is constructed.
        # Note that this requires QCoreApplication.libraryPaths() to return the
        # path to the Qt plugins which it always does in the frozen build,
        # because Qt is patched to know the layout of the calibre application
        # package. On non-frozen builds, it should just work because the
        # hard-coded paths of the Qt installation should work. If they do not,
        # then it is a distro problem.
        fmts = set(map(lambda x: x.data().decode('utf-8'), QImageReader.supportedImageFormats()))  # no2to3
        testf = {'jpg', 'png', 'svg', 'ico', 'gif', 'webp'}
        self.assertEqual(testf.intersection(fmts), testf, "Qt doesn't seem to be able to load some of its image plugins. Available plugins: %s" % fmts)
        data = P('images/blank.png', allow_user_override=False, data=True)
        img = image_from_data(data)
        image_from_data(P('catalog/mastheadImage.gif', allow_user_override=False, data=True))
        for fmt in 'png bmp jpeg'.split():
            d = image_to_data(img, fmt=fmt)
            image_from_data(d)
        # Run the imaging tests
        test()

        from calibre.gui2 import ensure_app, destroy_app
        display_env_var = os.environ.pop('DISPLAY', None)
        try:
            ensure_app()
            self.assertGreaterEqual(len(QFontDatabase().families()), 5, 'The QPA headless plugin is not able to locate enough system fonts via fontconfig')
            from calibre.ebooks.covers import create_cover
            create_cover('xxx', ['yyy'])
            na = QNetworkAccessManager()
            self.assertTrue(hasattr(na, 'sslErrors'), 'Qt not compiled with openssl')
            if iswindows:
                from qt.core import QtWin
                QtWin
            p = QWebEnginePage()

            def callback(result):
                callback.result = result
                if hasattr(print_callback, 'result'):
                    QApplication.instance().quit()

            def print_callback(result):
                print_callback.result = result
                if hasattr(callback, 'result'):
                    QApplication.instance().quit()

            p.runJavaScript('1 + 1', callback)
            p.printToPdf(print_callback)
            QTimer.singleShot(5000, lambda: QApplication.instance().quit())
            QApplication.instance().exec_()
            test_flaky = ismacos and not is_ci
            if not test_flaky:
                self.assertEqual(callback.result, 2, 'Simple JS computation failed')
                self.assertIn(b'Skia/PDF', bytes(print_callback.result), 'Print to PDF failed')
            del p
            del na
            destroy_app()
            del QWebEnginePage
        finally:
            if display_env_var is not None:
                os.environ['DISPLAY'] = display_env_var
Exemple #3
0
 def find(self, direction):
     text = str(self.search.text())
     self.view._page.findText(text, (
         QWebEnginePage.FindFlag.FindBackward if direction == 'prev' else QWebEnginePage.FindFlags(0)))
Exemple #4
0
 def __init__(self, parent):
     QWebEnginePage.__init__(self, create_profile(), parent)
     secure_webengine(self, for_viewer=True)
     self.bridge = PreviewBridge(self)
Exemple #5
0
 def find(self, forwards=True):
     text = str(self.search_text.text()).strip()
     flags = QWebEnginePage.FindFlags(
         0) if forwards else QWebEnginePage.FindFlag.FindBackward
     self.find_data = text, flags, forwards
     self.view.findText(text, flags, self.find_callback)