|
|
@@ -2,7 +2,7 @@
|
|
|
import re
|
|
|
import sys
|
|
|
|
|
|
-from PySide6.QtWidgets import QMainWindow, QApplication, QMessageBox
|
|
|
+from PySide6.QtWidgets import QMainWindow, QApplication, QMessageBox, QFileDialog
|
|
|
|
|
|
from src.DataFilter import Ui_Form
|
|
|
|
|
|
@@ -18,11 +18,13 @@ class MyMainForm(QMainWindow, Ui_Form):
|
|
|
self.filterCategoryBtn.clicked.connect(self.insertCategoryRegex)
|
|
|
self.filterDigitBtn.clicked.connect(self.insertDigitRegex)
|
|
|
self.filterEnglishBtn.clicked.connect(self.insertEnglishRegex)
|
|
|
+ self.fileBtn.clicked.connect(self.selectFile)
|
|
|
|
|
|
def submit(self):
|
|
|
inputText = self.inputBox.text()
|
|
|
if len(inputText) == 0:
|
|
|
QMessageBox.warning(self, "输入提示", "请输入待筛选关键词")
|
|
|
+ return
|
|
|
|
|
|
cnt = 0
|
|
|
if category_pattern.search(inputText) is not None:
|
|
|
@@ -33,17 +35,24 @@ class MyMainForm(QMainWindow, Ui_Form):
|
|
|
cnt = cnt + 1
|
|
|
if cnt > 1:
|
|
|
QMessageBox.warning(self, "提示", "一次只能使用一种正则筛选项")
|
|
|
-
|
|
|
- originText = self.originBox.toPlainText()
|
|
|
- if len(originText) == 0:
|
|
|
- QMessageBox.warning(self, "提示", "请输入待筛选关键词")
|
|
|
+ return
|
|
|
|
|
|
categoryText = self.filterCategoryBox.toPlainText()
|
|
|
if category_pattern.search(inputText) is not None and len(categoryText) == 0:
|
|
|
QMessageBox.warning(self, "提示", "使用类别筛选,请输入待筛选的类别关键词")
|
|
|
+ return
|
|
|
+
|
|
|
+
|
|
|
+ file_path = self.filePathBox.text()
|
|
|
+ if len(file_path) == 0:
|
|
|
+ QMessageBox.warning(self, "提示", "请选择带筛选文件")
|
|
|
+ return
|
|
|
+
|
|
|
+ originKeyArray = None
|
|
|
+ with open(file_path, 'r', encoding='utf-8') as f:
|
|
|
+ originKeyArray = f.readlines()
|
|
|
|
|
|
resultKeyArray = []
|
|
|
- originKeyArray = originText.splitlines()
|
|
|
if category_pattern.search(inputText) is not None:
|
|
|
categoryKeyArray = categoryText.splitlines()
|
|
|
for categoryKey in categoryKeyArray:
|
|
|
@@ -60,7 +69,7 @@ class MyMainForm(QMainWindow, Ui_Form):
|
|
|
def filter(self, originArray, inputText, oldStr=None, newStr=None):
|
|
|
resultArray = []
|
|
|
pattern_str = inputText
|
|
|
- if len(oldStr) > 0 and len(newStr) > 0:
|
|
|
+ if oldStr is not None and newStr is not None and len(oldStr) > 0 and len(newStr) > 0:
|
|
|
pattern_str = inputText.replace(oldStr, newStr)
|
|
|
pattern = re.compile(pattern_str)
|
|
|
for originKey in originArray:
|
|
|
@@ -81,6 +90,9 @@ class MyMainForm(QMainWindow, Ui_Form):
|
|
|
text = self.inputBox.text()
|
|
|
self.inputBox.setText(text + regexText)
|
|
|
|
|
|
+ def selectFile(self):
|
|
|
+ file_path = QFileDialog.getOpenFileName(self, "选择文件")
|
|
|
+ self.filePathBox.setText(file_path[0])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
app = QApplication(sys.argv)
|