Skip to content
Snippets Groups Projects

Connect EditSingleParamDialog with ValueColorEdit

Merged Lan Dam requested to merge i194_connect_edit_single_param_dialog_with_edit_value_color into develop
2 files
+ 222
0
Compare changes
  • Side-by-side
  • Inline
Files
2
from typing import Tuple
import re
from sohstationviewer.view.util.plot_type_info import plot_types
def validate_value_color_str(value_color_string: str,
plot_type: str,
row_id: int = 0) -> Tuple[bool, str]:
plot_type_info = plot_types.get(plot_type)
value_colors = value_color_string.split("|")
if 'total_value_color_required' in plot_type_info:
if len(value_colors) != plot_type_info['total_value_color_required']:
msg = (f"Row {row_id}: Total ValueColors in this row is "
f"{len(value_colors)} while it requires "
f"{plot_type_info['total_value_color_required']} for "
f"plot type {plot_type}.")
return False, msg
values = []
numbers = []
for vc in value_colors:
vc = vc.strip()
if plot_type_info is None:
continue
if not plot_type_info['pattern'].match(vc):
msg = (f"Row {row_id}: A ValueColor in this row is "
f"'{vc}', which doesn't match the required "
f"format of\n\n"
f"{plot_type_info['description']}")
return False, msg
val = vc.split(":")[0]
if val in values:
msg = f"Row {row_id}: Duplicated value '{val}' isn't allowed."
return False, msg
number = re.sub('<|=', '', val)
if numbers and number < max(numbers):
msg = (f"Row {row_id}: Number '{number}' is out of increasing "
f"order.")
return False, msg
values.append(val)
numbers.append(number)
return True, ''
Loading