continue implementing optional fields - still broken

This commit is contained in:
Roland W-H 2025-02-11 13:42:35 +00:00
parent 9143afc176
commit ecc2ce6d56

View File

@ -1,6 +1,6 @@
from PyQt6.QtCore import QRegularExpression, QEvent, QObject, QTimer from PyQt6.QtCore import QRegularExpression, QEvent, QObject, QTimer
from PyQt6.QtGui import QRegularExpressionValidator from PyQt6.QtGui import QRegularExpressionValidator
from PyQt6.QtWidgets import QWidget from PyQt6.QtWidgets import QWidget, QLayout
from PyQt6 import uic from PyQt6 import uic
import main_window import main_window
@ -37,6 +37,12 @@ class PlatformEdit(QWidget):
self.share_deal_reduce_amount_check self.share_deal_reduce_amount_check
] ]
self.required_fields = [
self.fund_deal_fee_box,
self.share_plat_fee_box,
self.share_deal_fee_box
]
# Create main window object, passing this instance as param # Create main window object, passing this instance as param
self.main_win = main_window.SIPPCompare(self) self.main_win = main_window.SIPPCompare(self)
@ -104,16 +110,27 @@ class PlatformEdit(QWidget):
# Check if all required fields have valid (non-zero) input # Check if all required fields have valid (non-zero) input
# TODO: Find a better way of doing this if possible # TODO: Find a better way of doing this if possible
def check_valid(self): def check_valid(self):
values = [self.fund_deal_fee_box.value(),
self.share_plat_fee_box.value(),
self.share_deal_fee_box.value()
]
valid = True valid = True
for value in values: for field in self.required_fields:
if value == 0: if field.value() == 0:
valid = False valid = False
for check_box in self.optional_check_boxes:
if check_box.isChecked():
check_box_pos = self.gridLayout.getItemPosition(
self.gridLayout.indexOf(check_box)
)
input_box_pos = list(check_box_pos)[:2]
input_box_pos[1] -= 1
input_box_item = self.gridLayout.itemAtPosition(input_box_pos[0], input_box_pos[1]).widget()
if input_box_item.staticMetaObject.className() == "QLineEdit":
if input_box_item.text() == "":
valid = False
elif input_box_item.staticMetaObject.className() == "QDoubleSpinBox":
if input_box_item.value() == 0:
valid = False
if valid: if valid:
self.save_but.setEnabled(True) self.save_but.setEnabled(True)
else: else: