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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| """ 从网上下载符合要求的图片和 bin 文件,打开此程序 输入文件名后自动处理打包 """ import os import shutil import PySimpleGUI as sg
HELP = """ 从网上下载符合要求的图片和 bin 文件, 并放在此程序所在的文件夹, 打开此程序,输入一个自定义的名字 此软件自动处理打包 """
XML = """<?xml version='1.0' encoding='utf-8' standalone='yes' ?><watch_skin_info><info>{"O00000oO":"{{NAME}}","O00000oo":0,"O0000O0o":103587,"O0000OOo":0,"O0000Oo":false}</info></watch_skin_info>"""
def write_xml(folder, name): """ generate the XML template and write it to XML file """ with open(f'{folder}/infos.xml', 'w', encoding='utf-8') as f: f.write(XML.replace('{{NAME}}', name)) def name_is_pic(name): """check whether the file is picture checks: 'webp', 'jpg', 'jpeg', 'gif' """ ext = name.split('.')[-1] if ext in {'webp', 'jpg', 'jpeg', 'gif'}: return True return False
def convert_png(folder): """ 把图片后缀改成png """ for file in os.listdir(folder): name_without_ext = file.split('.')[0] if name_is_pic(file): print('[I] 转换图片: %s' % file) os.system(f'magick "{folder}\\{file}" "{folder}\\{name_without_ext}.png"') pngs = [i for i in os.listdir(folder) if i.endswith('.png')] if len(pngs) > 1: for j in pngs[1:]: os.remove(f'{folder}\\{j}') print('[I] 删除: %s' % j) os.remove(f'{folder}\\{file}') print('[I] 删除: %s' % file) else: print('[X] 文件夹 %s 内没有图片文件。' % folder) def aio(skin_name) -> str: """ give me the skin name and i will do all things, return a str describe the status """ skin = 'no' pic = 'no' if not os.path.exists(skin_name): os.mkdir(skin_name) for this_folder_file in os.listdir('./'): if this_folder_file.endswith('.bin'): skin = 'yes' print('[I] 识别表盘:%s' % this_folder_file) bin_file = this_folder_file shutil.move(bin_file, f'{skin_name}/{bin_file}') write_xml(skin_name, skin_name) elif name_is_pic(this_folder_file): pic = 'yes' print('[I] 识别图片:%s' % this_folder_file) shutil.move(this_folder_file, f'{skin_name}\\{this_folder_file}') convert_png(skin_name) return f'完成,检测到皮肤:{skin},检测到图片:{pic}'
def gui(): f = ('微软雅黑', 16) sg.theme('Dark') layout = [ [sg.Text('表盘名称', font=f), sg.InputText(key='-NAME-', font=f, size=(20, 1))], [sg.Text('Ready', key='-STATUS-', size=(30, 1),font=f)], [sg.Button('生成!', font=f), sg.Button('退出', font=f), sg.Button('帮助', font=f)] ]
window = sg.Window('小米手环4表盘生成器', layout)
while True: event, values = window.read() print(event, values) if event == sg.WIN_CLOSED or event == '退出': break elif event == '生成!': text = values['-NAME-'] if not text: window['-STATUS-'].update('Skin name is required!') continue output = aio(text) window['-STATUS-'].update(output) elif event == '帮助': sg.popup('帮助', HELP, font=f)
if __name__ == '__main__': gui()
|