blob: a339b7f61806759196c28b9346361ba906ac708e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
from param import Param
import re
class Color(Param):
def __init__(self, value, classname=""):
super(Color, self).__init__(classname=classname)
try:
self.value = self._color_sanitize(value)
except Exception as e:
self.err_warn("Unable to sanitize the color: %s" % str(value))
self.err_warn(str(e))
def _color_sanitize(self, s):
if s == "":
return "transparent"
if re.match('(rgba?\([0-9]+,[0-9]+,[0-9]+\))|([a-zA-Z]+)|(\#[A-Ha-h0-9]+)', s):
return s.replace(' ', '');
else:
self.err_warn("Not a color: {}\n".format(s))
|