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 1167a64dbcfce86fb8f9058aad4e547c21f51d1e..bb064752ca5eff9fde8259ff3ce53579df2030c9 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 @@ -11,7 +11,7 @@ from sohstationviewer.view.db_config.value_color_helper.\ EditValueColorDialog, display_color -TOTAL = 7 +ROW_TOTAL = 7 class BoundValidator(QtGui.QValidator): @@ -90,14 +90,14 @@ class MultiColorDotDialog(EditValueColorDialog): def setup_ui(self) -> None: - for i in range(TOTAL): + for i in range(ROW_TOTAL): if i == 0: self.main_layout.addWidget( self.include_less_than_chkbox, 0, 0, 1, 1) self.include_less_than_chkbox.setChecked(True) - if i == TOTAL - 1: + if i == ROW_TOTAL - 1: self.main_layout.addWidget( - self.include_greater_than_chkbox, TOTAL - 1, 0, 1, 1) + self.include_greater_than_chkbox, ROW_TOTAL - 1, 0, 1, 1) (lower_bound_lnedit, higher_bound_lnedit, select_color_btn, color_label) = self.add_row(i) self.lower_bound_lnedits.append(lower_bound_lnedit) @@ -106,16 +106,16 @@ class MultiColorDotDialog(EditValueColorDialog): self.color_labels.append(color_label) self.set_color_enabled(i, False) - self.setup_complete_buttons(TOTAL) + self.setup_complete_buttons(ROW_TOTAL) def connect_signals(self) -> None: self.include_greater_than_chkbox.clicked.connect( - lambda: self.on_include(TOTAL - 1, + lambda: self.on_include(ROW_TOTAL - 1, self.include_greater_than_chkbox)) self.include_less_than_chkbox.clicked.connect( lambda: self.on_include(0, self.include_less_than_chkbox)) - for i in range(TOTAL): + for i in range(ROW_TOTAL): self.higher_bound_lnedits[i].textChanged.connect( lambda arg, idx=i: setattr(self, 'changed_rowid', idx)) self.higher_bound_lnedits[i].editingFinished.connect( @@ -127,6 +127,9 @@ class MultiColorDotDialog(EditValueColorDialog): super().connect_signals() + def add_row(self, rowid): + pass + def on_higher_bound_editing_finished(self, rowid: int): """ Check value entered for higher bound: @@ -137,19 +140,28 @@ class MultiColorDotDialog(EditValueColorDialog): 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 + :param rowid: id of the row being checked. rowid == self.changed_rowid + when the method is ignited by user editing the row's value (not + by clicking on some buttons) """ 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. return - if len(self.rowid_value_dict) < self.changed_rowid < TOTAL - 1: + if len(self.rowid_value_dict) < self.changed_rowid < ROW_TOTAL - 1: + if self.higher_bound_lnedits[rowid].text() == '': + # called by clearing text in this section + return + self.changed_rowid = None # When user edit the row that skips some row from the last row # the current higher_bound_lnedit will be cleared - self.higher_bound_lnedits[self.changed_rowid].setText('') - self.changed_rowid = None + msg = ("You have to edit rows in order.\n" + "Skipping rows isn't allowed.") + QtWidgets.QMessageBox.information(self, "Error", msg) + self.higher_bound_lnedits[rowid].setText('') return + self.changed_rowid = None prev_higher_bound = ( @@ -231,11 +243,11 @@ class MultiColorDotDialog(EditValueColorDialog): rest to be the max of all higher bound """ self.rowid_value_dict = {i: float(self.higher_bound_lnedits[i].text()) - for i in range(TOTAL - 1) + for i in range(ROW_TOTAL - 1) if self.higher_bound_lnedits[i].text() != ''} - last_row_lnedit = (self.lower_bound_lnedits[TOTAL - 1] + last_row_lnedit = (self.lower_bound_lnedits[ROW_TOTAL - 1] if self.upper_equal - else self.higher_bound_lnedits[TOTAL - 1]) + else self.higher_bound_lnedits[ROW_TOTAL - 1]) if len(self.rowid_value_dict) == 0: last_row_lnedit.clear() else: @@ -287,15 +299,15 @@ class MultiColorDotDialog(EditValueColorDialog): self.include_less_than_chkbox.setChecked(False) else: self.include_less_than_chkbox.setChecked(True) - if vc_idx < TOTAL - 1: + if vc_idx < ROW_TOTAL - 1: self.higher_bound_lnedits[vc_idx].setText(str(value)) self.lower_bound_lnedits[vc_idx + 1].setText(str(value)) else: self.include_greater_than_chkbox.setChecked(True) if self.upper_equal: - self.lower_bound_lnedits[TOTAL - 1].setText(str(value)) + self.lower_bound_lnedits[ROW_TOTAL - 1].setText(str(value)) else: - self.higher_bound_lnedits[TOTAL - 1].setText(str(value)) + self.higher_bound_lnedits[ROW_TOTAL - 1].setText(str(value)) if color == 'not plot': self.set_color_enabled(vc_idx, False) else: @@ -314,13 +326,13 @@ class MultiColorDotDialog(EditValueColorDialog): + If include_greater_than_chkbox is checked, format will be: value<:color """ - if self.changed_rowid and self.changed_rowid < TOTAL - 1: + if self.changed_rowid and self.changed_rowid < ROW_TOTAL - 1: self.save_colors_btn_clicked = True self.on_higher_bound_editing_finished(self.changed_rowid) return self.save_colors_btn_clicked = False value_color_list = [] - for i in range(TOTAL - 1): + for i in range(ROW_TOTAL - 1): if self.color_labels[i].isHidden() and i != 0: continue value = self.higher_bound_lnedits[i].text() @@ -332,13 +344,13 @@ class MultiColorDotDialog(EditValueColorDialog): value_color_list.append(f"{operator}{value}:{color}") if self.include_greater_than_chkbox.isChecked(): - color = self.color_labels[TOTAL - 1].palette().window( + color = self.color_labels[ROW_TOTAL - 1].palette().window( ).color().name() if self.upper_equal: - val = f"{self.lower_bound_lnedits[TOTAL - 1].text()}" + val = f"{self.lower_bound_lnedits[ROW_TOTAL - 1].text()}" value_color_list.append(f"{val}<:{color}") else: - val = f"{self.higher_bound_lnedits[TOTAL - 1].text()}" + val = f"{self.higher_bound_lnedits[ROW_TOTAL - 1].text()}" value_color_list.append(f"={val}:{color}") self.value_color_str = '|'.join(value_color_list) @@ -361,7 +373,7 @@ class MultiColorDotLowerEqualDialog(MultiColorDotDialog): if rowid == 0: lower_bound_lnedit.setHidden(True) comp_text = " d <" - elif rowid < TOTAL - 1: + elif rowid < ROW_TOTAL - 1: lower_bound_lnedit.setEnabled(False) comp_text = "<= d <" else: @@ -370,11 +382,11 @@ 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: + if rowid == ROW_TOTAL - 1: higher_bound_lnedit.setEnabled(False) select_color_btn = QtWidgets.QPushButton("Select Color") @@ -414,7 +426,7 @@ class MultiColorDotLowerEqualDialog(MultiColorDotDialog): else: # Ex: =1:#FF00FF value = value.replace('=', '') - self.set_row(TOTAL - 1, float(value), color) + self.set_row(ROW_TOTAL - 1, float(value), color) class MultiColorDotUpperEqualDialog(MultiColorDotDialog): @@ -433,7 +445,7 @@ class MultiColorDotUpperEqualDialog(MultiColorDotDialog): if rowid == 0: lower_bound_lnedit.setHidden(True) comp_text = " d <=" - elif rowid < TOTAL - 1: + elif rowid < ROW_TOTAL - 1: lower_bound_lnedit.setEnabled(False) comp_text = "< d <=" else: @@ -445,7 +457,7 @@ class MultiColorDotUpperEqualDialog(MultiColorDotDialog): validator = BoundValidator() higher_bound_lnedit.setValidator(validator) self.main_layout.addWidget(higher_bound_lnedit, rowid, 3, 1, 1) - if rowid == TOTAL - 1: + if rowid == ROW_TOTAL - 1: higher_bound_lnedit.setHidden(True) select_color_btn = QtWidgets.QPushButton("Select Color") @@ -485,7 +497,7 @@ class MultiColorDotUpperEqualDialog(MultiColorDotDialog): else: # Ex: 1<:#FF00FF value = value.replace('<', '') - self.set_row(TOTAL - 1, float(value), color) + self.set_row(ROW_TOTAL - 1, float(value), color) if __name__ == '__main__':