|
@@ -17,12 +17,38 @@ def setText(aString):
|
|
|
w.SetClipboardText(aString)
|
|
|
w.CloseClipboard()
|
|
|
|
|
|
+def list_to_clipboard(list):
|
|
|
+ text = " ".join(list)
|
|
|
+ print(text)
|
|
|
+ setText(text)
|
|
|
+
|
|
|
+# 单位in或cm 换算mm
|
|
|
+def convert_mm(text, unit):
|
|
|
+ list = re.findall(r"[1-9][\d\.]*\d*", text)
|
|
|
+ if (unit == 'in') :
|
|
|
+ print("单位英寸")
|
|
|
+ for i, ch in enumerate(list):
|
|
|
+ list[i] = str((int(float(ch) * 25.4 + 0.5)))
|
|
|
+ elif(unit == 'cm') :
|
|
|
+ print("单位厘米")
|
|
|
+ for i, ch in enumerate(list):
|
|
|
+ list[i] = str((int(float(ch) * 10 + 0.5)))
|
|
|
+ list_to_clipboard(list)
|
|
|
+
|
|
|
# 获取剪贴板文本
|
|
|
text = getText()
|
|
|
# print(text)
|
|
|
|
|
|
# 正则搜索数字,写回剪贴板
|
|
|
list = re.findall(r"[1-9][\d\.]*\d*[cmin\"]*", text)
|
|
|
-text = " ".join(list)
|
|
|
-print(text)
|
|
|
-setText(text)
|
|
|
+list_to_clipboard(list)
|
|
|
+
|
|
|
+# 判断厘米和英寸换算mm
|
|
|
+match = re.search(r"cm|in|\"", text)
|
|
|
+if match:
|
|
|
+ # print(match.group())
|
|
|
+ unit = match.group()
|
|
|
+ if (unit == 'in') or (unit == '\"') :
|
|
|
+ convert_mm(text, 'in')
|
|
|
+ elif(unit == 'cm') :
|
|
|
+ convert_mm(text, 'cm')
|