Skip to content

Commit 7ff13e0

Browse files
committed
Auto-selection functionality testing
1 parent 9c260a9 commit 7ff13e0

File tree

3 files changed

+33
-52
lines changed

3 files changed

+33
-52
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,17 @@ This is still very much WIP, and as it has the capability to delete files so ple
4040

4141
## KNOWN BUGS
4242

43+
- If too many files are selected for moving/deletion the box gets cut off at the bottom
4344
- While scanning it will display "0 matches found" despite finding matches
4445
- The sorting for the list of duplicate files seems to be bugged
45-
- (When clicking 'Sort By:' the list doesn't group the matches together)
4646

4747
## Future Plans
4848

4949
- Overhaul GUI
50-
- Implement saving/loading results list
51-
- Allow selection of multiple directories
50+
- Implement loading results list
5251
- Display the position itself for each group
53-
- Implement a form of auto-selection for the results
54-
- Ideally, a form of regex searching for the directory
55-
- Option to always ensure one of each matching file is preserved
52+
- Currently position data is saved if "Save Results" is selected
53+
- Option to always ensure one of each matching file is preserved
5654
- Optimize scanning (starts to slow down after 10K+ files)
5755
- More customization (Instead of 'Clear Name Field' allow user to specify 'Clear x Field', etc)
5856
- Pause/Stop/Resume functionality when scanning

gui.py

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ def process_files():
4242
duplicate_positions = set()
4343
near_duplicate_positions = set()
4444

45-
auto_select_dir = auto_select_entry.get()
46-
4745
position_to_files, duplicate_positions, near_duplicate_positions, invalid_positions, filenames_within_group = find_duplicate_and_near_duplicate_positions(
4846
directory,
4947
duplicates,
@@ -55,10 +53,8 @@ def process_files():
5553
round_positions=clean_options['round_positions'],
5654
find_near_duplicates=duplicate_options['find_similar_matches'],
5755
tolerance=duplicate_options['similarity_threshold'],
58-
progress_callback=lambda current, total, file_path: update_progress(current, total, file_path, duplicate_positions, near_duplicate_positions),
59-
auto_select_dir=auto_select_dir
56+
progress_callback=lambda current, total, file_path: update_progress(current, total, file_path, duplicate_positions, near_duplicate_positions)
6057
)
61-
6258
end_time = time.time()
6359

6460
progress_bar.stop()
@@ -69,45 +65,6 @@ def process_files():
6965
duplicate_window.geometry("800x600")
7066
duplicate_window.resizable(True, True)
7167

72-
def auto_select_files():
73-
auto_select_dir = auto_select_entry.get()
74-
if auto_select_dir:
75-
auto_select_pattern = os.path.join(auto_select_dir, '*')
76-
auto_select_files = glob.glob(auto_select_pattern)
77-
78-
selected_indices = []
79-
for index, result_file in enumerate(duplicate_listbox.get(0, tk.END)):
80-
if result_file in auto_select_files:
81-
selected_indices.append(index)
82-
83-
duplicate_listbox.selection_set(selected_indices)
84-
85-
for rounded_position, file_paths in position_to_files.items():
86-
selected_file = None
87-
for file_path in file_paths:
88-
if file_path not in filenames_within_group[rounded_position]:
89-
filenames_within_group[rounded_position].add(file_path)
90-
selected_file = file_path
91-
break
92-
93-
if auto_select_dir and selected_file:
94-
auto_select_pattern = os.path.join(auto_select_dir, '*')
95-
if selected_file.startswith(auto_select_pattern):
96-
index = duplicate_listbox.get(0, tk.END).index(os.path.relpath(selected_file, directory))
97-
duplicate_listbox.itemconfig(index, bg='lightblue')
98-
99-
auto_select_frame = tk.Frame(duplicate_window)
100-
auto_select_frame.pack(pady=10)
101-
102-
auto_select_label = tk.Label(auto_select_frame, text="Auto-Select Directory (with wildcards):")
103-
auto_select_label.pack(side=tk.LEFT)
104-
105-
auto_select_entry = tk.Entry(auto_select_frame, width=30)
106-
auto_select_entry.pack(side=tk.LEFT, padx=5)
107-
108-
auto_select_button = tk.Button(auto_select_frame, text="Auto-Select", command=auto_select_files)
109-
auto_select_button.pack(side=tk.LEFT)
110-
11168
duplicate_frame = tk.Frame(duplicate_window)
11269
duplicate_frame.pack(fill=tk.BOTH, expand=True, pady=10, padx=10)
11370

@@ -130,6 +87,20 @@ def auto_select_files():
13087
duplicate_listbox.insert(tk.END, os.path.relpath(file_path, directory))
13188
duplicate_listbox.insert(tk.END, "") # Add a blank line between groups
13289

90+
def auto_select_files(directory):
91+
auto_select_dir = auto_select_entry.get()
92+
if auto_select_dir:
93+
selected_indices = []
94+
for index, result_file in enumerate(duplicate_listbox.get(0, tk.END)):
95+
if result_file:
96+
if result_file.startswith(auto_select_dir):
97+
selected_indices.append(index)
98+
99+
duplicate_listbox.selection_clear(0, tk.END) # Clear any previous selection
100+
for index in selected_indices:
101+
duplicate_listbox.selection_set(index)
102+
duplicate_listbox.itemconfig(index, bg='lightblue')
103+
133104
def delete_selected_files():
134105
selected_indices = duplicate_listbox.curselection()
135106
selected_files = [duplicate_listbox.get(index) for index in selected_indices]
@@ -183,11 +154,23 @@ def move_selected_files():
183154
move_button = tk.Button(action_frame, text="Move Selected Files", command=move_selected_files)
184155
move_button.pack(side=tk.LEFT)
185156

157+
auto_select_frame = tk.Frame(duplicate_window)
158+
auto_select_frame.pack(pady=10)
159+
160+
auto_select_label = tk.Label(auto_select_frame, text="Auto-Select Directory (with wildcards):")
161+
auto_select_label.pack(side=tk.LEFT)
162+
163+
auto_select_entry = tk.Entry(auto_select_frame, width=30)
164+
auto_select_entry.pack(side=tk.LEFT, padx=5)
165+
166+
auto_select_button = tk.Button(auto_select_frame, text="Select", command=lambda: auto_select_files(directory))
167+
auto_select_button.pack(side=tk.LEFT)
168+
186169
def save_results():
187170
file_path = filedialog.asksaveasfilename(defaultextension=".txt", filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")])
188171
if file_path:
189172
try:
190-
with open(file_path, "w") as file:
173+
with open(file_path, "w", encoding="utf-8") as file:
191174
file.write("Exact Duplicate Positions:\n")
192175
for position in duplicate_positions:
193176
file.write(f"Position: {position}\n")

json_file_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def round_positions_in_file(file_path, num_decimals):
8989
except (json.JSONDecodeError, FileNotFoundError) as e:
9090
logging.error(f"Error processing file: {file_path} - {str(e)}")
9191

92-
def find_duplicate_and_near_duplicate_positions(directory_path, duplicates, near_duplicates, file_pattern='*.json', ignore_empty=False, num_decimals=None, update_name=False, remove_description=False, clear_name=False, round_positions=False, find_near_duplicates=False, tolerance=1, auto_select_dir=None, progress_callback=None):
92+
def find_duplicate_and_near_duplicate_positions(directory_path, duplicates, near_duplicates, file_pattern='*.json', ignore_empty=False, num_decimals=None, update_name=False, remove_description=False, clear_name=False, round_positions=False, find_near_duplicates=False, tolerance=1, progress_callback=None):
9393
position_to_files = defaultdict(list)
9494
duplicate_positions = set()
9595
near_duplicate_positions = set()

0 commit comments

Comments
 (0)