waterfall config fine-adjustments

* hide the waterfall colors input when pre-defined color scheme is
  selected
* skip unparseable lines on custom color input
* fallback to black and white if custom color config is unusable
* always use the waterfall classes when sending changes to the client
This commit is contained in:
Jakob Ketterl
2021-02-16 18:35:18 +01:00
parent 9aebeb51f8
commit 691d88f841
6 changed files with 30 additions and 8 deletions

View File

@ -76,10 +76,14 @@ class WaterfallColorsConverter(Converter):
def convert_from_form(self, value):
def parseString(s):
if s.startswith("#"):
return int(s[1:], 16)
# int() with base 0 can accept "0x" prefixed hex strings, or int numbers
return int(s, 0)
try:
if s.startswith("#"):
return int(s[1:], 16)
# int() with base 0 can accept "0x" prefixed hex strings, or int numbers
return int(s, 0)
except ValueError:
return None
# \r\n or \n? this should work with both.
return [parseString(v.strip("\r ")) for v in value.split("\n")]
values = [parseString(v.strip("\r ")) for v in value.split("\n")]
return [v for v in values if v is not None]