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

#42 #43 black formattering på nye filer

parent b70b6863
No related branches found
No related tags found
1 merge request!31#42 og #43 Kodebok-GUI
......@@ -60,6 +60,15 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
#
# NOTE about C0330:
# Ignoring pylint's C0330 "Wrong hanging indentation before block" error
# here because it erronously reports indentation issues, and conflicts with
# the black tool. See this issue on the black gitHub
# page: https://github.com/psf/black/issues/48, and this issue on pylints
# GitHub page referenced by the first issue:
# https://github.com/PyCQA/pylint/issues/289
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
......@@ -142,7 +151,8 @@ disable=print-statement,
E0611,
I1101,
E1101,
R0901
R0901,
C0330
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
......
......@@ -10,8 +10,8 @@ from soitool.database import DBPATH # , Database
from soitool.style import CODEBOOK_HEADER_FONT, CODEBOOK_HEADER_BACKGROUND_CSS
# Name and type of database
CONNAME = 'SOIDB'
DBTYPE = 'QSQLITE'
CONNAME = "SOIDB"
DBTYPE = "QSQLITE"
class CodeBookTableView(QTableView):
......@@ -30,7 +30,7 @@ class CodeBookTableView(QTableView):
db.setDatabaseName(DBPATH)
if not db.open():
raise RuntimeError('Could not open database.')
raise RuntimeError("Could not open database.")
# Enable sorting and sort by column 'Word'
self.setSortingEnabled(True)
......@@ -101,7 +101,7 @@ class CodeBookTableModel(QSqlTableModel):
def __init__(self):
super().__init__(None, QSqlDatabase.database(CONNAME))
self.setEditStrategy(QSqlTableModel.OnFieldChange)
self.setTable('CodeBook')
self.setTable("CodeBook")
self.setSort(0, Qt.AscendingOrder)
self.select()
......@@ -142,10 +142,10 @@ class CodeBookTableModel(QSqlTableModel):
# If a change is made to column 'Type'
if index.column() == 2:
# If correct string, replace with correctly cased str
if value.lower() == 'liten':
value = 'Liten'
elif value.lower() == 'stor':
value = 'Stor'
if value.lower() == "liten":
value = "Liten"
elif value.lower() == "stor":
value = "Stor"
else:
return False
......
"""Includes functionality for inserting rows into database-table CodeBook."""
from sqlite3 import IntegrityError
from PySide2.QtWidgets import QHBoxLayout, QVBoxLayout, QLabel, \
QLineEdit, QComboBox, QPushButton, QWidget
from PySide2.QtWidgets import (
QHBoxLayout,
QVBoxLayout,
QLabel,
QLineEdit,
QComboBox,
QPushButton,
QWidget,
)
from PySide2.QtCore import Qt
from soitool.database import Database
from soitool.codebook import CodeBookTableView, CodeBookTableModel
......@@ -34,10 +41,13 @@ class CodebookRowAdder(QWidget):
super().__init__()
# Raise error if argument is invalid
if codebook_view is not None and \
not isinstance(codebook_view, CodeBookTableView):
raise ValueError("Invalid value for argument 'codebook_view': "
+ "'{}'".format(codebook_view))
if codebook_view is not None and not isinstance(
codebook_view, CodeBookTableView
):
raise ValueError(
"Invalid value for argument 'codebook_view': "
+ "'{}'".format(codebook_view)
)
self.codebook_view = codebook_view
......@@ -71,13 +81,15 @@ class CodebookRowAdder(QWidget):
# Match width of widgets to columnwidths of the view if it is used
if self.codebook_view is not None:
self.text_field_word.setFixedWidth(
self.codebook_view.columnWidth(0) - 12)
self.codebook_view.columnWidth(0) - 12
)
self.text_field_category.setFixedWidth(
self.codebook_view.columnWidth(1) - 10)
self.codebook_view.columnWidth(1) - 10
)
self.combo_type.setFixedWidth(
self.codebook_view.columnWidth(2) - 5)
self.button.setFixedWidth(
self.codebook_view.columnWidth(3) - 5)
self.codebook_view.columnWidth(2) - 5
)
self.button.setFixedWidth(self.codebook_view.columnWidth(3) - 5)
# Set standard witdh of widgets if a view is not used
else:
self.text_field_word.setFixedWidth(140)
......@@ -162,10 +174,13 @@ class CodebookRowAdder(QWidget):
self.codebook_view.setModel(None)
# Try to add row to database
stmt = "INSERT INTO CodeBook(Word, Category, Type)" \
+ "VALUES(?, ?, ?)"
db.conn.execute(stmt, (word_input, category_input,
type_input,))
stmt = (
"INSERT INTO CodeBook(Word, Category, Type)"
+ "VALUES(?, ?, ?)"
)
db.conn.execute(
stmt, (word_input, category_input, type_input,)
)
# Add unique code to row and commit changes
db.add_code_to(word_input)
......
......@@ -4,8 +4,9 @@ from PySide2.QtGui import QFont
# Font and background-color for horizontal header in codebook-view.
CODEBOOK_HEADER_FONT = QFont()
CODEBOOK_HEADER_FONT.setFamily('Arial')
CODEBOOK_HEADER_FONT.setFamily("Arial")
CODEBOOK_HEADER_FONT.setPointSize(14)
CODEBOOK_HEADER_FONT.setWeight(50)
CODEBOOK_HEADER_BACKGROUND_CSS = "QHeaderView::section " \
"{background-color:rgb(240, 240, 240)}"
CODEBOOK_HEADER_BACKGROUND_CSS = (
"QHeaderView::section " "{background-color:rgb(240, 240, 240)}"
)
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