Code cleanup and documentation

This commit is contained in:
Landon Wark
2024-02-09 14:03:35 -06:00
parent eda62fba5a
commit a534d229a8
30 changed files with 1558 additions and 1347 deletions

View File

@@ -1,7 +1,7 @@
# import required modules
# from PyQt6.QtCore import Qt
"""
Gel box for artic quality control
"""
from PyQt6.QtWidgets import *
# import sys
from PyQt6.QtWidgets import QWidget
import numpy as np
import pyqtgraph as pg
@@ -9,11 +9,17 @@ from PyQt6.QtGui import *
from PyQt6.QtCore import *
from PIL import Image
import numpy as np
import logging
from pprint import pformat
from typing import Tuple, List
from pathlib import Path
logger = logging.getLogger(f"submissions.{__name__}")
# Main window class
class GelBox(QDialog):
def __init__(self, parent, img_path):
def __init__(self, parent, img_path:str|Path):
super().__init__(parent)
# setting title
self.setWindowTitle("PyQtGraph")
@@ -27,11 +33,12 @@ class GelBox(QDialog):
# calling method
self.UiComponents()
# showing all the widgets
# self.show()
# method for components
def UiComponents(self):
# widget = QWidget()
"""
Create widgets in ui
"""
# setting configuration options
pg.setConfigOptions(antialias=True)
# creating image view object
@@ -39,33 +46,41 @@ class GelBox(QDialog):
img = np.array(Image.open(self.img_path).rotate(-90).transpose(Image.FLIP_LEFT_RIGHT))
self.imv.setImage(img)#, xvals=np.linspace(1., 3., data.shape[0]))
layout = QGridLayout()
layout.addWidget(QLabel("DNA Core Submission Number"),0,1)
self.core_number = QLineEdit()
layout.addWidget(self.core_number, 0,2)
# setting this layout to the widget
# widget.setLayout(layout)
# plot window goes on right side, spanning 3 rows
layout.addWidget(self.imv, 0, 0,20,20)
layout.addWidget(self.imv, 1, 1,20,20)
# setting this widget as central widget of the main window
self.form = ControlsForm(parent=self)
layout.addWidget(self.form,21,1,1,4)
layout.addWidget(self.form,22,1,1,4)
QBtn = QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
self.buttonBox = QDialogButtonBox(QBtn)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
layout.addWidget(self.buttonBox, 21, 5, 1, 1)#, alignment=Qt.AlignmentFlag.AlignTop)
# self.buttonBox.clicked.connect(self.submit)
layout.addWidget(self.buttonBox, 22, 5, 1, 1)#, alignment=Qt.AlignmentFlag.AlignTop)
self.setLayout(layout)
def parse_form(self):
return self.img_path, self.form.parse_form()
def parse_form(self) -> Tuple[str, str|Path, list]:
"""
Get relevant values from self/form
Returns:
Tuple[str, str|Path, list]: output values
"""
dna_core_submission_number = self.core_number.text()
return dna_core_submission_number, self.img_path, self.form.parse_form()
class ControlsForm(QWidget):
def __init__(self, parent) -> None:
super().__init__(parent)
self.layout = QGridLayout()
columns = []
rows = []
for iii, item in enumerate(["Negative Control Key", "Description", "Results - 65 C", "Results - 63 C", "Results - Spike"]):
for iii, item in enumerate(["Negative Control Key", "Description", "Results - 65 C", "Results - 63 C", "Results - Spike"]):
label = QLabel(item)
self.layout.addWidget(label, 0, iii,1,1)
if iii > 1:
@@ -85,11 +100,22 @@ class ControlsForm(QWidget):
self.layout.addWidget(widge, iii+1, jjj+2, 1, 1)
self.setLayout(self.layout)
def parse_form(self):
dicto = {}
def parse_form(self) -> List[dict]:
"""
Pulls the controls statuses from the form.
Returns:
List[dict]: output of values
"""
output = []
for le in self.findChildren(QLineEdit):
label = [item.strip() for item in le.objectName().split(" : ")]
if label[0] not in dicto.keys():
dicto[label[0]] = {}
dicto[label[0]][label[1]] = le.text()
return dicto
try:
dicto = [item for item in output if item['name']==label[0]][0]
except IndexError:
dicto = dict(name=label[0], values=[])
dicto['values'].append(dict(name=label[1], value=le.text()))
if label[0] not in [item['name'] for item in output]:
output.append(dicto)
logger.debug(pformat(output))
return output