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

Fikset error i codebook_widget

parent 6eb682a7
No related branches found
No related tags found
No related merge requests found
Pipeline #78188 passed
...@@ -10,7 +10,6 @@ from PySide2.QtWidgets import ( ...@@ -10,7 +10,6 @@ from PySide2.QtWidgets import (
QWidget, QWidget,
) )
from PySide2.QtCore import Qt from PySide2.QtCore import Qt
from soitool.database import Database
from soitool.codebook_model_view import CodeBookTableModel, CodeBookTableView from soitool.codebook_model_view import CodeBookTableModel, CodeBookTableView
...@@ -29,6 +28,8 @@ class CodebookRowAdder(QWidget): ...@@ -29,6 +28,8 @@ class CodebookRowAdder(QWidget):
database. Therefore, this reference is needed to be able to database. Therefore, this reference is needed to be able to
insert new rows, but it is also used to refresh the view when insert new rows, but it is also used to refresh the view when
the row is inserted. the row is inserted.
database : soitool.database.Database
Database to use.
Raises Raises
------ ------
...@@ -37,7 +38,7 @@ class CodebookRowAdder(QWidget): ...@@ -37,7 +38,7 @@ class CodebookRowAdder(QWidget):
None (default) or CodeBookTableView. None (default) or CodeBookTableView.
""" """
def __init__(self, codebook_view=None): def __init__(self, database, codebook_view=None):
super().__init__() super().__init__()
# Raise error if argument is invalid # Raise error if argument is invalid
...@@ -49,6 +50,7 @@ class CodebookRowAdder(QWidget): ...@@ -49,6 +50,7 @@ class CodebookRowAdder(QWidget):
+ "'{}'".format(codebook_view) + "'{}'".format(codebook_view)
) )
self.database = database
self.codebook_view = codebook_view self.codebook_view = codebook_view
self.create_widgets() self.create_widgets()
...@@ -169,8 +171,6 @@ class CodebookRowAdder(QWidget): ...@@ -169,8 +171,6 @@ class CodebookRowAdder(QWidget):
if len(category_input) > 0: if len(category_input) > 0:
category_input = category_input[0].upper() + category_input[1:] category_input = category_input[0].upper() + category_input[1:]
db = Database()
try: try:
# If a view is used, remove its model temporarily # If a view is used, remove its model temporarily
if self.codebook_view is not None: if self.codebook_view is not None:
...@@ -181,13 +181,13 @@ class CodebookRowAdder(QWidget): ...@@ -181,13 +181,13 @@ class CodebookRowAdder(QWidget):
"INSERT INTO CodeBook(Word, Category, Type)" "INSERT INTO CodeBook(Word, Category, Type)"
+ "VALUES(?, ?, ?)" + "VALUES(?, ?, ?)"
) )
db.conn.execute( self.database.conn.execute(
stmt, (word_input, category_input, type_input,) stmt, (word_input, category_input, type_input,)
) )
# Add unique code to row and commit changes # Add unique code to row and commit changes
db.add_code_to(word_input) self.database.add_code_to(word_input)
db.conn.commit() self.database.conn.commit()
# Give feedback and reset input # Give feedback and reset input
self.label_feedback.setText("Ord/Uttrykk lagt til.") self.label_feedback.setText("Ord/Uttrykk lagt til.")
......
...@@ -7,12 +7,12 @@ from soitool.codebook_row_adder import CodebookRowAdder ...@@ -7,12 +7,12 @@ from soitool.codebook_row_adder import CodebookRowAdder
class CodebookWidget(QWidget): class CodebookWidget(QWidget):
"""Widget for viewing and editing codebook.""" """Widget for viewing and editing codebook."""
def __init__(self): def __init__(self, database):
super().__init__() super().__init__()
# Create widgets # Create widgets
self.view = CodeBookTableView() self.view = CodeBookTableView(database)
self.row_adder = CodebookRowAdder() self.row_adder = CodebookRowAdder(database, self.view)
self.create_and_set_layouts() self.create_and_set_layouts()
......
...@@ -197,7 +197,7 @@ class MainWindow(QMainWindow): ...@@ -197,7 +197,7 @@ class MainWindow(QMainWindow):
break break
# Codebook-tab does not exist, create, add and select tab # Codebook-tab does not exist, create, add and select tab
else: else:
tab = CodebookWidget() tab = CodebookWidget(self.database)
self.tabs.addTab(tab, "Kodebok") self.tabs.addTab(tab, "Kodebok")
self.tabs.setCurrentWidget(tab) self.tabs.setCurrentWidget(tab)
......
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