Skip to content
Snippets Groups Projects
Commit 1bdc5927 authored by Anders H. Rebner's avatar Anders H. Rebner
Browse files

Merge branch 'pdf-preview' into 'master'

#35 pdf preview

See merge request !16
parents cc4c5733 6fe62cd1
No related branches found
No related tags found
1 merge request!16#35 pdf preview
Pipeline #72835 passed
......@@ -41,3 +41,11 @@ ENV LC_ALL en_US.UTF-8
# From https://it.i88.ca/2016/03/how-to-fix-importerror-libgssapikrb5so2.html
# python3.7 -m unittest fails without this
RUN apt-get -y install libgssapi-krb5-2
# Necessary for import of PySide2.QtWebEngineWidgets to work
RUN apt-get -y install libnss3 \
libxcomposite-dev \
libxcursor-dev \
libxi-dev \
libxtst-dev \
libxrandr-dev
......@@ -6,11 +6,12 @@ out to separate modules.
"""
import sys
import os
from PySide2.QtCore import QRectF, QPoint, QTimer, Qt
from PySide2.QtCore import QRectF, QPoint, QTimer, Qt, QUrl
from PySide2.QtWidgets import QTabWidget, QWidget, QMainWindow, \
QApplication, QHBoxLayout, QVBoxLayout, QPushButton, QLabel, \
QAbstractItemView, QListWidget, QListWidgetItem, QAction, QGraphicsScene, \
QGraphicsView, QScrollArea, QGraphicsRectItem
from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings
from PySide2.QtGui import QBrush, QIcon, QPalette, QFont, QPixmap
from soitool.modules.module_table import TableModule
......@@ -481,6 +482,36 @@ class InlineEditableSOIView(QScrollArea):
self.view.translate(delta.x(), delta.y())
# pylint: disable=r0903
class PDFPreviewWidget(QWebEngineView):
"""Widget to preview PDFs using QWebEngineView with PDF plugin.
Inspired by the following sources:
* https://doc.qt.io/qt-5/qtwebengine-features.html#pdf-file-viewing
* https://doc.qt.io/qt-5/qtwebengine-webenginewidgets-simplebrowser-example.html
The load method interited from QWebEngineView's can be used to load a new
URL, and the inherited reload method can be used to reload the currently
opened URL.
Parameters
----------
initial_url : QUrl
URL to load by default. Used for QWebEngineView's .load method
https://doc.qt.io/qtforpython/PySide2/QtWebEngineWidgets/QWebEngineView.html#detailed-description
"""
def __init__(self, initial_url):
super().__init__()
self.page().settings().setAttribute(QWebEngineSettings.PluginsEnabled,
True)
# the following setting is the default, but explicitly enabling to be
# explicit
self.page().settings().setAttribute(QWebEngineSettings.
PdfViewerEnabled, True)
self.load(QUrl(initial_url))
if __name__ == "__main__":
app = QApplication(sys.argv)
WINDOW = MainWindow()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment