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

Merge branch 'master' into 'modulliste'

# Conflicts:
#   soitool/main_window.py
parents a2a08ff0 7e1b2911
No related branches found
No related tags found
1 merge request!22Modulliste
Pipeline #72946 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
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -2,4 +2,4 @@
; ignorerer sjekk for lange linjer, ettersom dette gjøres i pylint
; vi vil tillate lange linjer som avsluttes med link, og dette er mulig i
; pylint, men såvidt vi vet ikke mulig i flake8
ignore = E501
ignore = E501,W503
......@@ -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
......@@ -648,6 +649,36 @@ class ModuleList(QListWidget):
self.original_element_index = self.currentRow()
# 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()
......
"""Module containing subclassed SOIModule (QTableWidget, ModuleBase)."""
from PySide2.QtWidgets import QTableWidget, QTableWidgetItem, QShortcut
from PySide2.QtWidgets import QTableWidget, QTableWidgetItem
from PySide2 import QtGui, QtCore
from soitool.modules.module_base import ModuleBase
......@@ -28,7 +28,13 @@ class TableModule(ModuleBase, QTableWidget, metaclass=Meta):
"""
def set_pos(self, pos):
"""Set position of widget."""
"""Set position of widget.
Parameters
----------
pos : QPoint
Position (x, y).
"""
self.move(pos)
def __init__(self):
......@@ -58,7 +64,31 @@ class TableModule(ModuleBase, QTableWidget, metaclass=Meta):
self.cellChanged.connect(self.resize)
self.set_shortcuts()
def keyPressEvent(self, event):
"""Launch actions when specific combinations of keys are pressed.
If the keys pressed are not related to a shortcut on this custom widget
the event is sent on to be handled by the superclass (for navigation
with arrow-keys for.eg.)
Parameters
----------
event : QKeyEvent
event sent by Qt for us to handle
"""
if event.key() == QtCore.Qt.Key_Question:
self.add_column()
elif (event.modifiers() == QtCore.Qt.ShiftModifier
and event.key() == QtCore.Qt.Key_Underscore):
self.remove_column()
elif (event.modifiers() == QtCore.Qt.ControlModifier
and event.key() == QtCore.Qt.Key_Plus):
self.add_row()
elif (event.modifiers() == QtCore.Qt.ControlModifier
and event.key() == QtCore.Qt.Key_Underscore):
self.remove_row()
else:
super(TableModule, self).keyPressEvent(event)
def set_header_item(self, column, text):
"""Insert item with header-style.
......@@ -77,20 +107,6 @@ class TableModule(ModuleBase, QTableWidget, metaclass=Meta):
item.setFont(HEADER_FONT)
self.setItem(0, column, item)
def set_shortcuts(self):
"""Set shortcuts for adding and removing rows and columns."""
# Create shortcuts
shortcut_add_col = QShortcut(QtGui.QKeySequence("Shift++"), self)
shortcut_rem_col = QShortcut(QtGui.QKeySequence("Shift+-"), self)
shortcut_add_row = QShortcut(QtGui.QKeySequence("Ctrl++"), self)
shortcut_rem_row = QShortcut(QtGui.QKeySequence("Ctrl+-"), self)
# Connect shortcuts to functions
shortcut_add_col.activated.connect(self.add_column)
shortcut_rem_col.activated.connect(self.remove_column)
shortcut_add_row.activated.connect(self.add_row)
shortcut_rem_row.activated.connect(self.remove_row)
def add_column(self):
"""Add column to the right of selected column."""
self.insertColumn(self.currentColumn() + 1)
......
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