Skip to content
Snippets Groups Projects
Commit 5644ea93 authored by Thomas Holene Løkkeborg's avatar Thomas Holene Løkkeborg
Browse files

Merge branch 'blackify-prosjekt-filer' into 'master'

#47 Blackify prosjekt filer

See merge request !34
parents 39ed7bed 6924d38c
No related branches found
No related tags found
2 merge requests!34#47 Blackify prosjekt filer,!30WIP: #46 Start for å endre SOI layout og oppsett
Pipeline #74858 passed with stages
in 2 minutes and 51 seconds
...@@ -3,8 +3,13 @@ ...@@ -3,8 +3,13 @@
from datetime import datetime from datetime import datetime
from enum import Enum from enum import Enum
from reportlab.pdfgen import canvas from reportlab.pdfgen import canvas
from reportlab.platypus import Table, Paragraph, TableStyle, \ from reportlab.platypus import (
SimpleDocTemplate, Spacer Table,
Paragraph,
TableStyle,
SimpleDocTemplate,
Spacer,
)
from reportlab.lib.styles import ParagraphStyle from reportlab.lib.styles import ParagraphStyle
from reportlab.lib import colors from reportlab.lib import colors
from reportlab.lib.pagesizes import A4, portrait from reportlab.lib.pagesizes import A4, portrait
...@@ -12,28 +17,35 @@ from reportlab.lib.units import cm ...@@ -12,28 +17,35 @@ from reportlab.lib.units import cm
from soitool.database import Database from soitool.database import Database
A4_WIDTH = A4[0] A4_WIDTH = A4[0]
TITLE_FULL = '<u>Kodebok</u>' TITLE_FULL = "<u>Kodebok</u>"
TITLE_SMALL = "<u>Liten Kodebok</u>" TITLE_SMALL = "<u>Liten Kodebok</u>"
HEADERS = ["Ord/Uttrykk", "Kategori", "Type", "Kode"] HEADERS = ["Ord/Uttrykk", "Kategori", "Type", "Kode"]
HEADER_BG_COLOR = colors.HexColor("#a6a6a6") HEADER_BG_COLOR = colors.HexColor("#a6a6a6")
TITLE_STYLE = ParagraphStyle( TITLE_STYLE = ParagraphStyle(
name='Title', name="Title",
fontName='Helvetica', fontName="Helvetica",
fontSize=20, fontSize=20,
alignment=1, alignment=1,
underlineWidth=1.5 underlineWidth=1.5,
) )
PAGE_NUMBER_FONT = "Helvetica" PAGE_NUMBER_FONT = "Helvetica"
TABLE_STYLE = TableStyle([ TABLE_STYLE = TableStyle(
('FONTSIZE', (0, 0), (3, 0), 16), # Header-font [
('BOTTOMPADDING', (0, 0), (3, 0), 10), # Header-padding bottom ("FONTSIZE", (0, 0), (3, 0), 16), # Header-font
("BACKGROUND", (0, 0), (3, 0), HEADER_BG_COLOR), # Header background-color ("BOTTOMPADDING", (0, 0), (3, 0), 10), # Header-padding bottom
("ALIGN", (0, 0), (3, 0), "CENTER"), # Header-text centered (
('GRID', (0, 0), (-1, -1), 1, colors.black), # Border around cells "BACKGROUND",
]) (0, 0),
(3, 0),
HEADER_BG_COLOR,
), # Header background-color
("ALIGN", (0, 0), (3, 0), "CENTER"), # Header-text centered
("GRID", (0, 0), (-1, -1), 1, colors.black), # Border around cells
]
)
class CodebookSize(Enum): class CodebookSize(Enum):
...@@ -43,8 +55,9 @@ class CodebookSize(Enum): ...@@ -43,8 +55,9 @@ class CodebookSize(Enum):
SMALL = 1 SMALL = 1
def generate_codebook_pdf(codebook_size=CodebookSize.FULL, def generate_codebook_pdf(
page_size=A4, orientation=portrait): codebook_size=CodebookSize.FULL, page_size=A4, orientation=portrait
):
"""Generate PDF with data from database-table 'CodeBook'. """Generate PDF with data from database-table 'CodeBook'.
Parameters Parameters
...@@ -80,8 +93,9 @@ def generate_codebook_pdf(codebook_size=CodebookSize.FULL, ...@@ -80,8 +93,9 @@ def generate_codebook_pdf(codebook_size=CodebookSize.FULL,
file_name = generate_filename(codebook_size) file_name = generate_filename(codebook_size)
# Create document, add elements and save as PDF # Create document, add elements and save as PDF
doc = SimpleDocTemplate(file_name, pagesize=orientation(page_size), doc = SimpleDocTemplate(
topMargin=30) file_name, pagesize=orientation(page_size), topMargin=30
)
doc.build(elements, canvasmaker=PageNumCanvas) doc.build(elements, canvasmaker=PageNumCanvas)
......
...@@ -10,17 +10,20 @@ CURDIR = os.path.dirname(__file__) ...@@ -10,17 +10,20 @@ CURDIR = os.path.dirname(__file__)
DBPATH = os.path.join(CURDIR, DBNAME) DBPATH = os.path.join(CURDIR, DBNAME)
# DDL-statements for creating tables # DDL-statements for creating tables
CODEBOOK = "CREATE TABLE CodeBook" \ CODEBOOK = (
"(Word VARCHAR PRIMARY KEY NOT NULL CHECK(length(Word) > 0), " \ "CREATE TABLE CodeBook"
"Category VARCHAR, " \ "(Word VARCHAR PRIMARY KEY NOT NULL CHECK(length(Word) > 0), "
"Type VARCHAR DEFAULT 'Stor' CHECK(Type='Stor' OR Type='Liten'), " \ "Category VARCHAR, "
"Code VARCHAR UNIQUE)" "Type VARCHAR DEFAULT 'Stor' CHECK(Type='Stor' OR Type='Liten'), "
CATEGORYWORDS = "CREATE TABLE CategoryWords" \ "Code VARCHAR UNIQUE)"
"(Word VARCHAR PRIMARY KEY, Category VARCHAR)" )
CATEGORYWORDS = (
"CREATE TABLE CategoryWords" "(Word VARCHAR PRIMARY KEY, Category VARCHAR)"
)
BYHEART = "CREATE TABLE ByHeart(Word VARCHAR PRIMARY KEY)" BYHEART = "CREATE TABLE ByHeart(Word VARCHAR PRIMARY KEY)"
class Database(): class Database:
""" """
Holds database-connection and related functions. Holds database-connection and related functions.
......
"""Includes functionality for inline editing of SOI.""" """Includes functionality for inline editing of SOI."""
from PySide2.QtCore import Qt, QRectF, QTimer, QPoint, QMarginsF from PySide2.QtCore import Qt, QRectF, QTimer, QPoint, QMarginsF
from PySide2.QtWidgets import QApplication, QScrollArea, QLabel, \ from PySide2.QtWidgets import (
QGraphicsScene, QGraphicsView, QGraphicsRectItem QApplication,
QScrollArea,
QLabel,
QGraphicsScene,
QGraphicsView,
QGraphicsRectItem,
)
from PySide2.QtGui import QFont, QPixmap, QBrush, QPalette, QPainter from PySide2.QtGui import QFont, QPixmap, QBrush, QPalette, QPainter
from PySide2.QtPrintSupport import QPrinter from PySide2.QtPrintSupport import QPrinter
...@@ -90,9 +96,11 @@ class InlineEditableSOIView(QScrollArea): ...@@ -90,9 +96,11 @@ class InlineEditableSOIView(QScrollArea):
ok = painter.begin(printer) ok = painter.begin(printer)
if not ok: if not ok:
raise ValueError("Not able to begin QPainter using QPrinter " raise ValueError(
"based on argument " "Not able to begin QPainter using QPrinter "
"filename '{}'".format(filename)) "based on argument "
"filename '{}'".format(filename)
)
# render each page to own PDF page # render each page to own PDF page
for i, modules in enumerate(self.pages): for i, modules in enumerate(self.pages):
...@@ -100,9 +108,10 @@ class InlineEditableSOIView(QScrollArea): ...@@ -100,9 +108,10 @@ class InlineEditableSOIView(QScrollArea):
x = 0 x = 0
y = self.soi.HEIGHT * i + self.soi.PADDING * i y = self.soi.HEIGHT * i + self.soi.PADDING * i
self.scene.render(painter, source=QRectF(x, y, self.scene.render(
self.soi.WIDTH, painter,
self.soi.HEIGHT)) source=QRectF(x, y, self.soi.WIDTH, self.soi.HEIGHT),
)
# if there are more pages, newPage # if there are more pages, newPage
if i + 1 < len(self.pages): if i + 1 < len(self.pages):
...@@ -119,8 +128,9 @@ class InlineEditableSOIView(QScrollArea): ...@@ -119,8 +128,9 @@ class InlineEditableSOIView(QScrollArea):
# adjust page size # adjust page size
full_scene_height = y + self.soi.HEIGHT full_scene_height = y + self.soi.HEIGHT
self.scene.setSceneRect(QRectF(0, 0, self.soi.WIDTH, self.scene.setSceneRect(
full_scene_height)) QRectF(0, 0, self.soi.WIDTH, full_scene_height)
)
self.draw_page(x, y) self.draw_page(x, y)
self.draw_header(x + self.soi.PADDING, y + self.soi.PADDING, i + 1) self.draw_header(x + self.soi.PADDING, y + self.soi.PADDING, i + 1)
...@@ -150,30 +160,37 @@ class InlineEditableSOIView(QScrollArea): ...@@ -150,30 +160,37 @@ class InlineEditableSOIView(QScrollArea):
page_number.setFont(QFont("Times New Roman", 50)) page_number.setFont(QFont("Times New Roman", 50))
# source: https://stackoverflow.com/a/8638114/3545896 # source: https://stackoverflow.com/a/8638114/3545896
# CAUTION: does not work if font is set through stylesheet # CAUTION: does not work if font is set through stylesheet
label_width = \ label_width = (
page_number.fontMetrics().boundingRect(page_number.text()).width() page_number.fontMetrics().boundingRect(page_number.text()).width()
)
page_number.move(x + (self.soi.CONTENT_WIDTH - label_width) / 2, y) page_number.move(x + (self.soi.CONTENT_WIDTH - label_width) / 2, y)
self.scene.addWidget(page_number) self.scene.addWidget(page_number)
# classification # classification
classification = QLabel(self.soi.classification) classification = QLabel(self.soi.classification)
classification.setStyleSheet("background-color: rgba(0,0,0,0%); " classification.setStyleSheet(
"color: red") "background-color: rgba(0,0,0,0%); " "color: red"
)
classification.setFont(QFont("Times New Roman", 50)) classification.setFont(QFont("Times New Roman", 50))
# source: https://stackoverflow.com/a/8638114/3545896 # source: https://stackoverflow.com/a/8638114/3545896
# CAUTION: does not work if font is set through stylesheet # CAUTION: does not work if font is set through stylesheet
label_width = (classification.fontMetrics() label_width = (
.boundingRect(classification.text()).width()) classification.fontMetrics()
x_pos = x + self.soi.CONTENT_WIDTH - label_width - \ .boundingRect(classification.text())
self.soi.HEADER_HEIGHT .width()
)
x_pos = (
x + self.soi.CONTENT_WIDTH - label_width - self.soi.HEADER_HEIGHT
)
classification.move(x_pos, y) classification.move(x_pos, y)
self.scene.addWidget(classification) self.scene.addWidget(classification)
# patch # patch
pixmap = QPixmap(self.soi.icon) pixmap = QPixmap(self.soi.icon)
patch = QLabel() patch = QLabel()
patch.setPixmap(pixmap.scaled(self.soi.HEADER_HEIGHT, patch.setPixmap(
self.soi.HEADER_HEIGHT)) pixmap.scaled(self.soi.HEADER_HEIGHT, self.soi.HEADER_HEIGHT)
)
patch.move(x + self.soi.CONTENT_WIDTH - self.soi.HEADER_HEIGHT, y) patch.move(x + self.soi.CONTENT_WIDTH - self.soi.HEADER_HEIGHT, y)
self.scene.addWidget(patch) self.scene.addWidget(patch)
...@@ -186,19 +203,32 @@ class InlineEditableSOIView(QScrollArea): ...@@ -186,19 +203,32 @@ class InlineEditableSOIView(QScrollArea):
y : int y : int
""" """
# color the page white # color the page white
page_background = QGraphicsRectItem(x, y, self.soi.WIDTH, page_background = QGraphicsRectItem(
self.soi.HEIGHT) x, y, self.soi.WIDTH, self.soi.HEIGHT
)
page_background.setBrush(QBrush(Qt.white)) page_background.setBrush(QBrush(Qt.white))
self.scene.addItem(page_background) self.scene.addItem(page_background)
# draw borders # draw borders
self.scene.addRect(x, y, self.soi.WIDTH, self.soi.HEIGHT) self.scene.addRect(x, y, self.soi.WIDTH, self.soi.HEIGHT)
self.scene.addRect(x + self.soi.PADDING, y + self.soi.PADDING, self.scene.addRect(
self.soi.CONTENT_WIDTH, self.soi.CONTENT_HEIGHT) x + self.soi.PADDING,
self.scene.addRect(x + self.soi.PADDING, y + self.soi.PADDING, y + self.soi.PADDING,
self.soi.CONTENT_WIDTH, self.soi.CONTENT_HEIGHT) self.soi.CONTENT_WIDTH,
self.scene.addRect(x + self.soi.PADDING, y + self.soi.PADDING, self.soi.CONTENT_HEIGHT,
self.soi.CONTENT_WIDTH, self.soi.HEADER_HEIGHT) )
self.scene.addRect(
x + self.soi.PADDING,
y + self.soi.PADDING,
self.soi.CONTENT_WIDTH,
self.soi.CONTENT_HEIGHT,
)
self.scene.addRect(
x + self.soi.PADDING,
y + self.soi.PADDING,
self.soi.CONTENT_WIDTH,
self.soi.HEADER_HEIGHT,
)
def setup_scene(self): def setup_scene(self):
"""Prepare scene for use. """Prepare scene for use.
...@@ -220,6 +250,7 @@ class InlineEditableSOIView(QScrollArea): ...@@ -220,6 +250,7 @@ class InlineEditableSOIView(QScrollArea):
Used to demonstrate zooming only, should be removed once the project Used to demonstrate zooming only, should be removed once the project
matures. matures.
""" """
def do_on_timeout(): def do_on_timeout():
self.zoom(1 / 1.00005) self.zoom(1 / 1.00005)
...@@ -244,8 +275,9 @@ class InlineEditableSOIView(QScrollArea): ...@@ -244,8 +275,9 @@ class InlineEditableSOIView(QScrollArea):
# Zoom # Zoom
self.view.scale(zoom_factor, zoom_factor) self.view.scale(zoom_factor, zoom_factor)
pos_old = self.view.mapToScene(QPoint(self.soi.WIDTH / 2, pos_old = self.view.mapToScene(
self.soi.HEIGHT / 2)) QPoint(self.soi.WIDTH / 2, self.soi.HEIGHT / 2)
)
pos_new = self.view.mapToScene(self.soi.WIDTH / 2, self.soi.HEIGHT / 2) pos_new = self.view.mapToScene(self.soi.WIDTH / 2, self.soi.HEIGHT / 2)
delta = pos_new - pos_old delta = pos_new - pos_old
self.view.translate(delta.x(), delta.y()) self.view.translate(delta.x(), delta.y())
...@@ -44,7 +44,7 @@ class CoolWidget(QtWidgets.QWidget): ...@@ -44,7 +44,7 @@ class CoolWidget(QtWidgets.QWidget):
self, self,
"Change text", "Change text",
"Please type something", "Please type something",
QtWidgets.QLineEdit.Normal QtWidgets.QLineEdit.Normal,
) )
if ok: if ok:
self.qlabel.setText(text) self.qlabel.setText(text)
......
...@@ -7,8 +7,15 @@ import sys ...@@ -7,8 +7,15 @@ import sys
import os import os
from enum import Enum from enum import Enum
from functools import partial from functools import partial
from PySide2.QtWidgets import QTabWidget, QWidget, QMainWindow, \ from PySide2.QtWidgets import (
QApplication, QHBoxLayout, QVBoxLayout, QAction QTabWidget,
QWidget,
QMainWindow,
QApplication,
QHBoxLayout,
QVBoxLayout,
QAction,
)
from PySide2.QtGui import QIcon from PySide2.QtGui import QIcon
from soitool.codebook import CodeBookTableView from soitool.codebook import CodeBookTableView
from soitool.codebook_row_adder import CodebookRowAdder from soitool.codebook_row_adder import CodebookRowAdder
...@@ -93,15 +100,17 @@ class MainWindow(QMainWindow): ...@@ -93,15 +100,17 @@ class MainWindow(QMainWindow):
# Export full codebook # Export full codebook
export_codebook_full = QAction("Stor kodebok", self) export_codebook_full = QAction("Stor kodebok", self)
export_codebook_full.setStatusTip("Eksporter stor kodebok som PDF") export_codebook_full.setStatusTip("Eksporter stor kodebok som PDF")
export_codebook_full.triggered.connect(partial(generate_codebook_pdf, export_codebook_full.triggered.connect(
CodebookSize.FULL)) partial(generate_codebook_pdf, CodebookSize.FULL)
)
export_codebook.addAction(export_codebook_full) export_codebook.addAction(export_codebook_full)
# Export small codebook # Export small codebook
export_codebook_small = QAction("Liten kodebok", self) export_codebook_small = QAction("Liten kodebok", self)
export_codebook_small.setStatusTip("Eksporter liten kodebok som PDF") export_codebook_small.setStatusTip("Eksporter liten kodebok som PDF")
export_codebook_small.triggered.connect(partial(generate_codebook_pdf, export_codebook_small.triggered.connect(
CodebookSize.SMALL)) partial(generate_codebook_pdf, CodebookSize.SMALL)
)
export_codebook.addAction(export_codebook_small) export_codebook.addAction(export_codebook_small)
# Hot keys # Hot keys
...@@ -123,7 +132,7 @@ class MainWindow(QMainWindow): ...@@ -123,7 +132,7 @@ class MainWindow(QMainWindow):
self.setCentralWidget(self.tabs) self.setCentralWidget(self.tabs)
# Add HV logo # Add HV logo
filename = 'media/HVlogo.PNG' filename = "media/HVlogo.PNG"
dirname = os.path.dirname(__file__) dirname = os.path.dirname(__file__)
filepath = os.path.join(dirname, filename) filepath = os.path.join(dirname, filename)
self.setWindowIcon(QIcon(filepath)) self.setWindowIcon(QIcon(filepath))
...@@ -155,7 +164,7 @@ class MainWindow(QMainWindow): ...@@ -155,7 +164,7 @@ class MainWindow(QMainWindow):
# Set layout, add tab and select tab # Set layout, add tab and select tab
tab.setLayout(hbox) tab.setLayout(hbox)
self.tabs.addTab(tab, 'Kodebok') self.tabs.addTab(tab, "Kodebok")
self.tabs.setCurrentWidget(tab) self.tabs.setCurrentWidget(tab)
......
...@@ -26,11 +26,14 @@ class ModuleList(QListWidget): ...@@ -26,11 +26,14 @@ class ModuleList(QListWidget):
super().__init__() super().__init__()
# full import path below to avoid circular dependency # full import path below to avoid circular dependency
if not isinstance(parent, if not isinstance(
soitool.soi_workspace_widget.SOIWorkspaceWidget): parent, soitool.soi_workspace_widget.SOIWorkspaceWidget
raise RuntimeError('Only soitool.SOIWorkspaceWidget is ' ):
'acceptable type for parent-variable ' raise RuntimeError(
'in class Module_list.') "Only soitool.SOIWorkspaceWidget is "
"acceptable type for parent-variable "
"in class Module_list."
)
self.type = module_type self.type = module_type
self.parent = parent self.parent = parent
self.original_element_name = None self.original_element_name = None
...@@ -56,11 +59,14 @@ class ModuleList(QListWidget): ...@@ -56,11 +59,14 @@ class ModuleList(QListWidget):
"""Fill list with elements.""" """Fill list with elements."""
# Get names of modules/attachments: # Get names of modules/attachments:
if ModuleType(self.type) == ModuleType.MAIN_MODULE: if ModuleType(self.type) == ModuleType.MAIN_MODULE:
names = [module["meta"]["name"] for names = [
module in self.parent.soi.modules] module["meta"]["name"] for module in self.parent.soi.modules
]
elif ModuleType(self.type) == ModuleType.ATTACHMENT_MODULE: elif ModuleType(self.type) == ModuleType.ATTACHMENT_MODULE:
names = [attachment["meta"]["name"] for names = [
attachment in self.parent.soi.attachments] attachment["meta"]["name"]
for attachment in self.parent.soi.attachments
]
for i, name in enumerate(names): for i, name in enumerate(names):
item = QListWidgetItem(name) item = QListWidgetItem(name)
......
...@@ -4,7 +4,7 @@ from PySide2 import QtGui, QtCore ...@@ -4,7 +4,7 @@ from PySide2 import QtGui, QtCore
from soitool.modules.module_base import ModuleBase from soitool.modules.module_base import ModuleBase
HEADER_FONT = QtGui.QFont() HEADER_FONT = QtGui.QFont()
HEADER_FONT.setFamily('Arial') HEADER_FONT.setFamily("Arial")
HEADER_FONT.setPointSize(12) HEADER_FONT.setPointSize(12)
HEADER_FONT.setWeight(100) HEADER_FONT.setWeight(100)
...@@ -78,14 +78,20 @@ class TableModule(ModuleBase, QTableWidget, metaclass=Meta): ...@@ -78,14 +78,20 @@ class TableModule(ModuleBase, QTableWidget, metaclass=Meta):
""" """
if event.key() == QtCore.Qt.Key_Question: if event.key() == QtCore.Qt.Key_Question:
self.add_column() self.add_column()
elif (event.modifiers() == QtCore.Qt.ShiftModifier elif (
and event.key() == QtCore.Qt.Key_Underscore): event.modifiers() == QtCore.Qt.ShiftModifier
and event.key() == QtCore.Qt.Key_Underscore
):
self.remove_column() self.remove_column()
elif (event.modifiers() == QtCore.Qt.ControlModifier elif (
and event.key() == QtCore.Qt.Key_Plus): event.modifiers() == QtCore.Qt.ControlModifier
and event.key() == QtCore.Qt.Key_Plus
):
self.add_row() self.add_row()
elif (event.modifiers() == QtCore.Qt.ControlModifier elif (
and event.key() == QtCore.Qt.Key_Underscore): event.modifiers() == QtCore.Qt.ControlModifier
and event.key() == QtCore.Qt.Key_Underscore
):
self.remove_row() self.remove_row()
else: else:
super(TableModule, self).keyPressEvent(event) super(TableModule, self).keyPressEvent(event)
......
...@@ -24,10 +24,12 @@ class PDFPreviewWidget(QWebEngineView): ...@@ -24,10 +24,12 @@ class PDFPreviewWidget(QWebEngineView):
def __init__(self, initial_url): def __init__(self, initial_url):
super().__init__() super().__init__()
self.page().settings().setAttribute(QWebEngineSettings.PluginsEnabled, self.page().settings().setAttribute(
True) QWebEngineSettings.PluginsEnabled, True
)
# the following setting is the default, but explicitly enabling to be # the following setting is the default, but explicitly enabling to be
# explicit # explicit
self.page().settings().setAttribute(QWebEngineSettings. self.page().settings().setAttribute(
PdfViewerEnabled, True) QWebEngineSettings.PdfViewerEnabled, True
)
self.load(QUrl(initial_url)) self.load(QUrl(initial_url))
...@@ -4,8 +4,16 @@ This dialog is called when a button in soi_workspace_widget is pressed ...@@ -4,8 +4,16 @@ This dialog is called when a button in soi_workspace_widget is pressed
""" """
from PySide2.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QFormLayout, \ from PySide2.QtWidgets import (
QLabel, QLineEdit, QRadioButton, QPushButton QDialog,
QVBoxLayout,
QHBoxLayout,
QFormLayout,
QLabel,
QLineEdit,
QRadioButton,
QPushButton,
)
class Setup(QDialog): # pylint: disable = R0902 class Setup(QDialog): # pylint: disable = R0902
...@@ -34,8 +42,8 @@ class Setup(QDialog): # pylint: disable = R0902 ...@@ -34,8 +42,8 @@ class Setup(QDialog): # pylint: disable = R0902
self.layout_setup.addWidget(self.label_header) self.layout_setup.addWidget(self.label_header)
self.head1 = QLabel("Header1") # Change variablename later self.head1 = QLabel("Header1") # Change variablename later
self.head2 = QLabel("Header2") # Change variablename later self.head2 = QLabel("Header2") # Change variablename later
self.hline1 = QLineEdit() # Change variablename later self.hline1 = QLineEdit() # Change variablename later
self.hline2 = QLineEdit() # Change variablename later self.hline2 = QLineEdit() # Change variablename later
self.layout_header.addRow(self.head1, self.hline1) self.layout_header.addRow(self.head1, self.hline1)
self.layout_header.addRow(self.head2, self.hline2) self.layout_header.addRow(self.head2, self.hline2)
self.layout_setup.addLayout(self.layout_header) self.layout_setup.addLayout(self.layout_header)
...@@ -79,3 +87,7 @@ class Setup(QDialog): # pylint: disable = R0902 ...@@ -79,3 +87,7 @@ class Setup(QDialog): # pylint: disable = R0902
self.button_cancel.clicked.connect(self.reject) # esc-key (default) self.button_cancel.clicked.connect(self.reject) # esc-key (default)
self.button_save.clicked.connect(self.accept) # enter-key (default) self.button_save.clicked.connect(self.accept) # enter-key (default)
# need two functions, save and cancel
# when cancel, clear lineedits and set radiobuttons to default or SOI-parts
# when save, lineedits writes to labels and find a way to get radiobuttons
...@@ -12,7 +12,7 @@ class ModuleType(Enum): ...@@ -12,7 +12,7 @@ class ModuleType(Enum):
ATTACHMENT_MODULE = 1 ATTACHMENT_MODULE = 1
class SOI(): class SOI:
"""Datastructure for SOI. """Datastructure for SOI.
Holds all info about an SOI necessary to view and edit it. Holds all info about an SOI necessary to view and edit it.
...@@ -72,20 +72,22 @@ class SOI(): ...@@ -72,20 +72,22 @@ class SOI():
# separate data classes (auto-placement stuff in one class, styling in # separate data classes (auto-placement stuff in one class, styling in
# another, etc). # another, etc).
# pylint: disable=r0913 # pylint: disable=r0913
def __init__(self, def __init__(
title="Default SOI title", self,
description="Default SOI description", title="Default SOI title",
version="1", description="Default SOI description",
date=None, version="1",
valid_from=None, date=None,
valid_to=None, valid_from=None,
icon="soitool/media/HVlogo.png", valid_to=None,
classification="ugradert", icon="soitool/media/HVlogo.png",
orientation="landscape", classification="ugradert",
placement_strategy="auto", orientation="landscape",
algorithm_bin="BFF", placement_strategy="auto",
algorithm_pack="MaxRectsBI", algorithm_bin="BFF",
algorithm_sort="SORT_AREA"): algorithm_pack="MaxRectsBI",
algorithm_sort="SORT_AREA",
):
# populate date-related arguments if they are not supplied by the user # populate date-related arguments if they are not supplied by the user
if date is None: if date is None:
...@@ -122,31 +124,16 @@ class SOI(): ...@@ -122,31 +124,16 @@ class SOI():
self.modules = [ self.modules = [
{ {
"widget": TableModule(), "widget": TableModule(),
"meta": { "meta": {"x": 0, "y": 0, "page": 1, "name": "Tabell1"},
"x": 0,
"y": 0,
"page": 1,
"name": 'Tabell1'
}
}, },
{ {
"widget": TableModule(), "widget": TableModule(),
"meta": { "meta": {"x": 0, "y": 0, "page": 1, "name": "Tabell2"},
"x": 0,
"y": 0,
"page": 1,
"name": 'Tabell2'
}
}, },
{ {
"widget": TableModule(), "widget": TableModule(),
"meta": { "meta": {"x": 0, "y": 0, "page": 2, "name": "Tabell3"},
"x": 0, },
"y": 0,
"page": 2,
"name": 'Tabell3'
}
}
] ]
# NOTE # NOTE
...@@ -154,12 +141,7 @@ class SOI(): ...@@ -154,12 +141,7 @@ class SOI():
self.attachments = [ self.attachments = [
{ {
"widget": TableModule(), "widget": TableModule(),
"meta": { "meta": {"x": 0, "y": 0, "page": 2, "name": "Tabell1"},
"x": 0,
"y": 0,
"page": 2,
"name": 'Tabell1'
}
} }
] ]
...@@ -177,16 +159,22 @@ class SOI(): ...@@ -177,16 +159,22 @@ class SOI():
itself a dict with fields "x", "y" and "page", and "widget" is a itself a dict with fields "x", "y" and "page", and "widget" is a
widget based on "ModuleBase" widget based on "ModuleBase"
""" """
distance_to_start_of_next_soi_content_y = self.CONTENT_HEIGHT + \ distance_to_start_of_next_soi_content_y = (
self.PADDING * 2 + self.HEADER_HEIGHT self.CONTENT_HEIGHT + self.PADDING * 2 + self.HEADER_HEIGHT
)
scene_skip_distance_page_height = \ scene_skip_distance_page_height = (
distance_to_start_of_next_soi_content_y * \ distance_to_start_of_next_soi_content_y
(module["meta"]["page"] - 1) * (module["meta"]["page"] - 1)
)
new_x = module["meta"]["x"] + self.PADDING new_x = module["meta"]["x"] + self.PADDING
new_y = module["meta"]["y"] + self.PADDING + self.HEADER_HEIGHT + \ new_y = (
scene_skip_distance_page_height module["meta"]["y"]
+ self.PADDING
+ self.HEADER_HEIGHT
+ scene_skip_distance_page_height
)
module["widget"].set_pos(QPoint(new_x, new_y)) module["widget"].set_pos(QPoint(new_x, new_y))
...@@ -199,8 +187,9 @@ class SOI(): ...@@ -199,8 +187,9 @@ class SOI():
next to each other from left to right next to each other from left to right
""" """
x = self.MODULE_PADDING x = self.MODULE_PADDING
first_page_modules = [module for module in self.modules first_page_modules = [
if module["meta"]["page"] == 1] module for module in self.modules if module["meta"]["page"] == 1
]
for module in first_page_modules: for module in first_page_modules:
module["meta"]["x"] = x module["meta"]["x"] = x
...@@ -214,8 +203,9 @@ class SOI(): ...@@ -214,8 +203,9 @@ class SOI():
# NOTE the following is simply duplicated.. left like this to KISS # NOTE the following is simply duplicated.. left like this to KISS
# will be replaced by rectpack anyways # will be replaced by rectpack anyways
x = self.MODULE_PADDING x = self.MODULE_PADDING
second_page_modules = [module for module in self.modules second_page_modules = [
if module["meta"]["page"] == 2] module for module in self.modules if module["meta"]["page"] == 2
]
for module in second_page_modules: for module in second_page_modules:
module["meta"]["x"] = x module["meta"]["x"] = x
module["meta"]["y"] = self.MODULE_PADDING module["meta"]["y"] = self.MODULE_PADDING
......
...@@ -3,8 +3,13 @@ ...@@ -3,8 +3,13 @@
Meant for use inside of tabs in our program. Meant for use inside of tabs in our program.
""" """
from PySide2.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QPushButton, \ from PySide2.QtWidgets import (
QLabel QWidget,
QHBoxLayout,
QVBoxLayout,
QPushButton,
QLabel,
)
from soitool.soi import SOI, ModuleType from soitool.soi import SOI, ModuleType
from soitool.module_list import ModuleList from soitool.module_list import ModuleList
from soitool.inline_editable_soi_view import InlineEditableSOIView from soitool.inline_editable_soi_view import InlineEditableSOIView
......
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