Skip to content

Commit 21379e1

Browse files
committed
add gpt gui version
1 parent 924469d commit 21379e1

File tree

5 files changed

+172
-5
lines changed

5 files changed

+172
-5
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

guiver_front.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
msg = tk.StringVar()
1414

1515

16-
17-
18-
1916
def get_path():
2017
p = askdirectory()
2118
path.set(p)
2219

20+
2321
def click():
2422
print(tx)
2523
fm = FindMethod()
@@ -42,6 +40,6 @@ def show_msg(m):
4240
tk.Label(root, text='Value to Search: ').grid(row=1, column=0)
4341
entry2 = tk.Entry(root, textvariable=value).grid(row=1, column=1)
4442
tk.Button(root, text='Search!', command=click).grid(row=1, column=2)
45-
tx = tk.Text(root).grid(row=2, column=0, columnspan=3)
43+
tx = tk.Text(root).grid(row=2, column=0, columnspan=3) # NoneType Object
4644

4745
root.mainloop()

guiver_gpt.py

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import os
2+
import openpyxl
3+
import xlrd
4+
import sys
5+
import threading
6+
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QLineEdit, QTextBrowser, QVBoxLayout, QFileDialog, QProgressBar
7+
from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot, Qt
8+
9+
class ExcelSearchApp(QWidget):
10+
def __init__(self):
11+
super().__init__()
12+
self.initUI()
13+
self.search_thread = None
14+
15+
def initUI(self):
16+
self.setWindowTitle('Excel Search Tool')
17+
self.setGeometry(100, 100, 600, 400)
18+
19+
self.folder_label = QLabel('Select Folder:')
20+
self.folder_button = QPushButton('Browse')
21+
self.folder_button.clicked.connect(self.browse_folder)
22+
self.folder_line_edit = QLineEdit()
23+
24+
self.search_label = QLabel('Enter Word to Search:')
25+
self.search_line_edit = QLineEdit()
26+
27+
self.search_button = QPushButton('Search')
28+
self.search_button.clicked.connect(self.start_search)
29+
30+
self.result_text_browser = QTextBrowser()
31+
self.progress_bar = QProgressBar()
32+
33+
layout = QVBoxLayout()
34+
layout.addWidget(self.folder_label)
35+
layout.addWidget(self.folder_button)
36+
layout.addWidget(self.folder_line_edit)
37+
layout.addWidget(self.search_label)
38+
layout.addWidget(self.search_line_edit)
39+
layout.addWidget(self.search_button)
40+
layout.addWidget(self.progress_bar)
41+
layout.addWidget(self.result_text_browser)
42+
43+
self.setLayout(layout)
44+
45+
def browse_folder(self):
46+
folder = QFileDialog.getExistingDirectory(self, 'Select Folder')
47+
if folder:
48+
self.folder_line_edit.setText(folder)
49+
50+
def start_search(self):
51+
folder_path = self.folder_line_edit.text()
52+
search_word = self.search_line_edit.text()
53+
54+
# Check if a search is already running, if so, stop it
55+
if self.search_thread and self.search_thread.is_alive():
56+
self.search_thread.stop_search()
57+
58+
# Clear the previous search results and reset the progress bar
59+
self.result_text_browser.clear()
60+
self.progress_bar.setValue(0)
61+
62+
# Create a new search thread
63+
self.search_thread = SearchThread(folder_path, search_word)
64+
self.search_thread.search_complete.connect(self.display_results)
65+
self.search_thread.search_progress.connect(self.update_progress)
66+
self.search_thread.start()
67+
68+
@pyqtSlot(list)
69+
def display_results(self, matching_info):
70+
if matching_info:
71+
result_text = "Matching occurrences:\n"
72+
for match in matching_info:
73+
result_text += f"File: {match['File']}, Sheet: {match['Sheet']}, Cell: {match['Cell']}\n"
74+
self.result_text_browser.setPlainText(result_text)
75+
else:
76+
self.result_text_browser.setPlainText("No matching occurrences found.")
77+
78+
@pyqtSlot(int)
79+
def update_progress(self, value):
80+
self.progress_bar.setValue(value)
81+
82+
class SearchThread(QObject, threading.Thread):
83+
search_complete = pyqtSignal(list)
84+
search_progress = pyqtSignal(int)
85+
86+
def __init__(self, folder_path, search_word):
87+
super().__init__()
88+
self.folder_path = folder_path
89+
self.search_word = search_word
90+
self.is_running = True
91+
92+
def run(self):
93+
matching_info = []
94+
95+
for root, _, files in os.walk(self.folder_path):
96+
if not self.is_running:
97+
break
98+
99+
total_files = len(files)
100+
processed_files = 0
101+
102+
for filename in files:
103+
if not self.is_running:
104+
break
105+
106+
if filename.endswith('.xlsx'):
107+
file_path = os.path.join(root, filename)
108+
workbook = openpyxl.load_workbook(file_path)
109+
for sheet_name in workbook.sheetnames:
110+
if not self.is_running:
111+
break
112+
113+
sheet = workbook[sheet_name]
114+
for row_number, row in enumerate(sheet.iter_rows(values_only=True), start=1):
115+
for column_number, cell_value in enumerate(row, start=1):
116+
if not self.is_running:
117+
break
118+
119+
if self.search_word in str(cell_value):
120+
matching_info.append({
121+
"File": file_path,
122+
"Sheet": sheet.title,
123+
"Cell": f"{openpyxl.utils.get_column_letter(column_number)}{row_number}",
124+
})
125+
126+
elif filename.endswith('.xls'):
127+
file_path = os.path.join(root, filename)
128+
xls_workbook = xlrd.open_workbook(file_path)
129+
for sheet in xls_workbook.sheets():
130+
if not self.is_running:
131+
break
132+
133+
for row_number in range(sheet.nrows):
134+
for column_number in range(sheet.ncols):
135+
if not self.is_running:
136+
break
137+
138+
cell_value = sheet.cell_value(row_number, column_number)
139+
if self.search_word in str(cell_value):
140+
matching_info.append({
141+
"File": file_path,
142+
"Sheet": sheet.name,
143+
"Cell": f"{xlrd.colname(column_number)}{row_number + 1}",
144+
})
145+
146+
processed_files += 1
147+
progress = int((processed_files / total_files) * 100)
148+
self.search_progress.emit(progress)
149+
150+
# Emit the signal with the search results
151+
self.search_complete.emit(matching_info)
152+
153+
def stop_search(self):
154+
self.is_running = False
155+
156+
def main():
157+
app = QApplication(sys.argv)
158+
window = ExcelSearchApp()
159+
window.show()
160+
sys.exit(app.exec_())
161+
162+
if __name__ == "__main__":
163+
main()

main_dirloop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
print(
99
" ______ _________ __ \n / ____/ __________ / / ____(_)___ ____/ /__ _____\n / __/ | |/_/ ___/ _ \/ / /_ / / __ \/ __ / _ \/ ___/\n / /____> </ /__/ __/ / __/ / / / / / /_/ / __/ / \n/_____/_/|_|\___/\___/_/_/ /_/_/ /_/\__,_/\___/_/ \n ")
10-
print("**V2.1 dirloop ver - Written by Shimin Gao**")
10+
print("**V2.1 dirloop ver -- 作者:高世岷**")
1111

1212

1313
def run():

0 commit comments

Comments
 (0)