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

#38 #39 Småjusteringer i docstrings og kommentarer

parent ab02c0e7
No related branches found
No related tags found
1 merge request!40#38 #39 Eksporter og importer SOI til/fra fil
Pipeline #76134 failed
......@@ -77,7 +77,7 @@ class MainWindow(QMainWindow):
self.setWindowIcon(QIcon(filepath))
# pylint: disable=R0914, R0915
# Ignoring "Too manu local variables" and "Too many statements"
# Ignoring "Too many local variables" and "Too many statements"
def setup_menubar(self):
"""Set up menubar with submenus and actions."""
menu = self.menuBar()
......@@ -132,8 +132,8 @@ class MainWindow(QMainWindow):
export_uncompressed.triggered.connect(
partial(self.try_export_soi, compressed=False)
)
export_serialized_soi.addAction(export_uncompressed)
export_serialized_soi.addAction(export_compressed)
export_serialized_soi.addAction(export_uncompressed)
file_menu.addMenu(export_serialized_soi)
# View/edit Codebook
......@@ -207,8 +207,8 @@ class MainWindow(QMainWindow):
def try_export_soi(self, compressed=True):
"""Export the SOI in the current tab.
Feedback is given through a dialog if the current tab does not show a
SOI (tab is not a SOIWorkspaceWidget).
Feedback is given through a dialog if the current tab does not contain
an SOI (tab is not a SOIWorkspaceWidget).
Parameters
----------
......@@ -217,7 +217,7 @@ class MainWindow(QMainWindow):
"""
tab_widget = self.tabs.currentWidget()
# If tab contains a SOI
# If tab contains an SOI
if isinstance(tab_widget, SOIWorkspaceWidget):
export_soi(tab_widget.soi, compressed)
else:
......@@ -230,11 +230,12 @@ class MainWindow(QMainWindow):
def import_soi(self):
"""Import serialized SOI.
Launches a QFileDialog with .txt and .json as accepted file extensions.
Launches a QFileDialog with a name-filter, where .txt and .json are
accepted file extensions.
A SOIWorkspaceWidget containing the SOI-object is created and opened
in a new tab, which is selected.
"""
# Get file-name from dialog
# Get file-path from dialog
file_path = QFileDialog().getOpenFileName(
self,
"Åpne SOI",
......
......@@ -102,8 +102,10 @@ class ModuleList(QListWidget):
Is sent to super().
"""
super().currentChanged(current, previous)
self.original_element_name = self.item(current.row()).text()
self.original_element_index = current.row()
# If an item is selected
if current.row() != -1:
self.original_element_name = self.item(current.row()).text()
self.original_element_index = current.row()
def dataChanged(self, index1, index2, roles):
"""Check for duplicate name and notify parent when an element changes.
......
......@@ -37,9 +37,11 @@ class TableModule(ModuleBase, QTableWidget, metaclass=Meta):
QTableWidget.__init__(self)
ModuleBase.__init__(self)
# Remove headers
# Remove headers and scrollbars
self.horizontalHeader().hide()
self.verticalHeader().hide()
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
# If parameters are None, start as empty table.
if size is None and content is None:
......@@ -74,10 +76,6 @@ class TableModule(ModuleBase, QTableWidget, metaclass=Meta):
self.setFixedWidth(size["width"])
self.setFixedHeight(size["height"])
# Remove scrollbars
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.cellChanged.connect(self.resize)
def keyPressEvent(self, event):
......
......@@ -23,9 +23,9 @@ def serialize_soi(soi):
Raises
------
TypeError
Raises error if parameter 'soi' is not a SOI.
Raises error if parameter 'soi' is not an SOI.
"""
# If parameter 'soi' is not a SOI
# If parameter 'soi' is not an SOI
if not isinstance(soi, SOI):
raise TypeError(
"Invalid type for parameter 'soi': " + "'{}'.".format(soi)
......@@ -81,14 +81,14 @@ def export_soi(soi, compressed=True):
A .json-file is created to contain uncompressed SOI.
The generated file-name will be on the format: "SOI_title_YYYY_mm_dd",
where title is the soi-title.
where title is the SOI-title.
Parameters
----------
soi: soitool.soi.SOI
SOI to export
compressed : bool, optional
Serialized SOI is compressed if True (default).
Serialized SOI will be compressed if True (default).
"""
# Serialize SOI
serialized = serialize_soi(soi)
......@@ -117,7 +117,7 @@ def import_soi(file_path):
Parameters
----------
file_path : string
full path to file containing serialized SOI
Full path to a file containing serialized SOI.
Returns
-------
......
......@@ -108,7 +108,7 @@ SCHEMA = Schema(
class SerializeTest(unittest.TestCase):
"""Testcase for functions in module 'serialize_export_import.py'."""
"""Testcase for functions in module 'serialize_export_import_soi.py'."""
def setUp(self):
"""Create SOI-object and generate filepath for exported SOI."""
......
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