1 Star 16 Fork 16

阿德/代码编辑器

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Ui_FineText.py 4.98 KB
一键复制 编辑 原始数据 按行查看 历史
阿德 提交于 2020-06-05 14:58 +08:00 . Signed-off-by: huangweide001 85042684@qq.com
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'F:\prog-tmp\PyQt5-code\MDI_code_compV0.33\FineText.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import os
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(476, 157)
Dialog.setSizeGripEnabled(True)
self.groupBox = QtWidgets.QGroupBox(Dialog)
self.groupBox.setGeometry(QtCore.QRect(20, 70, 181, 71))
self.groupBox.setObjectName("groupBox")
self.rdb_currentFile = QtWidgets.QRadioButton(self.groupBox)
self.rdb_currentFile.setGeometry(QtCore.QRect(20, 20, 111, 16))
self.rdb_currentFile.setObjectName("rdb_currentFile")
self.rdb_cbpDir = QtWidgets.QRadioButton(self.groupBox)
self.rdb_cbpDir.setGeometry(QtCore.QRect(20, 50, 101, 16))
self.rdb_cbpDir.setObjectName("rdb_cbpDir")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(10, 30, 61, 16))
self.label.setObjectName("label")
self.lineEdit_destText = QtWidgets.QLineEdit(Dialog)
self.lineEdit_destText.setGeometry(QtCore.QRect(70, 30, 321, 20))
self.lineEdit_destText.setObjectName("lineEdit_destText")
self.ButtonFind = QtWidgets.QPushButton(Dialog)
self.ButtonFind.setGeometry(QtCore.QRect(400, 26, 61, 31))
self.ButtonFind.setObjectName("ButtonFind")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "查找"))
self.groupBox.setTitle(_translate("Dialog", "查找范围:"))
self.rdb_currentFile.setText(_translate("Dialog", "当前文件"))
self.rdb_cbpDir.setText(_translate("Dialog", "当前工程目录"))
self.label.setText(_translate("Dialog", "查找内容:"))
self.ButtonFind.setText(_translate("Dialog", "查找"))
class FindText(QDialog, Ui_Dialog):
def __init__(self, parent=None):
super(FindText, self).__init__(parent)
self.setupUi(self)
#1.主窗口作为父窗口
self.parent = parent
#2. 点击查找按钮的信号的槽函数
self.ButtonFind.clicked.connect(self.FineTextInFiles)
self.rdb_cbpDir.setChecked(True)
def FineTextInFiles(self):
self.parent.text_browser.clear()
if os.path.isdir(self.parent.ProjectDir) == False:
self.parent.text_browser.append("工程目录出错。")
return
text_file_list = []
#1. 仅仅查找当前的文件
if self.rdb_currentFile.isChecked():
text_file_list.append(self.parent.mdi.activeSubWindow().widget().filename)
#2. 扫描整个工程目录的c、h文件,并存放到 text_file_list
else:
walk_tree = os.walk(self.parent.ProjectDir)
#"walk" through the directory tree and save the readable files to a list
for root, subFolders, files in walk_tree:
for file in files:
full_with_path = os.path.join(root, file)
if os.path.exists(full_with_path) != None:
endChar = full_with_path[-1]
if 'h' == endChar or 'H' == endChar or 'c' == endChar or 'C' == endChar:
full_with_path = full_with_path.replace("\\", "/")
text_file_list.append(full_with_path)
#2.1 包含的系统文件也要
for file in self.parent.file_list:
if file not in text_file_list:
text_file_list.append(file)
#3. 开始查找
destCount=0
for file in text_file_list:
fin = open(file, "r", encoding='utf-8', errors="ignore")
input_file = fin.read()#.encode("gbk").decode("utf-8")
input_str = input_file.splitlines(False)
for i in range(len(input_str) ) :
if self.lineEdit_destText.text() in input_str[i]:
destCount += 1
self.parent.text_browser.append("%s:%d:%s"%(file, i+1, input_str[i]))
#4. 在信息输出窗口中显示结果
self.parent.text_browser.append("在 %d 个文件中找到 %d 处。"%(len(text_file_list), destCount))
#5. 发送一个 QCloseEvent,窗口自杀
e = QCloseEvent()
QApplication.postEvent(self, e)
'''
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
'''
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/huangweide001/code4STC51.git
git@gitee.com:huangweide001/code4STC51.git
huangweide001
code4STC51
代码编辑器
master

搜索帮助