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