Files
ctbjrj/tools/replace_cjzz.py
T

74 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
"""把 xiangmu 窗体里的 CJZZ.Controls 第三方控件替换为标准 WinForms 控件,
让 SharpDevelop 设计器能正常打开编辑。"""
import io
import re
import os
BASE = r"C:\Users\099978\Documents\SharpDevelop Projects\成套报价软件\成套报价软件\xiangmu"
# 控件类型映射
TYPE_MAP = {
"CJZZ.Controls.ResizableComboBox": "System.Windows.Forms.ComboBox",
"CJZZ.Controls.ResizableTextBox": "System.Windows.Forms.TextBox",
"CJZZ.Controls.RoundedButton": "System.Windows.Forms.Button",
"CJZZ.Controls.MultiSelectComboBox": "System.Windows.Forms.ComboBox",
}
# 需要删除的 CJZZ 特有属性行(按前缀匹配)
CJZZ_PROPS = [
"BorderColor", "HoverBorderColor", "FocusBorderColor", "PlaceholderColor",
"PlaceholderText", "Flat", "Radius", "Items.PerLine", "Watermark",
"ShowClearButton", "ArrowColor", "ArrowHoverColor",
]
def fix_file(path):
s = io.open(path, encoding="utf-8-sig").read()
orig = s
n_changed = 0
# 1) 替换类型声明
for old_t, new_t in TYPE_MAP.items():
old_decl = "private " + old_t + " "
new_decl = "private " + new_t + " "
if old_decl in s:
s = s.replace(old_decl, new_decl)
n_changed += s.count(new_decl) - orig.count(new_decl)
old_new = "new " + old_t + "()"
new_new = "new " + new_t + "()"
if old_new in s:
s = s.replace(old_new, new_new)
n_changed += 1
# 2) 删除 CJZZ 特有属性行
lines = s.split("\n")
out = []
removed = 0
for line in lines:
stripped = line.strip()
skip = False
for prop in CJZZ_PROPS:
# 形如 this.xxx.PropName = ...;
m = re.match(r"this\.\w+\.(" + prop + r")\s*=", stripped)
if m:
skip = True
removed += 1
break
if not skip:
out.append(line)
s = "\n".join(out)
if s != orig:
io.open(path, "w", encoding="utf-8-sig", newline="\r\n").write(s)
print("%s: 类型替换=%d, 删除属性行=%d" % (os.path.basename(path), n_changed, removed))
else:
print("%s: 无变化" % os.path.basename(path))
if __name__ == "__main__":
for name in os.listdir(BASE):
if name.endswith(".ui.cs"):
fix_file(os.path.join(BASE, name))
print("\n完成。")