diff --git a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py index 65a5cecaef2ef16ac7eedc95fb291fdec288f625..4c63963f0f74117641e124ef0f5e5ab3e2209417 100644 --- a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py +++ b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py @@ -1,7 +1,6 @@ import sys import platform import os - from typing import List, Dict from PySide2 import QtWidgets, QtCore, QtGui @@ -17,7 +16,10 @@ TOTAL = 7 class BoundValidator(QtGui.QValidator): """ - Validator that allow float value and empty string + Validator that allow float value and empty string. + Range of value is from -10, 10 because -20/20 are the values assigned to + higher bounds of the previous/next when the current row is 0 and last + so the editable higher bounds can't ever be reached to. Value '-' to allow typing negative float. If user type '-' only, it will be checked when editing is finished. """ @@ -28,7 +30,7 @@ class BoundValidator(QtGui.QValidator): input = float(input) except ValueError: return QtGui.QValidator.Invalid - if -20 <= input <= 20: + if -10 <= input <= 10: return QtGui.QValidator.Acceptable else: return QtGui.QValidator.Invalid @@ -61,6 +63,9 @@ class MultiColorDotDialog(EditValueColorDialog): # After a higher bound widget is edited and enter is hitted, button's # clicked signal will be called before higher_bound_editting_finished # is reached. The following flags are to change that order. + # These flags are also used to prevent the case hitting Select Color or + # Save right after user done with editing. In case there is error when + # checking the value, the button click will be canceled too. self.changed_rowid = None self.select_color_btn_clicked = False self.save_colors_btn_clicked = False @@ -127,15 +132,16 @@ class MultiColorDotDialog(EditValueColorDialog): Check value entered for higher bound: + If the last row is empty string, that value will be eliminated from condition. - + If other row is empty string, give error message + If value not greater than previous row and less than latter row, give error message. -20 and 20 are given to previous or latter row if not exist b/c they are out of range of bound [-10, 10] Call set_value_rowid_dict to keep track of value by rowid. + + :param rowid: rowid is """ if self.changed_rowid is None: # When the function isn't called from user's changing text on - # a higher_bound_lnedit, this function will be ignored + # a higher_bound_lnedit, this function will be ignored. return if len(self.rowid_value_dict) < self.changed_rowid < TOTAL - 1: @@ -164,6 +170,13 @@ class MultiColorDotDialog(EditValueColorDialog): else: # If the cleared one is the last one, the lower_bound_lnedit # of the next row will be cleared too. + if rowid == 0: + # If the cleared one is the only one, this shouldn't be + # allowed. A warning should be given. + msg = ("There should be at least one value" + " for this plot type.") + QtWidgets.QMessageBox.information(self, "Error", msg) + return self.set_color_enabled(rowid, False) self.lower_bound_lnedits[rowid + 1].setText('') self.set_value_rowid_dict() @@ -302,7 +315,6 @@ class MultiColorDotDialog(EditValueColorDialog): value<:color """ if self.changed_rowid and self.changed_rowid < TOTAL - 1: - print("on_save_color") self.save_colors_btn_clicked = True self.on_higher_bound_editing_finished(self.changed_rowid) return @@ -358,7 +370,8 @@ class MultiColorDotLowerEqualDialog(MultiColorDotDialog): self.main_layout.addWidget(QtWidgets.QLabel(comp_text), rowid, 2, 1, 1) higher_bound_lnedit = QtWidgets.QLineEdit() - validator = BoundValidator() + validator = BoundValidator + higher_bound_lnedit.setValidator(validator) self.main_layout.addWidget(higher_bound_lnedit, rowid, 3, 1, 1) if rowid == TOTAL - 1: @@ -485,4 +498,5 @@ if __name__ == '__main__': test = MultiColorDotUpperEqualDialog( None, '<=0:not plot|<=1:#FFFF00|<=2:#00FF00|2<:#FF00FF') test.exec_() - sys.exit(app.exec_()) + print("result:", test.value_color_str) + sys.exit(app.exec_()) \ No newline at end of file