-
Notifications
You must be signed in to change notification settings - Fork 0
/
hex_color.py
28 lines (22 loc) · 1.05 KB
/
hex_color.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import logger as l
def check(hex_list: dict): #*adapted* from https://www.geeksforgeeks.org/check-if-a-given-string-is-a-valid-hexadecimal-color-code-or-not/
"""
Checks if a hex code is valid. If a code isn't valid, the key of the hex number will be returned
`hex_list` is a dictionary of hex colours, suggested use:
'hover_color' = ...
'frame_color' = ...
'root_color' = ...
'button_color' = ...
"""
l.log(type="DEBUG",message="Checking HEX Code")
for hex in hex_list:
print(hex_list[hex])
if hex_list[hex][0] != "#":
return hex
if hex_list[hex][0] != "#":
return hex
if (not(len(hex_list[hex]) == 4 or len(hex_list[hex]) == 7)):
return hex
for i in range(1, len(hex_list[hex])):
if (not((hex_list[hex][i] >= '0' and hex_list[hex][i] <= '9') or (hex_list[hex][i] >= 'a' and hex_list[hex][i] <= 'f') or (hex_list[hex][i] >= 'A' or hex[i] <= 'F'))): # Dont know what it does.
return hex