Skip to content
Snippets Groups Projects
Commit 1ed6be24 authored by Lan Dam's avatar Lan Dam
Browse files

param_dialog.py: handle warning message when plot_type is empty or ValueColors...

param_dialog.py: handle warning message when plot_type is empty or ValueColors isn't available; different ValueColors' placeholder text if plot_type requires ValueColors
parent ddae0df7
No related branches found
No related tags found
1 merge request!70DB config dialogs
...@@ -3,6 +3,7 @@ param_dialog.py ...@@ -3,6 +3,7 @@ param_dialog.py
GUI to add/dit/remove params GUI to add/dit/remove params
NOTE: Cannot remove or change params that are already used for channels. NOTE: Cannot remove or change params that are already used for channels.
""" """
from PySide2 import QtWidgets
from sohstationviewer.view.util.plot_func_names import plot_functions from sohstationviewer.view.util.plot_func_names import plot_functions
from sohstationviewer.view.db_config.db_config_dialog import UiDBInfoDialog from sohstationviewer.view.db_config.db_config_dialog import UiDBInfoDialog
...@@ -17,6 +18,9 @@ class ParamDialog(UiDBInfoDialog): ...@@ -17,6 +18,9 @@ class ParamDialog(UiDBInfoDialog):
""" """
:param parent: QMainWindow/QWidget - the parent widget :param parent: QMainWindow/QWidget - the parent widget
""" """
self.require_valuecolors_plottypes = [
p for p in plot_functions.keys()
if 'ValueColors' in plot_functions[p][0]]
super().__init__( super().__init__(
parent, parent,
['No.', 'Param', 'Plot Type', 'ValueColors', 'Height '], ['No.', 'Param', 'Plot Type', 'ValueColors', 'Height '],
...@@ -34,10 +38,22 @@ class ParamDialog(UiDBInfoDialog): ...@@ -34,10 +38,22 @@ class ParamDialog(UiDBInfoDialog):
""" """
self.add_widget(None, row_idx, 0) # No. self.add_widget(None, row_idx, 0) # No.
self.add_widget(self.data_list, row_idx, 1, foreign_key=fk) self.add_widget(self.data_list, row_idx, 1, foreign_key=fk)
self.add_widget(self.data_list, row_idx, 2, plot_type = self.add_widget(
choices=[''] + sorted(plot_functions.keys())) self.data_list, row_idx, 2,
choices=[''] + sorted(plot_functions.keys()))
self.add_widget(self.data_list, row_idx, 3) place_holder_text = ""
if plot_type in self.require_valuecolors_plottypes:
place_holder_text = "Enter ValueColors..."
if plot_type == 'linesDots':
place_holder_text = "Ex: L:G|D:W"
elif plot_type == 'multiColorDots':
place_holder_text = "Ex: -1:_|0:R|2.3:Y|+2.3:G"
elif plot_type == "upDownDots":
place_holder_text = "Ex: 1:R|0:Y"
elif plot_type == "dotForTime":
place_holder_text = "Ex: G"
self.add_widget(self.data_list, row_idx, 3,
place_holder_text=place_holder_text)
self.add_widget(self.data_list, row_idx, 4, range_values=[0, 10]) self.add_widget(self.data_list, row_idx, 4, range_values=[0, 10])
def get_data_list(self): def get_data_list(self):
...@@ -68,17 +84,29 @@ class ParamDialog(UiDBInfoDialog): ...@@ -68,17 +84,29 @@ class ParamDialog(UiDBInfoDialog):
raise Exception(f"Row {row_idx}: multiColorDots type requires " raise Exception(f"Row {row_idx}: multiColorDots type requires "
f"some ValueColors value") f"some ValueColors value")
if value_colors_string != "": if value_colors_string != "":
value_colors = value_colors_string.split("|") if plot_type in self.require_valuecolors_plottypes:
try: value_colors = value_colors_string.split("|")
for vc in value_colors: try:
vc = vc.strip() for vc in value_colors:
if not dbConf[plot_type]['pattern'].match(vc): vc = vc.strip()
msg = (f"Row {row_idx}: The ValueColors got is '{vc}' " if not dbConf[plot_type]['pattern'].match(vc):
f"which doesn't match the required format.\n\n" msg = (f"Row {row_idx}: The ValueColors got is "
f"{dbConf[plot_type]['instruction']}") f"'{vc}' which doesn't match the required "
raise Exception(msg) f"format.\n\n"
except KeyError: f"{dbConf[plot_type]['instruction']}")
pass raise Exception(msg)
except KeyError:
pass
else:
if plot_type == "":
msg = (f"Row {row_idx}: No ValueColors should be entered "
f"when no Plot Type selected.")
else:
msg = (f"Row {row_idx}: No ValueColors is required for "
f"Plot Type {plot_type}.")
QtWidgets.QMessageBox.information(
self, "Clear ValueColors", msg)
self.data_table_widget.cellWidget(row_idx, 3).clear()
return [ return [
self.data_table_widget.cellWidget(row_idx, 1).text().strip(), self.data_table_widget.cellWidget(row_idx, 1).text().strip(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment