diff --git a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/line_dot_dialog.py b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/line_dot_dialog.py new file mode 100644 index 0000000000000000000000000000000000000000..6f794f1585806ea240fe1f87c3127dc084e1072d --- /dev/null +++ b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/line_dot_dialog.py @@ -0,0 +1,109 @@ +import sys +import platform +import os + +from PySide2 import QtWidgets +from PySide2.QtWidgets import QWidget + +from sohstationviewer.view.db_config.value_color_helper.\ + edit_value_color_dialog.edit_value_color_dialog_super_class import \ + EditValueColorDialog, display_color + + +class LineDotDialog(EditValueColorDialog): + def __init__(self, parent: QWidget, value_color_str: str): + """ + Dialog to edit color for Line/Dot Plot + + :param parent: the parent widget + :param value_color_str: string for value color to be saved in DB + """ + # Widget that allow user to add/edit line's color + self.select_line_color_btn = QtWidgets.QPushButton("Select Color") + # Widget to display line's color + self.line_color_label = QtWidgets.QLabel() + self.line_color_label.setFixedWidth(30) + self.line_color_label.setAutoFillBackground(True) + + # check box to include dot in value_color_str or not + self.dot_include_chkbox = QtWidgets.QCheckBox('Included') + # Widget that allow user to add/edit dot's color + self.select_dot_color_btn = QtWidgets.QPushButton("Select Color") + # Widget to display dot's color + self.dot_color_label = QtWidgets.QLabel() + self.dot_color_label.setFixedWidth(30) + self.dot_color_label.setAutoFillBackground(True) + + super(LineDotDialog, self).__init__(parent, value_color_str) + self.setWindowTitle("Edit Line/Dot Plotting's Colors") + + self.on_click_include_dot() + + def setup_ui(self) -> None: + self.main_layout.addWidget(QtWidgets.QLabel('Line Color'), 0, 1, 1, 1) + self.main_layout.addWidget(self.line_color_label, 0, 2, 1, 1) + self.main_layout.addWidget(self.select_line_color_btn, 0, 3, 1, 1) + + self.main_layout.addWidget(self.dot_include_chkbox, 1, 0, 1, 1) + self.main_layout.addWidget(QtWidgets.QLabel('Dot Color'), 1, 1, 1, 1) + self.main_layout.addWidget(self.dot_color_label, 1, 2, 1, 1) + self.main_layout.addWidget(self.select_dot_color_btn, 1, 3, 1, 1) + + self.setup_complete_buttons(2) + + def connect_signals(self) -> None: + self.select_line_color_btn.clicked.connect( + lambda: self.on_select_color(self.line_color_label)) + self.select_dot_color_btn.clicked.connect( + lambda: self.on_select_color(self.dot_color_label)) + self.dot_include_chkbox.clicked.connect(self.on_click_include_dot) + super().connect_signals() + + def on_click_include_dot(self): + """ + Enable/disable select color and show/hide color label according to + dot_include_chkbox is checked or unchecked. + """ + enabled = self.dot_include_chkbox.isChecked() + self.select_dot_color_btn.setEnabled(enabled) + self.dot_color_label.setHidden(not enabled) + + def set_value(self): + """ + Change the corresponding color_labels's color according to the color + from value_color_str. + """ + self.dot_include_chkbox.setChecked(False) + if self.value_color_str == "": + return + vc_parts = self.value_color_str.split('|') + for vc_str in vc_parts: + obj_type, color = vc_str.split(':') + if obj_type == 'Line': + display_color(self.line_color_label, color) + if obj_type == 'Dot': + display_color(self.dot_color_label, color) + self.dot_include_chkbox.setChecked(True) + + def on_save_color(self): + """ + Create value_color_str from GUI's info and close the GUI with color + is the hex color got from color_labels' color + """ + line_color = self.line_color_label.palette().window().color().name() + self.value_color_str = f"Line:{line_color}" + if self.dot_include_chkbox.isChecked(): + dot_color = self.dot_color_label.palette().window().color().name() + self.value_color_str += f"|Dot:{dot_color}" + self.close() + + +if __name__ == '__main__': + os_name, version, *_ = platform.platform().split('-') + if os_name == 'macOS': + os.environ['QT_MAC_WANTS_LAYER'] = '1' + app = QtWidgets.QApplication(sys.argv) + test = LineDotDialog(None, "Line:#00FF00|Dot:#00FF00") + test.exec_() + print("result:", test.value_color_str) + sys.exit(app.exec_()) 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 4c63963f0f74117641e124ef0f5e5ab3e2209417..1167a64dbcfce86fb8f9058aad4e547c21f51d1e 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 @@ -499,4 +499,4 @@ if __name__ == '__main__': None, '<=0:not plot|<=1:#FFFF00|<=2:#00FF00|2<:#FF00FF') test.exec_() print("result:", test.value_color_str) - sys.exit(app.exec_()) \ No newline at end of file + sys.exit(app.exec_()) diff --git a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/tri_color_lines_dialog.py b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/tri_color_lines_dialog.py new file mode 100644 index 0000000000000000000000000000000000000000..9ca2b88d638551ab4746865d973763d46a435ee4 --- /dev/null +++ b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/tri_color_lines_dialog.py @@ -0,0 +1,110 @@ +import sys +import platform +import os + +from PySide2 import QtWidgets +from PySide2.QtWidgets import QWidget + +from sohstationviewer.view.db_config.value_color_helper.\ + edit_value_color_dialog.edit_value_color_dialog_super_class import \ + EditValueColorDialog, display_color + + +class TriColorLinesDialog(EditValueColorDialog): + def __init__(self, parent: QWidget, value_color_str: str): + """ + Dialog to edit color for Up/Down Plot + + :param parent: the parent widget + :param value_color_str: string for value color to be saved in DB + """ + # Widget that allow user to add/edit value positive one's color + self.select_pos_one_color_btn = QtWidgets.QPushButton("Select Color") + # Widget to display positive one's color + self.pos_one_color_label = QtWidgets.QLabel() + self.pos_one_color_label.setFixedWidth(30) + self.pos_one_color_label.setAutoFillBackground(True) + + # Widget that allow user to add/edit value zero's color + self.select_zero_color_btn = QtWidgets.QPushButton("Select Color") + # Widget to display down's color + self.zero_color_label = QtWidgets.QLabel() + self.zero_color_label.setFixedWidth(30) + self.zero_color_label.setAutoFillBackground(True) + + # Widget that allow user to add/edit value positive one's color + self.select_neg_one_color_btn = QtWidgets.QPushButton("Select Color") + # Widget to display positive one's color + self.neg_one_color_label = QtWidgets.QLabel() + self.neg_one_color_label.setFixedWidth(30) + self.neg_one_color_label.setAutoFillBackground(True) + + super(TriColorLinesDialog, self).__init__(parent, value_color_str) + self.setWindowTitle("Edit TriColor Plotting's Colors") + + def setup_ui(self) -> None: + self.main_layout.addWidget(QtWidgets.QLabel('" 1" Color'), 0, 0, 1, 1) + self.main_layout.addWidget(self.pos_one_color_label, 0, 1, 1, 1) + self.main_layout.addWidget(self.select_pos_one_color_btn, 0, 2, 1, 1) + + self.main_layout.addWidget(QtWidgets.QLabel('" 0" Color'), 1, 0, 1, 1) + self.main_layout.addWidget(self.zero_color_label, 1, 1, 1, 1) + self.main_layout.addWidget(self.select_zero_color_btn, 1, 2, 1, 1) + + self.main_layout.addWidget(QtWidgets.QLabel('"-1" Color'), 2, 0, 1, 1) + self.main_layout.addWidget(self.neg_one_color_label, 2, 1, 1, 1) + self.main_layout.addWidget(self.select_neg_one_color_btn, 2, 2, 1, 1) + + self.setup_complete_buttons(3) + + def connect_signals(self) -> None: + self.select_pos_one_color_btn.clicked.connect( + lambda: self.on_select_color(self.pos_one_color_label)) + self.select_zero_color_btn.clicked.connect( + lambda: self.on_select_color(self.zero_color_label)) + self.select_neg_one_color_btn.clicked.connect( + lambda: self.on_select_color(self.neg_one_color_label)) + super().connect_signals() + + def set_value(self): + """ + Change the corresponding color_labels's color according to the color + from value_color_str. + """ + if self.value_color_str == "": + return + vc_parts = self.value_color_str.split('|') + for vc_str in vc_parts: + val, color = vc_str.split(':') + if val == '1': + display_color(self.pos_one_color_label, color) + if val == '0': + display_color(self.zero_color_label, color) + if val == '-1': + display_color(self.neg_one_color_label, color) + + def on_save_color(self): + """ + Create value_color_str from GUI's info and close the GUI with color + is the hex color got from color_labels' color + """ + pos_one_color = self.pos_one_color_label.palette()\ + .window().color().name() + zero_color = self.zero_color_label.palette().window().color().name() + neg_one_color = self.neg_one_color_label.palette() \ + .window().color().name() + + self.value_color_str = (f"-1:{neg_one_color}|0:{zero_color}" + f"|1:{pos_one_color}") + self.close() + + +if __name__ == '__main__': + os_name, version, *_ = platform.platform().split('-') + if os_name == 'macOS': + os.environ['QT_MAC_WANTS_LAYER'] = '1' + app = QtWidgets.QApplication(sys.argv) + test = TriColorLinesDialog(None, '-1:#FF00FF|0:#FF0000|1:#00FF00') + test.exec_() + print("result:", test.value_color_str) + sys.exit(app.exec_()) diff --git a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/up_down_dialog.py b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/up_down_dialog.py index bc8618e5ef4bf5871abf362e796ab8d51c11b96e..477db73aecafd9e26305989153e5e9b74cc9fb6f 100644 --- a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/up_down_dialog.py +++ b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/up_down_dialog.py @@ -85,4 +85,5 @@ if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) test = UpDownDialog(None, 'Down:#FF0000|Up:#00FF00') test.exec_() + print("result:", test.value_color_str) sys.exit(app.exec_())