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
This commit is part of merge request !70. Comments created here will be created in the context of that merge request.
......@@ -3,6 +3,7 @@ param_dialog.py
GUI to add/dit/remove params
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.db_config.db_config_dialog import UiDBInfoDialog
......@@ -17,6 +18,9 @@ class ParamDialog(UiDBInfoDialog):
"""
: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__(
parent,
['No.', 'Param', 'Plot Type', 'ValueColors', 'Height '],
......@@ -34,10 +38,22 @@ class ParamDialog(UiDBInfoDialog):
"""
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, 2,
choices=[''] + sorted(plot_functions.keys()))
self.add_widget(self.data_list, row_idx, 3)
plot_type = self.add_widget(
self.data_list, row_idx, 2,
choices=[''] + sorted(plot_functions.keys()))
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])
def get_data_list(self):
......@@ -68,17 +84,29 @@ class ParamDialog(UiDBInfoDialog):
raise Exception(f"Row {row_idx}: multiColorDots type requires "
f"some ValueColors value")
if value_colors_string != "":
value_colors = value_colors_string.split("|")
try:
for vc in value_colors:
vc = vc.strip()
if not dbConf[plot_type]['pattern'].match(vc):
msg = (f"Row {row_idx}: The ValueColors got is '{vc}' "
f"which doesn't match the required format.\n\n"
f"{dbConf[plot_type]['instruction']}")
raise Exception(msg)
except KeyError:
pass
if plot_type in self.require_valuecolors_plottypes:
value_colors = value_colors_string.split("|")
try:
for vc in value_colors:
vc = vc.strip()
if not dbConf[plot_type]['pattern'].match(vc):
msg = (f"Row {row_idx}: The ValueColors got is "
f"'{vc}' which doesn't match the required "
f"format.\n\n"
f"{dbConf[plot_type]['instruction']}")
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 [
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