Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
UncertainProd
GitHub Repository: UncertainProd/FnF-Spritesheet-and-XML-Maker
Path: blob/master/src/utils.py
254 views
1
from PyQt5.QtWidgets import QMessageBox
2
3
SPRITEFRAME_SIZE = 128
4
imghashes = {} # dict[Int(hash) -> PIL.Image object]
5
spritesheet_split_cache = {} # dict[str(spritesheet_path) -> dict[ (x,y,w,h, clipped)-> int(hash) ] ]
6
g_settings = {
7
"isclip": 1,
8
"prefix_type": "charname",
9
"custom_prefix": "",
10
"must_use_prefix": 0
11
} # dict containing all settings (check settingswindow.py)
12
13
def get_stylesheet_from_file(filename):
14
with open(filename, 'r') as f:
15
style = f.read()
16
return style
17
18
def temp_path_shortener(pathstr):
19
if '/' in pathstr:
20
return "/".join(pathstr.split('/')[-2:])
21
else:
22
return pathstr
23
24
def display_msg_box(parent, window_title="MessageBox", text="Text Here", icon=None):
25
msgbox = QMessageBox(parent)
26
msgbox.setWindowTitle(window_title)
27
msgbox.setText(text)
28
if not icon:
29
msgbox.setIcon(QMessageBox.Information)
30
else:
31
msgbox.setIcon(icon)
32
x = msgbox.exec_()
33
print("[DEBUG] Exit status of msgbox: "+str(x))
34
35
def parse_value(val, exceptions=None, fallback=0, dtype=int):
36
if exceptions is None:
37
exceptions = dict()
38
39
if val in exceptions.keys():
40
return exceptions.get(val)
41
else:
42
try:
43
return dtype(val)
44
except Exception as e:
45
print("Could not convert into required type")
46
print(e)
47
return fallback
48
49
def clean_filename(filename):
50
replacers = {
51
'\\': '_backslash_',
52
'/': '_fwdslash_',
53
':': '_colon_',
54
'*': '_asterisk_',
55
'?': '_questionmark_',
56
'"': '_quot_',
57
'<': '_lt_',
58
'>': '_gt_',
59
'|': '_pipe_'
60
}
61
for ch, replch in replacers.items():
62
filename = filename.replace(ch, replch)
63
return filename
64
65
if __name__ == '__main__':
66
print("To run the actual application, Please type: \npython xmlpngUI.py\nor \npython3 xmlpngUI.py \ndepending on what works")
67