From 2649643b65c541d2957f101da66669db8627e688 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sat, 6 May 2023 19:09:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=89=AA=E8=B4=B4=E6=9D=BF?= =?UTF-8?q?=E5=8D=95=E9=80=89=E5=8F=98=E5=A4=9A=E9=80=89=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=B9=B6=E6=95=B4=E5=90=88=E5=85=A5=E5=B7=A5=E5=85=B7=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=20=E5=8F=96=E6=B6=88=E5=B7=A5=E5=85=B7=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E8=87=AA=E5=8A=A8=E7=BD=AE=E9=A1=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具/工具面板.py | 5 +++- 文本处理工具/单选变为多选.py | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 文本处理工具/单选变为多选.py diff --git a/工具/工具面板.py b/工具/工具面板.py index 2fe1a11a..f04695bf 100644 --- a/工具/工具面板.py +++ b/工具/工具面板.py @@ -108,6 +108,8 @@ def run_command1(): call(["python","统考数据导入.py"]) elif selectedtool == "合并使用记录并排序": call(["python","合并使用记录并排序.py"]) + elif selectedtool == "剪贴板单选变多选": + call(["python","../文本处理工具/单选变为多选.py"]) LabelTool.config(text = selectedtool+"STEP1命令执行完毕") button1.place_forget() @@ -211,6 +213,7 @@ menubar.add_cascade(label = "其他", menu = OtherMenu) OtherMenu.add_command(label = "剪贴板mathpix预处理", command = lambda: SetButton("mathpix预处理",1,[])) OtherMenu.add_command(label = "剪贴板带圈数字处理", command = lambda: SetButton("带圈数字处理",1,[])) OtherMenu.add_command(label = "剪贴板表格整理", command = lambda: SetButton("剪贴板表格整理",1,[])) +OtherMenu.add_command(label = "剪贴板单选变多选", command = lambda: SetButton("剪贴板单选变多选",1,[])) menubar.add_command(label = "退出", command = root.destroy) @@ -218,7 +221,7 @@ menubar.add_command(label = "退出", command = root.destroy) root.config(menu = menubar) -root.attributes("-topmost",1) +# root.attributes("-topmost",1) root.iconbitmap("logo.ico") root.mainloop() \ No newline at end of file diff --git a/文本处理工具/单选变为多选.py b/文本处理工具/单选变为多选.py new file mode 100644 index 00000000..1693a5df --- /dev/null +++ b/文本处理工具/单选变为多选.py @@ -0,0 +1,52 @@ +import os,re +import win32clipboard as wc +import win32con + +# 获取剪切板内容 +def getCopy(): + wc.OpenClipboard() + t = wc.GetClipboardData(win32con.CF_UNICODETEXT) + wc.CloseClipboard() + return t + +# 写入剪切板内容 +def setCopy(str): + wc.OpenClipboard() + wc.EmptyClipboard() + wc.SetClipboardData(win32con.CF_UNICODETEXT, str) + wc.CloseClipboard() + +def choicetoblankfilling(data): + choiceslist = re.findall(r"(\\(?:two|four|one)ch[\s\S]*?)(?:\n[\s]*\\item|$)",data) + for rawchoice in choiceslist: + leftcount = 0 + rightcount = 0 + choicestring = rawchoice + contentlist = [""] + while len(choicestring) > 0: + char = choicestring[0] + if char == "{": + leftcount += 1 + if char == "}": + rightcount += 1 + if leftcount > rightcount: + contentlist[-1]+=char + if leftcount == rightcount and contentlist[-1] != "": + contentlist[-1] += "}" + contentlist.append("") + choicestring = choicestring[1:] + contentlist = [c[1:-1] for c in contentlist if c.strip()!=""] + repstring = "" + for t in range(len(contentlist)): + repstring += r"\textcircled{"+str(t+1)+"} "+contentlist[t]+"; " + repstring= repstring[:-2]+"." + data = data.replace(rawchoice,repstring) + data = re.sub(r"bracket\{\d*?\}\.*",r"blank{50}.\\\\",data) + return data + +data = getCopy() +modified_data = choicetoblankfilling(data) +setCopy(modified_data) + +with open("临时文件/outputfile.txt","w",encoding = "utf8") as f: + f.write(modified_data) \ No newline at end of file