-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.py
More file actions
48 lines (39 loc) · 1.43 KB
/
Copy pathutility.py
File metadata and controls
48 lines (39 loc) · 1.43 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from PySide6.QtWidgets import QMessageBox
font_list_built_in = [
("Arial", "sans-serif"),
("Verdana", "sans-serif"),
("Helvetica", "sans-serif"),
("Tahoma", "sans-serif"),
("Trebuchet MS", "sans-serif"),
("Times New Roman", "serif"),
("Georgia", "serif"),
("Garamond", "serif"),
("Courier New", "monospace"),
("Brush Script MT", "cursive"),
]
def rgb_to_hex(r, g, b):
"""
Takes values from range 0-255 and returns a hex string in format "RRGGBB"
"""
return '#%02x%02x%02x' % (r, g, b)
def hex_to_rgb(hex_string):
"""
String has to be formatted this way: "RRGGBB" or "RGB" (shorthand version)
Returns a tuple of integers like (R, G, B), where each value is in range 0-255
"""
if len(hex_string) == 6: # Classic hex string
r = int("0x" + hex_string[:2], 0)
g = int("0x" + hex_string[2:4], 0)
b = int("0x" + hex_string[4:], 0)
elif len(hex_string) == 3: # Shorthand hex string
r = int("0x" + hex_string[0] + hex_string[0], 0)
g = int("0x" + hex_string[1] + hex_string[1], 0)
b = int("0x" + hex_string[2] + hex_string[2], 0)
else: # Not a valid hex string
return None
return r, g, b
def file_open_error():
error = QMessageBox()
error.setText("ERROR - could not open file. Not a valid EPUB.")
error.setWindowTitle("Error")
error.exec()