近日,使用 designer 编辑文件时遇到了一个问题,更换了控件,属性,以及资源都要重新
转换一下文件,闲来没事写了小工具
直接上代码,文件名: watch_file.py
使用到的库 click, 需要提前设置好环境变量,即将designer所在的目录添加到path
#!/usr/bin/env python
# -*-coding: utf-8 -*-
# @Author: Candy
# @DateTime: 2022/9/28 23:50
# @FileName: watch_file.py
# 监控文件的变化进行对应的转换操作
import os
import time
import click
def _delete_last_line(file):
# 删除最后一行, (uic转换时文件末尾自动导入 import xxx_rc, 现在自动生成qrc已经加上了_rc)
with open(file, 'r+', encoding='utf-8') as f:
lines = f.readlines()[0:-1]
f.seek(0, 0)
f.truncate()
if f.write(''.join(lines)):
print(f'[{
time.ctime()}] delete last line')
@click.command()
@click.argument('input-file', type=click.Path(exists=True), required=True, nargs=1)
@click.option('--output-file',