color_keywords.py
a set of variables and functions to process color keywords and their hexadecimal values.
I'm not a fan of color keyword values due to the inherent limitation in number, but since they are supported by the W3C specifications, I need to have a way to identify whether a color keyword value is valid or not and a way to convert them into their hex format.
get_all_keywords()
returns a list of all of the color keywords.
Returns:
Name | Type | Description |
---|---|---|
keywords |
list
|
all of the color keywords (basic and extended). |
Source code in webcode_tk/color_keywords.py
211 212 213 214 215 216 217 218 |
|
get_basic_color_keywords()
returns a dictionary of the basic color keywords and their hex equivalent.
Returns:
Name | Type | Description |
---|---|---|
basic_color_keywords |
dict
|
returns the dictionary of basic color keywords and their hex code equivalent. |
Source code in webcode_tk/color_keywords.py
184 185 186 187 188 189 190 191 192 |
|
get_full_color_keywords()
returns all color keywords (basic and extended) with their hex value.
Returns:
Name | Type | Description |
---|---|---|
color_keywords |
dict
|
a dictionary with the keyword as the key and the hex code as its value. |
Source code in webcode_tk/color_keywords.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
get_hex_by_keyword(word)
returns the hex value of a keyword (if valid).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
word
|
str
|
the keyword you are trying to convert to hex. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if the keyword is not a valid keyword. |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
the 6-digit hex code of that value in the format |
Source code in webcode_tk/color_keywords.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
is_a_keyword(word)
checks the keyword to see if it's a valid color keyword value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
word
|
str
|
the color keyword in question. |
required |
Returns:
Name | Type | Description |
---|---|---|
is_keyword |
bool
|
whether the color value is valid or not. |
Source code in webcode_tk/color_keywords.py
221 222 223 224 225 226 227 228 229 230 231 |
|
Notes:
I have added rebeccapurple
to the list of extended keywords. This is from CSS Level 4 colors, and I highly recommend you read the article on how that particular color was added to the list of extended keywords below (in references).
References:
* CSS3/Color
*