Skip to content

Commit 1e636c4

Browse files
authored
Fixed QFileDialog filters, fixed windows separator
1 parent 607aea1 commit 1e636c4

File tree

8 files changed

+38
-31
lines changed

8 files changed

+38
-31
lines changed

FF_Additional_UI.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def get_paths():
109109
# Check if "/" is at end of inputted path
110110
if check:
111111
# Going through all paths to look if auto-completion should be loaded
112-
if path.endswith(os.sep):
112+
if path.endswith(FF_Files.SEP):
113113
completer_paths = get_paths()
114114
logging.debug("Changed QCompleter")
115115
else:

FF_Compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def load_second_search():
427427
parent=None,
428428
caption="Select Second Search",
429429
dir=FF_Files.USER_FOLDER,
430-
filter="*.FFSearch;")
430+
filter="*.FFSearch")
431431

432432
# Debug
433433
logging.debug(f"Second search: {second_search_file[0]}, Reading file...")

FF_Files.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
elif platform == "win32" or platform == "cygwin":
3939
FF_LIB_FOLDER = os.path.join(USER_FOLDER, "AppData", "Roaming", "File-Find")
4040
NORMAL_FONT_SIZE = 15
41-
SMALLER_FONT_SIZE = 13
41+
SMALLER_FONT_SIZE = 12
4242
# Standard file separator
4343
SEP = "\\"
4444
# On Linux
4545
else:
4646
FF_LIB_FOLDER = os.path.join(USER_FOLDER, ".file-find")
4747
NORMAL_FONT_SIZE = 15
48-
SMALLER_FONT_SIZE = 14
48+
SMALLER_FONT_SIZE = 12
4949
# Standard file separator
5050
SEP = os.sep
5151

@@ -136,10 +136,10 @@ def remove_cache():
136136
# Convert a file path to the corresponding cache file or metadata
137137
def path_to_cache_file(path, metadata=False):
138138
if not metadata:
139-
return os.path.join(CACHED_SEARCHES_FOLDER, path.replace(os.sep, "-") + ".FFCache")
139+
return os.path.join(CACHED_SEARCHES_FOLDER, path.replace(SEP, "-") + ".FFCache")
140140
# If instead ask for metadata
141141
elif metadata:
142-
return os.path.join(CACHE_METADATA_FOLDER, path.replace(os.sep, "-") + ".FFCache")
142+
return os.path.join(CACHE_METADATA_FOLDER, path.replace(SEP, "-") + ".FFCache")
143143
else:
144144
logging.fatal("Wrong arguments used with the convert_path_to_cache_file() function in FF_Files.py")
145145

FF_Main_UI.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -874,11 +874,11 @@ def reset_filters(self):
874874
def import_filters(self, import_path=None):
875875
if import_path is None:
876876
# Debug
877-
logging.info("Asking for location for export")
877+
logging.info("Asking for location for import")
878878
import_path = QFileDialog.getOpenFileName(parent=self.Root_Window,
879879
dir=FF_Files.USER_FOLDER,
880-
caption="Export File Find Search",
881-
filter="*.FFFilter;*.FFSearch")[0]
880+
caption="Import Filer or Search",
881+
filter="File Find Filter or Search (*.FFFilter *.FFSearch)")[0]
882882

883883
# If opened file is a search
884884
if import_path.endswith(".FFSearch"):
@@ -943,15 +943,24 @@ def import_filters(self, import_path=None):
943943
def export_filters(self):
944944
# Debug
945945
logging.info("Request location for export")
946-
export_path = QFileDialog.getSaveFileName(parent=self.Root_Window,
947-
dir=FF_Files.USER_FOLDER,
948-
caption="Export File Find Search",
949-
filter="File Find Filter Preset (*.FFFilter);;"
950-
"JSON (JavaScript Object Notation) (*.json)")[0]
946+
export_dialog = QFileDialog.getSaveFileName(parent=self.Root_Window,
947+
dir=FF_Files.USER_FOLDER,
948+
caption="Export File Find Search",
949+
filter="File Find Filter Preset (*.FFFilter);;"
950+
"JSON (JavaScript Object Notation) (*.json)")[0]
951+
export_path = export_dialog[0]
952+
951953
# If User pressed "Cancel"
952954
if export_path == "":
953955
return
954956

957+
# If the suffix wasn't added, add it
958+
if not (export_path.endswith(".FFFilter") or export_path.endswith(".json")):
959+
if "FFFilter" in export_dialog[1]:
960+
export_path += ".FFFilter"
961+
else:
962+
export_path += ".json"
963+
955964
# Debug
956965
logging.info(f"Exporting all filters to {export_path}, with {FF_Files.FF_FILTER_VERSION=}...")
957966
# Making user folder compatible

FF_Menubar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def open_in_app(self):
478478
selected_program = QFileDialog.getOpenFileName(
479479
parent=self.parent,
480480
dir="/Applications",
481-
filter="*.app;")[0]
481+
filter="Application/Executable (*.app *.bin *.exe")[0]
482482

483483
# Tests if the user selected an app
484484
if selected_program != "":

FF_Search.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# PySide6 Gui Imports
2222
from PySide6.QtCore import QThreadPool, Signal, QObject, QDate, Qt
23-
from PySide6.QtWidgets import QFileDialog, QWidget
23+
from PySide6.QtWidgets import QWidget
2424

2525
# Projects Libraries
2626
import FF_Additional_UI
@@ -100,16 +100,6 @@ def __str__(self):
100100

101101
# Loading a saved search
102102
class LoadSearch:
103-
def __init__(self, parent):
104-
load_dialog = QFileDialog.getOpenFileName(parent,
105-
"Import File Find Search",
106-
FF_Files.USER_FOLDER,
107-
"*.FFSearch;")
108-
self.load_file = load_dialog[0]
109-
110-
# Open file
111-
self.open_file(self.load_file, parent)
112-
113103
# Opening the user-interface and creating a cache file for the reload button
114104
@staticmethod
115105
def load_search_content(load_file):
@@ -579,7 +569,7 @@ def searching(self, data_name, data_in_name, data_filetype, data_file_size_min,
579569

580570
for cache_file in os.listdir(FF_Files.CACHED_SEARCHES_FOLDER):
581571
# Looks if there is a cache file for a higher directory
582-
if data_search_from.replace(os.sep, "-").startswith(cache_file.removesuffix(".FFCache")):
572+
if data_search_from.replace(FF_Files.SEP, "-").startswith(cache_file.removesuffix(".FFCache")):
583573
# Date created from separate file
584574
with open(os.path.join(FF_Files.CACHE_METADATA_FOLDER, cache_file)) as time_file:
585575
cache_file_c_date = load(time_file)["c_time"]
@@ -970,7 +960,7 @@ def searching(self, data_name, data_in_name, data_filetype, data_file_size_min,
970960
# the broader cache which was created at the same time. Dividing by 10 so to only add fractions of
971961
# a seconds to the c_time as to not get ranked over newer caches.
972962
# Doing this so the already specialized cache gets used preferably
973-
c_time_adjust = data_search_from.count(os.sep) / 10
963+
c_time_adjust = data_search_from.count(FF_Files.SEP) / 10
974964
logging.debug(f"Cache time {newest_fitting_cache_file_c_date} + adjuster: {c_time_adjust} "
975965
f"= {newest_fitting_cache_file_c_date + c_time_adjust}")
976966

FF_Search_UI.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,19 @@ def save_search():
140140
FF_Files.USER_FOLDER,
141141
"File Find Search (*.FFSearch);;Plain Text File (*.txt)")
142142
save_file = save_dialog[0]
143+
144+
# If the suffix wasn't added, add it
145+
if not (save_file.endswith(".FFSearch") or save_file.endswith(".txt")):
146+
if "FFFilter" in save_dialog[1]:
147+
save_file += ".FFFilter"
148+
else:
149+
save_file += ".json"
150+
143151
if save_file.endswith(".txt") and not os.path.exists(save_file):
144152
with open(save_file, "w") as export_file:
145153
for save_file in self.matched_list:
146154
export_file.write(save_file + "\n")
147-
elif save_file.endswith("FSearch") and not os.path.exists(save_file):
155+
elif save_file.endswith(".FSearch") and not os.path.exists(save_file):
148156
with open(save_file, "w") as export_file:
149157
dump({"VERSION": FF_Files.FF_SEARCH_VERSION, "matched_list": self.matched_list}, export_file)
150158

File-Find.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ def event(self, event: QEvent) -> bool:
5656
path = QFileOpenEvent.url(event).path()
5757

5858
# If the opened file is a file find search
59-
if path.endswith("FFSearch"):
59+
if path.endswith(".FFSearch"):
6060
# Debug
6161
logging.info(f"Opening {path}...")
6262
FF_Search.LoadSearch.open_file(path, None)
6363

6464
# Filter preset
65-
elif path.endswith("FFFilter"):
65+
elif path.endswith(".FFFilter"):
6666
# Debug
6767
logging.info(f"Opening {path}...")
6868
main_window.import_filters(path)

0 commit comments

Comments
 (0)