From fcbc78b05b2448c6d97555ff77801566f8c45088 Mon Sep 17 00:00:00 2001 From: Roland W-H Date: Tue, 11 Feb 2025 15:52:36 +0000 Subject: [PATCH] opt field input validation complete - functionality still TODO --- gui/platform_edit.ui | 9 ++++++++ src/platform_edit.py | 55 ++++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/gui/platform_edit.ui b/gui/platform_edit.ui index 6233405..abd0088 100644 --- a/gui/platform_edit.ui +++ b/gui/platform_edit.ui @@ -62,6 +62,9 @@ + + false + QAbstractSpinBox::ButtonSymbols::NoButtons @@ -75,6 +78,9 @@ + + false + QAbstractSpinBox::ButtonSymbols::NoButtons @@ -188,6 +194,9 @@ + + false + QAbstractSpinBox::ButtonSymbols::NoButtons diff --git a/src/platform_edit.py b/src/platform_edit.py index e5dd0f9..846551d 100644 --- a/src/platform_edit.py +++ b/src/platform_edit.py @@ -30,6 +30,19 @@ class PlatformEdit(QWidget): if autofill: self.save_but.setEnabled(True) + self.required_fields = [ + self.fund_deal_fee_box, + self.share_plat_fee_box, + self.share_deal_fee_box + ] + + self.optional_fields = [ + self.plat_name_box, + self.share_plat_max_fee_box, + self.share_deal_reduce_trades_box, + self.share_deal_reduce_amount_box + ] + self.optional_check_boxes = [ self.plat_name_check, self.share_plat_max_fee_check, @@ -37,21 +50,21 @@ class PlatformEdit(QWidget): 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 self.main_win = main_window.SIPPCompare(self) # Handle events # NOTE: Signal defined in UI file to close window when save button clicked self.save_but.clicked.connect(self.init_variables) - self.fund_deal_fee_box.valueChanged.connect(self.check_valid) - self.share_plat_fee_box.valueChanged.connect(self.check_valid) - self.share_deal_fee_box.valueChanged.connect(self.check_valid) + + for field in self.required_fields: + field.valueChanged.connect(self.check_valid) + + for field in self.optional_fields: + if field.staticMetaObject.className() == "QLineEdit": + field.textChanged.connect(self.check_valid) + elif field.staticMetaObject.className() == "QDoubleSpinBox": + field.valueChanged.connect(self.check_valid) for check_box in self.optional_check_boxes: check_box.checkStateChanged.connect(self.check_valid) @@ -98,17 +111,13 @@ class PlatformEdit(QWidget): # When focus is given to an input box, select all text in it (easier to edit) def eventFilter(self, obj: QObject, event: QEvent): - if obj.staticMetaObject.className() == "QDoubleSpinBox" and event.type() == QEvent.Type.FocusIn: + if event.type() == QEvent.Type.FocusIn: # Alternative condition for % suffix - currently unused #if obj.value() == 0 or obj == self.share_plat_fee_box: QTimer.singleShot(0, obj.selectAll) - #if obj in self.optional_check_boxes and \ - #event.type() == QEvent.Type.FocusIn or event.type() == QEvent.Type.FocusOut: - # print("Working") return False # Check if all required fields have valid (non-zero) input - # TODO: Find a better way of doing this if possible def check_valid(self): valid = True @@ -117,19 +126,21 @@ class PlatformEdit(QWidget): valid = False for check_box in self.optional_check_boxes: + 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 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": + input_box_item.setEnabled(True) + input_box_type = input_box_item.staticMetaObject.className() + if input_box_type == "QLineEdit": if input_box_item.text() == "": valid = False - elif input_box_item.staticMetaObject.className() == "QDoubleSpinBox": + elif input_box_type == "QDoubleSpinBox" or input_box_type == "QSpinBox": if input_box_item.value() == 0: valid = False + else: + input_box_item.setEnabled(False) if valid: self.save_but.setEnabled(True)