-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileScope.py
More file actions
329 lines (284 loc) · 11.4 KB
/
FileScope.py
File metadata and controls
329 lines (284 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
"""
FileScope - Professional Finder Tool with Glowing Animated Hybrid Progress Bar
"""
import os
import sys
import subprocess
import platform
from PySide6.QtWidgets import (
QApplication, QWidget, QFileDialog, QVBoxLayout, QHBoxLayout,
QPushButton, QLabel, QLineEdit, QListWidget, QComboBox, QProgressBar,
QMessageBox
)
from PySide6.QtCore import Qt, QThread, Signal, QTimer
from PySide6.QtGui import QIcon
def resource_path(file_name):
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, file_name)
# ---------------------- WORKER THREAD ----------------------
class SearchWorker(QThread):
found = Signal(str)
progress = Signal(int)
finished = Signal()
def __init__(self, root_path, search_type, query):
super().__init__()
self.root_path = root_path
self.search_type = search_type
self.query = query.lower()
self._running = True
def stop(self):
self._running = False
def run(self):
total_folders = sum(len(dirs) for _, dirs, _ in os.walk(self.root_path))
total_folders = max(total_folders, 1)
processed_folders = 0
for root, dirs, files in os.walk(self.root_path):
if not self._running:
break
# Folder search
if self.search_type == "Folder Name":
for d in dirs:
if not self._running:
break
path = os.path.join(root, d)
if self.query in d.lower():
self.found.emit(path)
# File search
for f in files:
if not self._running:
break
path = os.path.join(root, f)
try:
if self.search_type == "File Name":
if self.query in f.lower():
self.found.emit(path)
elif self.search_type == "Word in File":
with open(path, "r", encoding="utf-8", errors="ignore") as file:
if self.query in file.read().lower():
self.found.emit(path)
except Exception:
pass
processed_folders += 1
percent = int((processed_folders / total_folders) * 100)
self.progress.emit(percent)
self.finished.emit()
# ---------------------- UI ----------------------
class FinderApp(QWidget):
def __init__(self):
super().__init__()
self.setWindowIcon(QIcon(resource_path("logo.ico")))
self.setWindowTitle("FileScope - Professional Finder Tool")
self.setMinimumSize(950, 550)
self.root_path = ""
self.worker = None
self.match_count = 0
self.smooth_value = 0
self.target_progress = 0
self.glow_pos = 0
self.build_ui()
def build_ui(self):
main_layout = QVBoxLayout()
# Title
title = QLabel("📁 FileScope")
title.setAlignment(Qt.AlignCenter)
title.setObjectName("Title")
# Controls
controls = QHBoxLayout()
self.path_input = QLineEdit()
self.path_input.setPlaceholderText("Select root folder...")
self.path_input.setReadOnly(True)
browse_btn = QPushButton("Browse")
browse_btn.clicked.connect(self.browse_folder)
self.search_type = QComboBox()
self.search_type.addItems(["Folder Name", "File Name", "Word in File"])
self.query_input = QLineEdit()
self.query_input.setPlaceholderText("Enter search text")
self.query_input.returnPressed.connect(self.start_search)
self.search_btn = QPushButton("Search")
self.search_btn.clicked.connect(self.start_search)
self.cancel_btn = QPushButton("Cancel")
self.cancel_btn.clicked.connect(self.cancel_search)
self.cancel_btn.setEnabled(False)
about_btn = QPushButton("About")
about_btn.clicked.connect(self.show_about)
controls.addWidget(self.path_input)
controls.addWidget(browse_btn)
controls.addWidget(self.search_type)
controls.addWidget(self.query_input)
controls.addWidget(self.search_btn)
controls.addWidget(self.cancel_btn)
controls.addWidget(about_btn)
# Progress bar (start empty)
self.progress_bar = QProgressBar()
self.progress_bar.setTextVisible(False)
self.progress_bar.setFixedHeight(12)
self.progress_bar.setMaximum(100) # empty at start
self.progress_bar.setValue(0)
# Results and counter
self.results_list = QListWidget()
self.results_list.itemDoubleClicked.connect(self.open_item)
self.match_counter_label = QLabel("Matches found: 0")
self.match_counter_label.setAlignment(Qt.AlignRight)
main_layout.addWidget(title)
main_layout.addLayout(controls)
main_layout.addWidget(self.progress_bar)
main_layout.addWidget(self.results_list)
main_layout.addWidget(self.match_counter_label)
self.setLayout(main_layout)
self.apply_styles()
# Timer for smooth animation and glow
self.timer = QTimer()
self.timer.timeout.connect(self.update_progress_smooth)
self.timer.start(15) # small interval for smooth movement
# ---------------------- FUNCTIONS ----------------------
def show_about(self):
QMessageBox.information(
self,
"About FileScope",
"🏢 FileScope - Professional File & Folder Finder\n\n"
"FileScope helps businesses and individuals quickly locate folders, files, "
"or content inside files. Provides fast, efficient, and intuitive search.\n\n"
"Key Features:\n"
"• Search folders by name\n"
"• Search files by name\n"
"• Search for words inside files\n"
"• Smooth hybrid glowing progress bar\n"
"• Live match counter\n"
"• Cancelable search\n"
"• Double-click to open files/folders\n"
"• Press Enter to search\n\n"
"🏢 Built by MateTools\n"
"🌐 Website: https://matetools.gumroad.com"
)
def browse_folder(self):
folder = QFileDialog.getExistingDirectory(self, "Select Folder")
if folder:
self.root_path = folder
self.path_input.setText(folder)
def start_search(self):
if self.worker:
self.worker.stop()
self.worker.wait()
if not self.root_path:
self.results_list.clear()
self.results_list.addItem("Please select a root folder.")
return
query = self.query_input.text().strip()
if not query:
self.results_list.clear()
self.results_list.addItem("Please enter a search query.")
return
self.results_list.clear()
# Start indeterminate glow only when search begins
self.progress_bar.setMaximum(0)
self.smooth_value = 0
self.target_progress = 0
self.glow_pos = 0
self.match_count = 0
self.update_counter()
self.search_btn.setEnabled(False)
self.cancel_btn.setEnabled(True)
self.worker = SearchWorker(self.root_path, self.search_type.currentText(), query)
self.worker.found.connect(self.add_result)
self.worker.progress.connect(self.set_target_progress)
self.worker.finished.connect(self.search_finished)
self.worker.start()
def add_result(self, path):
self.results_list.addItem(path)
self.match_count += 1
self.update_counter()
def update_counter(self):
self.match_counter_label.setText(f"Matches found: {self.match_count}")
def set_target_progress(self, value):
if self.progress_bar.maximum() == 0:
# Switch from indeterminate to real progress
self.progress_bar.setMaximum(100)
self.target_progress = value
def update_progress_smooth(self):
# Smooth progress animation
if self.progress_bar.maximum() != 0 and self.smooth_value < self.target_progress:
self.smooth_value += 1
self.progress_bar.setValue(self.smooth_value)
# Glow effect animation
self.glow_pos = (self.glow_pos + 1) % 200
gradient_pos = self.glow_pos / 200
self.progress_bar.setStyleSheet(f"""
QProgressBar {{
border: 1px solid #334155;
border-radius: 6px;
background-color: #020617;
}}
QProgressBar::chunk {{
background: qlineargradient(
x1:{gradient_pos}, y1:0, x2:{gradient_pos+0.2}, y2:0,
stop:0 #2563eb, stop:0.5 #60a5fa, stop:1 #2563eb
);
border-radius: 6px;
}}
""")
def cancel_search(self):
if self.worker:
self.worker.stop()
def search_finished(self):
self.search_btn.setEnabled(True)
self.cancel_btn.setEnabled(False)
self.progress_bar.setMaximum(100)
self.progress_bar.setValue(100)
if self.results_list.count() == 0:
self.results_list.addItem("No results containing all your search terms were found.")
self.worker = None
def open_item(self, item):
path = item.text()
if os.path.exists(path):
try:
if platform.system() == "Windows":
os.startfile(path)
elif platform.system() == "Darwin":
subprocess.Popen(["open", path])
else:
subprocess.Popen(["xdg-open", path])
except Exception as e:
print(f"Failed to open {path}: {e}")
def closeEvent(self, event):
if self.worker:
self.worker.stop()
self.worker.wait()
event.accept()
def apply_styles(self):
self.setStyleSheet("""
QWidget {
background-color: #0f172a;
color: #e5e7eb;
font-size: 14px;
}
QLineEdit, QComboBox, QListWidget {
background-color: #020617;
border: 1px solid #334155;
border-radius: 6px;
padding: 6px;
}
QPushButton {
background-color: #2563eb;
border: none;
border-radius: 6px;
padding: 8px 14px;
font-weight: bold;
}
QPushButton:hover {
background-color: #1d4ed8;
}
QPushButton:disabled {
background-color: #475569;
}
QLabel#Title {
font-size: 22px;
font-weight: bold;
margin: 10px 0;
}
""")
# ---------------------- MAIN ----------------------
if __name__ == "__main__":
app = QApplication(sys.argv)
window = FinderApp()
window.show()
sys.exit(app.exec())