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 2291e44080c35a9a34437a7a913104e422b2c27b..492ada7976555c6a45dbc4801498ea79760a1893 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 @@ -66,7 +66,7 @@ class MultiColorDotDialog(EditValueColorDialog): # 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.changed_row_id = None self.select_color_btn_clicked = False self.save_colors_btn_clicked = False @@ -76,8 +76,8 @@ class MultiColorDotDialog(EditValueColorDialog): # Check box for including data point greater than all the rest self.include_greater_than_chkbox = QtWidgets.QCheckBox('Include') - # Keep track of value by rowid - self.rowid_value_dict: Dict[int, float] = {} + # Keep track of value by row_id + self.row_id_value_dict: Dict[int, float] = {} super(MultiColorDotDialog, self).__init__(parent, value_color_str) self.setWindowTitle("Edit Multi Color Dot Plotting") @@ -86,7 +86,7 @@ class MultiColorDotDialog(EditValueColorDialog): self.cancel_btn.setFocusPolicy(QtCore.Qt.NoFocus) self.save_colors_btn.setFocusPolicy(QtCore.Qt.NoFocus) - self.set_value_rowid_dict() + self.set_value_row_id_dict() def setup_ui(self) -> None: @@ -117,7 +117,7 @@ class MultiColorDotDialog(EditValueColorDialog): for i in range(ROW_TOTAL): self.higher_bound_lnedits[i].textChanged.connect( - lambda arg, idx=i: setattr(self, 'changed_rowid', idx)) + lambda arg, idx=i: setattr(self, 'changed_row_id', idx)) self.higher_bound_lnedits[i].editingFinished.connect( lambda idx=i: self.on_higher_bound_editing_finished(idx)) # some how pass False to on_select_color, have to handle this @@ -127,33 +127,33 @@ class MultiColorDotDialog(EditValueColorDialog): super().connect_signals() - def get_comparing_text(self, rowid): + def get_comparing_text(self, row_id): pass - def add_row(self, rowid): + def add_row(self, row_id): """ Adding a row including Lower bound line dit, comparing operator label, higher bound line edit, select color button, display color label - :param rowid: id of current row + :param row_id: id of current row """ lower_bound_lnedit = QtWidgets.QLineEdit() lower_bound_lnedit.setEnabled(False) - comparing_text = self.get_comparing_text(rowid) + comparing_text = self.get_comparing_text(row_id) comparing_label = QtWidgets.QLabel(comparing_text) higher_bound_lnedit = QtWidgets.QLineEdit() validator = BoundValidator() higher_bound_lnedit.setValidator(validator) - if rowid == 0: + if row_id == 0: lower_bound_lnedit.setHidden(True) - elif rowid == ROW_TOTAL - 1: + elif row_id == ROW_TOTAL - 1: higher_bound_lnedit.setHidden(True) select_color_btn = QtWidgets.QPushButton("Select Color") select_color_btn.clicked.connect( - lambda: self.on_select_color(rowid)) + lambda: self.on_select_color(row_id)) # set focus policy to not be clicked by hitting enter in higher bound select_color_btn.setFocusPolicy(QtCore.Qt.NoFocus) @@ -162,16 +162,16 @@ class MultiColorDotDialog(EditValueColorDialog): color_label.setAutoFillBackground(True) # layout - self.main_layout.addWidget(lower_bound_lnedit, rowid, 1, 1, 1) - self.main_layout.addWidget(comparing_label, rowid, 2, 1, 1) - self.main_layout.addWidget(higher_bound_lnedit, rowid, 3, 1, 1) - self.main_layout.addWidget(select_color_btn, rowid, 4, 1, 1) - self.main_layout.addWidget(color_label, rowid, 5, 1, 1) + self.main_layout.addWidget(lower_bound_lnedit, row_id, 1, 1, 1) + self.main_layout.addWidget(comparing_label, row_id, 2, 1, 1) + self.main_layout.addWidget(higher_bound_lnedit, row_id, 3, 1, 1) + self.main_layout.addWidget(select_color_btn, row_id, 4, 1, 1) + self.main_layout.addWidget(color_label, row_id, 5, 1, 1) return (lower_bound_lnedit, higher_bound_lnedit, select_color_btn, color_label) - def handle_clear_higher_bound(self, rowid): + def handle_clear_higher_bound(self, row_id): """ If user clear higher_bound + in the middle, not allow. @@ -180,52 +180,52 @@ class MultiColorDotDialog(EditValueColorDialog): cleared, and the very end row's value will be set to the higher_bound of the previous row. """ - if rowid < len(self.rowid_value_dict) - 1: + if row_id < len(self.row_id_value_dict) - 1: # If the cleared one isn't the last one, it shouldn't be # allowed. An Error message should be given. msg = "Higher bound must be a number" QtWidgets.QMessageBox.information(self, "Error", msg) - self.higher_bound_lnedits[rowid].setText( - str(self.rowid_value_dict[rowid])) + self.higher_bound_lnedits[row_id].setText( + str(self.row_id_value_dict[row_id])) 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 row_id == 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() + self.set_color_enabled(row_id, False) + self.lower_bound_lnedits[row_id + 1].setText('') + self.set_value_row_id_dict() - def handle_skipping_editing_row(self, rowid): + def handle_skipping_editing_row(self, row_id): """ If user add value in a row that skipping from the last edited row, it shouldn't be allowed, an Error message should be given before the higher_bound is cleared, the actions will ignite the call to this function one more time which should be ignored. """ - if self.higher_bound_lnedits[rowid].text() == '': + if self.higher_bound_lnedits[row_id].text() == '': # called by clearing text in this section return - self.changed_rowid = None + self.changed_row_id = None # When user edit the row that skips some row from the last row # the current higher_bound_lnedit will be cleared 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('') + self.higher_bound_lnedits[row_id].setText('') def handle_edited_value_not_ascending( - self, rowid, prev_higher_bound, next_higher_bound): + self, row_id, prev_higher_bound, next_higher_bound): """ If value enter to the current higher_bound_lnedit make it out of increasing sorting, a warning will be given, and the widget will be set to the original value. - :param rowid: id of current row + :param row_id: id of current row :param prev_higher_bound: higher_bound value of the previous row :param next_higher_bound: higher_bound value of the next row """ @@ -237,16 +237,16 @@ class MultiColorDotDialog(EditValueColorDialog): msg = f"Value entered must be: {cond}" QtWidgets.QMessageBox.information(self, "Error", msg) try: - self.higher_bound_lnedits[rowid].setText( - str(self.rowid_value_dict[rowid])) + self.higher_bound_lnedits[row_id].setText( + str(self.row_id_value_dict[row_id])) except KeyError: # If the current row is the last one, there's no original value # So the widget will be cleared. - self.higher_bound_lnedits[rowid].setText('') + self.higher_bound_lnedits[row_id].setText('') self.select_color_btn_clicked = False self.save_colors_btn_clicked = False - def on_higher_bound_editing_finished(self, rowid: int): + def on_higher_bound_editing_finished(self, row_id: int): """ Check value entered for higher bound: + If the last row is empty string, that value will be eliminated @@ -254,104 +254,104 @@ class MultiColorDotDialog(EditValueColorDialog): + 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. + Call set_value_row_id_dict to keep track of value by row_id. - :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) + :param row_id: id of the row being checked. + row_id == self.changed_row_id when the method is ignited by + editing the row's value (not by clicking on some buttons) """ - if self.changed_rowid is None: + if self.changed_row_id 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 < ROW_TOTAL - 1: - self.handle_skipping_editing_row(rowid) + if len(self.row_id_value_dict) < self.changed_row_id < ROW_TOTAL - 1: + self.handle_skipping_editing_row(row_id) return - self.changed_rowid = None + self.changed_row_id = None prev_higher_bound = ( - float(self.higher_bound_lnedits[rowid - 1].text()) - if rowid > 0 else -20) + float(self.higher_bound_lnedits[row_id - 1].text()) + if row_id > 0 else -20) - if self.higher_bound_lnedits[rowid].text().strip() == '': - self.handle_clear_higher_bound(rowid) + if self.higher_bound_lnedits[row_id].text().strip() == '': + self.handle_clear_higher_bound(row_id) self.select_color_btn_clicked = False self.save_colors_btn_clicked = False return - if rowid >= len(self.rowid_value_dict) - 1: + if row_id >= len(self.row_id_value_dict) - 1: # When the current higher_bound_lnedits is on the last row # set the limit 20 to be the next_higher_bound next_higher_bound = 20 else: next_higher_bound = float( - self.higher_bound_lnedits[rowid + 1].text()) + self.higher_bound_lnedits[row_id + 1].text()) - curr_higher_bound = float(self.higher_bound_lnedits[rowid].text()) + curr_higher_bound = float(self.higher_bound_lnedits[row_id].text()) if (curr_higher_bound <= prev_higher_bound or curr_higher_bound >= next_higher_bound): - self.handle_edited_value_not_ascending(rowid, + self.handle_edited_value_not_ascending(row_id, prev_higher_bound, next_higher_bound) return - if ((rowid == 0 and self.include_less_than_chkbox.isChecked()) - or rowid != 0): + if ((row_id == 0 and self.include_less_than_chkbox.isChecked()) + or row_id != 0): # Enable button Select Color unless the row is the first row but # Include checkbox isn't checked - self.set_color_enabled(rowid, True) - self.lower_bound_lnedits[rowid + 1].setText(str(curr_higher_bound)) - self.set_value_rowid_dict() + self.set_color_enabled(row_id, True) + self.lower_bound_lnedits[row_id + 1].setText(str(curr_higher_bound)) + self.set_value_row_id_dict() if self.save_colors_btn_clicked: self.on_save_color() if self.select_color_btn_clicked: - self.on_select_color(rowid) + self.on_select_color(row_id) - def set_value_rowid_dict(self): + def set_value_row_id_dict(self): """ - Update rowid_value_dict to the current higher bound + Update row_id_value_dict to the current higher bound Update lower bound of the last row which is for greater than all the 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(ROW_TOTAL - 1) - if self.higher_bound_lnedits[i].text() != ''} + self.row_id_value_dict = {i: float(self.higher_bound_lnedits[i].text()) + for i in range(ROW_TOTAL - 1) + if self.higher_bound_lnedits[i].text() != ''} last_row_lnedit = self.lower_bound_lnedits[ROW_TOTAL - 1] - if len(self.rowid_value_dict) == 0: + if len(self.row_id_value_dict) == 0: last_row_lnedit.clear() else: - last_row_lnedit.setText(str(max(self.rowid_value_dict.values()))) + last_row_lnedit.setText(str(max(self.row_id_value_dict.values()))) - def set_color_enabled(self, rowid: int, enabled: bool): + def set_color_enabled(self, row_id: int, enabled: bool): """ Enable color: allow to edit and display color Disable color: disallow to edit and hide color """ - self.select_color_btns[rowid].setEnabled(enabled) - self.color_labels[rowid].setHidden(not enabled) + self.select_color_btns[row_id].setEnabled(enabled) + self.color_labels[row_id].setHidden(not enabled) - def on_select_color(self, rowid: int): + def on_select_color(self, row_id: int): """ When clicking on Select Color button, Color Picker will pop up with the default color is color_label's color. User will select a color then save to update the selected color to the color_label. """ - if self.changed_rowid is not None: + if self.changed_row_id is not None: self.select_color_btn_clicked = True - self.on_higher_bound_editing_finished(self.changed_rowid) + self.on_higher_bound_editing_finished(self.changed_row_id) return self.select_color_btn_clicked = False - super().on_select_color(self.color_labels[rowid]) + super().on_select_color(self.color_labels[row_id]) - def on_include(self, rowid: int, chkbox: QtWidgets.QCheckBox): + def on_include(self, row_id: int, chkbox: QtWidgets.QCheckBox): """ Enable/Disable Select Color button when include_less_than_chkbox/ include_greater_than_chkbox is checked/unchecked. """ - self.set_color_enabled(rowid, chkbox.isChecked()) + self.set_color_enabled(row_id, chkbox.isChecked()) def set_row(self, vc_idx: int, value: float, color: str): """ @@ -392,9 +392,9 @@ class MultiColorDotDialog(EditValueColorDialog): + If include_greater_than_chkbox is checked, format will be: value<:color """ - if self.changed_rowid and self.changed_rowid < ROW_TOTAL - 1: + if self.changed_row_id and self.changed_row_id < ROW_TOTAL - 1: self.save_colors_btn_clicked = True - self.on_higher_bound_editing_finished(self.changed_rowid) + self.on_higher_bound_editing_finished(self.changed_row_id) return self.save_colors_btn_clicked = False value_color_list = [] @@ -427,15 +427,15 @@ class MultiColorDotLowerEqualDialog(MultiColorDotDialog): super(MultiColorDotLowerEqualDialog, self).__init__( parent, value_color_str, upper_equal=False) - def get_comparing_text(self, rowid: int): + def get_comparing_text(self, row_id: int): """ Create text that show relationship between lower_bound and higher_bound to data for the selected color. - :param rowid: id of current row + :param row_id: id of current row """ - if rowid == 0: + if row_id == 0: comparing_text = " d <" - elif rowid < ROW_TOTAL - 1: + elif row_id < ROW_TOTAL - 1: comparing_text = "<= d <" else: comparing_text = "= d" @@ -471,15 +471,15 @@ class MultiColorDotUpperEqualDialog(MultiColorDotDialog): super(MultiColorDotUpperEqualDialog, self).__init__( parent, value_color_str, upper_equal=True) - def get_comparing_text(self, rowid): + def get_comparing_text(self, row_id): """ Create text that show relationship between lower_bound and higher_bound to data for the selected color. - :param rowid: id of current row + :param row_id: id of current row """ - if rowid == 0: + if row_id == 0: comparing_text = " d <=" - elif rowid < ROW_TOTAL - 1: + elif row_id < ROW_TOTAL - 1: comparing_text = "< d <=" else: comparing_text = "< d "