forked from preshtildeath/print-proxy-prep
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.py
86 lines (59 loc) · 2.14 KB
/
util.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import sys
import subprocess
import constants
def list_files(folder, extensions=None):
files = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f))]
if extensions is not None and isinstance(extensions, list):
files = [f for f in files if os.path.splitext(f)[1] in extensions]
return files
def list_folders(folder):
return [f for f in os.listdir(folder) if os.path.isdir(os.path.join(folder, f))]
def mm_to_inch(mm):
return mm * 0.0393701
def mm_to_point(mm):
return inch_to_point(mm_to_inch(mm))
def inch_to_mm(inch):
return inch / 0.0393701
def inch_to_point(inch):
return inch * 72
def point_to_inch(point):
return point / 72
def is_number_string(str):
return str.replace(".", "", 1).isdigit()
def cap_bleed_edge_str(bleed_edge):
if is_number_string(bleed_edge):
bleed_edge_num = float(bleed_edge)
max_bleed_edge = inch_to_mm(0.12)
if bleed_edge_num > max_bleed_edge:
bleed_edge_num = min(bleed_edge_num, max_bleed_edge)
bleed_edge = "{:.2f}".format(bleed_edge_num)
return bleed_edge
def cap_offset_str(offset):
if is_number_string(offset):
offset_num = float(offset)
max_offset = 10.0
if offset_num > max_offset:
offset_num = min(offset_num, max_offset)
offset = "{:.2f}".format(offset_num)
return offset
def open_folder(path):
if os.path.isdir(path):
path = path if isinstance(path, str) else f"{path}"
if sys.platform == "darwin":
subprocess.call(["open", "--", path])
elif sys.platform.startswith("linux"):
subprocess.call(["xdg-open", "--", path])
elif sys.platform == "win32":
subprocess.call(["explorer", path])
def open_file(path):
subprocess.Popen([path], shell=True)
def resource_path():
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
return sys._MEIPASS
except Exception:
return constants.cwd
def is_debugger_attached():
gettrace = getattr(sys, "gettrace", None)
return gettrace is not None and gettrace() is not None