Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Ui.parse_color accepting anything input as valid
-
@omz as far as I can see ui.parse_color tries to accept any input. Meaning it does not fail. Maybe there is a fail flag in values I am not seeing. At first I thought it was defaulting to (0,0,0,1.0) if it had bad input, but that's not the case.
Did you have a strategy in mind how to determine from the result that the passed parameter is invalid? In this case I am thinking more about css names.
I can pass 'rxx' to ui._parse_color and still get a result. Just not the right result. I have the css names in .json formatted file. Just seems over kill to have to load it to see if a Css color name is valid or not. -
It intentionally never fails if the data type is correct (i.e. a number, tuple or string), but the error handling is buggy, as I just noticed, and the result is basically undefined in some cases. I think I'll change this to return
(0, 0, 0, 0)
as a default when there is no color with the given name. It might also make sense to return negative values, as that would never be a valid result, but I don't think I want this to throw exceptions. -
@omz , ok great. I think (0,0,0,0) is good. Can't image that would trip someone up on testing for a valid response and no exception thrown.