Created WastewaterArticAssociation, added tip handling.
This commit is contained in:
@@ -2,8 +2,7 @@ import sys
|
||||
from pprint import pformat
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtWidgets import (QDialog, QComboBox, QCheckBox,
|
||||
QLabel, QWidget, QHBoxLayout,
|
||||
QVBoxLayout, QDialogButtonBox, QGridLayout)
|
||||
QLabel, QWidget, QVBoxLayout, QDialogButtonBox, QGridLayout)
|
||||
from backend.db.models import Equipment, BasicSubmission, Process
|
||||
from backend.validators.pydant import PydEquipment, PydEquipmentRole, PydTips
|
||||
import logging
|
||||
@@ -11,9 +10,10 @@ from typing import List
|
||||
|
||||
logger = logging.getLogger(f"submissions.{__name__}")
|
||||
|
||||
|
||||
class EquipmentUsage(QDialog):
|
||||
|
||||
def __init__(self, parent, submission:BasicSubmission) -> QDialog:
|
||||
def __init__(self, parent, submission: BasicSubmission) -> QDialog:
|
||||
super().__init__(parent)
|
||||
self.submission = submission
|
||||
self.setWindowTitle("Equipment Checklist")
|
||||
@@ -29,7 +29,7 @@ class EquipmentUsage(QDialog):
|
||||
def populate_form(self):
|
||||
"""
|
||||
Create form widgets
|
||||
"""
|
||||
"""
|
||||
QBtn = QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
|
||||
self.buttonBox = QDialogButtonBox(QBtn)
|
||||
self.buttonBox.accepted.connect(self.accept)
|
||||
@@ -49,43 +49,44 @@ class EquipmentUsage(QDialog):
|
||||
|
||||
Returns:
|
||||
List[PydEquipment]: All equipment pulled from widgets
|
||||
"""
|
||||
"""
|
||||
output = []
|
||||
for widget in self.findChildren(QWidget):
|
||||
match widget:
|
||||
case RoleComboBox() :
|
||||
case RoleComboBox():
|
||||
if widget.check.isChecked():
|
||||
output.append(widget.parse_form())
|
||||
case _:
|
||||
pass
|
||||
logger.debug(f"parsed output of Equsage form: {pformat(output)}")
|
||||
return [item for item in output if item is not None]
|
||||
|
||||
|
||||
class LabelRow(QWidget):
|
||||
|
||||
def __init__(self, parent) -> None:
|
||||
super().__init__(parent)
|
||||
self.layout = QHBoxLayout()
|
||||
self.layout = QGridLayout()
|
||||
self.check = QCheckBox()
|
||||
self.layout.addWidget(self.check)
|
||||
self.layout.addWidget(self.check, 0, 0)
|
||||
self.check.stateChanged.connect(self.check_all)
|
||||
for item in ["Role", "Equipment", "Process", "Tips"]:
|
||||
for iii, item in enumerate(["Role", "Equipment", "Process", "Tips"], start=1):
|
||||
l = QLabel(item)
|
||||
l.setMaximumWidth(200)
|
||||
l.setMinimumWidth(200)
|
||||
self.layout.addWidget(l)
|
||||
self.layout.addWidget(l, 0, iii, alignment=Qt.AlignmentFlag.AlignRight)
|
||||
self.setLayout(self.layout)
|
||||
|
||||
def check_all(self):
|
||||
"""
|
||||
Toggles all checkboxes in the form
|
||||
"""
|
||||
"""
|
||||
for object in self.parent().findChildren(QCheckBox):
|
||||
object.setChecked(self.check.isChecked())
|
||||
|
||||
|
||||
class RoleComboBox(QWidget):
|
||||
|
||||
def __init__(self, parent, role:PydEquipmentRole, used:list) -> None:
|
||||
def __init__(self, parent, role: PydEquipmentRole, used: list) -> None:
|
||||
super().__init__(parent)
|
||||
# self.layout = QHBoxLayout()
|
||||
self.layout = QGridLayout()
|
||||
@@ -105,27 +106,23 @@ class RoleComboBox(QWidget):
|
||||
self.process.setMinimumWidth(200)
|
||||
self.process.setEditable(False)
|
||||
self.process.currentTextChanged.connect(self.update_tips)
|
||||
# self.tips = QComboBox()
|
||||
# self.tips.setMaximumWidth(200)
|
||||
# self.tips.setMinimumWidth(200)
|
||||
# self.tips.setEditable(True)
|
||||
self.layout.addWidget(self.check,0,0)
|
||||
self.layout.addWidget(self.check, 0, 0)
|
||||
label = QLabel(f"{role.name}:")
|
||||
label.setMinimumWidth(200)
|
||||
label.setMaximumWidth(200)
|
||||
label.setAlignment(Qt.AlignmentFlag.AlignLeft)
|
||||
self.layout.addWidget(label,0,1)
|
||||
self.layout.addWidget(self.box,0,2)
|
||||
self.layout.addWidget(self.process,0,3)
|
||||
self.layout.addWidget(label, 0, 1)
|
||||
self.layout.addWidget(self.box, 0, 2)
|
||||
self.layout.addWidget(self.process, 0, 3)
|
||||
self.setLayout(self.layout)
|
||||
|
||||
|
||||
def update_processes(self):
|
||||
"""
|
||||
Changes processes when equipment is changed
|
||||
"""
|
||||
"""
|
||||
equip = self.box.currentText()
|
||||
# logger.debug(f"Updating equipment: {equip}")
|
||||
equip2 = [item for item in self.role.equipment if item.name==equip][0]
|
||||
equip2 = [item for item in self.role.equipment if item.name == equip][0]
|
||||
# logger.debug(f"Using: {equip2}")
|
||||
self.process.clear()
|
||||
self.process.addItems([item for item in equip2.processes if item in self.role.processes])
|
||||
@@ -143,24 +140,25 @@ class RoleComboBox(QWidget):
|
||||
widget.addItems(tip_choices)
|
||||
# logger.debug(f"Tiprole: {tip_role.__dict__}")
|
||||
widget.setObjectName(f"tips_{tip_role.name}")
|
||||
widget.setMinimumWidth(100)
|
||||
widget.setMaximumWidth(100)
|
||||
widget.setMinimumWidth(200)
|
||||
widget.setMaximumWidth(200)
|
||||
self.layout.addWidget(widget, iii, 4)
|
||||
else:
|
||||
widget = QLabel("")
|
||||
widget.setMinimumWidth(100)
|
||||
widget.setMaximumWidth(100)
|
||||
self.layout.addWidget(widget,0,4)
|
||||
widget.setMinimumWidth(200)
|
||||
widget.setMaximumWidth(200)
|
||||
self.layout.addWidget(widget, 0, 4)
|
||||
|
||||
def parse_form(self) -> PydEquipment|None:
|
||||
def parse_form(self) -> PydEquipment | None:
|
||||
"""
|
||||
Creates PydEquipment for values in form
|
||||
|
||||
Returns:
|
||||
PydEquipment|None: PydEquipment matching form
|
||||
"""
|
||||
"""
|
||||
eq = Equipment.query(name=self.box.currentText())
|
||||
tips = [PydTips(name=item.currentText(), role=item.objectName().lstrip("tips").lstrip("_")) for item in self.findChildren(QComboBox) if item.objectName().startswith("tips")]
|
||||
tips = [PydTips(name=item.currentText(), role=item.objectName().lstrip("tips").lstrip("_")) for item in
|
||||
self.findChildren(QComboBox) if item.objectName().startswith("tips")]
|
||||
logger.debug(tips)
|
||||
try:
|
||||
return PydEquipment(
|
||||
@@ -173,4 +171,3 @@ class RoleComboBox(QWidget):
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Could create PydEquipment due to: {e}")
|
||||
|
||||
Reference in New Issue
Block a user