Skip to content

Commit 5a2d667

Browse files
authored
Added new settings option
- Updated links in the About menu - Added settings option for controlling the actions which is executed when an item is double-clicked - Updated settings handling
1 parent aba5656 commit 5a2d667

File tree

7 files changed

+101
-120
lines changed

7 files changed

+101
-120
lines changed

FF_About_UI.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ def generate_link_button(displayed_text, domain):
124124
# Return the Label to move it
125125
return link
126126

127-
sourcecode = generate_link_button("Website", "https://pixel-master.github.io/File-Find/")
128-
about_layout.addWidget(sourcecode, 7, 0)
127+
update = generate_link_button("Update", "https://pixel-master.github.io/File-Find/download")
128+
about_layout.addWidget(update, 7, 0)
129129

130-
update = generate_link_button("Update", "https://github.com/Pixel-Master/File-Find/releases")
131-
about_layout.addWidget(update, 7, 1)
130+
sourcecode = generate_link_button("Website and FaQ", "https://pixel-master.github.io/File-Find/")
131+
about_layout.addWidget(sourcecode, 7, 1)
132132

133-
faq_link = generate_link_button("FaQ", "https://pixel-master.github.io/File-Find/#faq")
133+
faq_link = generate_link_button("Source", "https://github.com/Pixel-Master/File-Find")
134134
about_layout.addWidget(faq_link, 7, 2)
135135

136136
# Menu bar

FF_Compare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(self, path_of_first_search, parent):
8787
# Add items
8888
self.added_files_listbox.addItems(compared_searches.files_only_in_first_search)
8989
# Double-Clicking Event
90-
self.added_files_listbox.doubleClicked.connect(menu_bar.open_in_finder)
90+
self.added_files_listbox.doubleClicked.connect(menu_bar.double_clicking_item)
9191

9292
# Removed files / files only in second search
9393

@@ -102,7 +102,7 @@ def __init__(self, path_of_first_search, parent):
102102
# Add items
103103
self.removed_files_listbox.addItems(compared_searches.files_only_in_second_search)
104104
# Double-Clicking Event
105-
self.removed_files_listbox.doubleClicked.connect(menu_bar.open_in_finder)
105+
self.removed_files_listbox.doubleClicked.connect(menu_bar.double_clicking_item)
106106

107107
# Debug
108108
logging.debug("Done!")

FF_Duplicated.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def __init__(
428428
def open_double_clicked(item):
429429
# Only if subdirectory is clicked
430430
if item.text(0) != os.path.basename(item.text(0)):
431-
menu_bar.open_in_finder()
431+
menu_bar.double_clicking_item()
432432

433433
self.Duplicated_Tree.itemDoubleClicked.connect(open_double_clicked)
434434

FF_Files.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
# Versions
2020
VERSION: str = "27-july-2024"
21-
VERSION_SHORT: str = "1.1-beta1"
21+
VERSION_SHORT: str = "1.1"
2222
# Versions of file formats
2323
FF_FILTER_VERSION = 1
2424
FF_SEARCH_VERSION = 1
@@ -97,10 +97,11 @@
9797
"first_version": f"{VERSION_SHORT}[{VERSION}]",
9898
"version": f"{VERSION_SHORT}[{VERSION}]",
9999
"excluded_files": [],
100-
"cache": "On Launch",
100+
"cache": "on Launch",
101101
"popup": {"FF_ver_welcome": False, "FF_welcome": True, "delete_question": False},
102102
"filter_preset_name": "Default",
103-
"display_menu_bar_icon": True}
103+
"display_menu_bar_icon": True,
104+
"double_click_action": "View file in Finder/File Explorer"}
104105

105106
# Color schemes
106107
RED_COLOR = "#b31b00"
@@ -127,7 +128,7 @@ def cache_test(is_launching):
127128
logging.debug(f"{cache_settings = }")
128129

129130
# Deleting Cache on Launch
130-
if cache_settings == "On Launch" and is_launching:
131+
if cache_settings.lower() == "on launch" and is_launching:
131132
logging.debug("Deleting Cache!")
132133
remove_cache()
133134

@@ -280,7 +281,14 @@ def setup():
280281
"delete_question": settings["popup"]["delete_question"]}
281282

282283
for settings_key in DEFAULT_SETTINGS:
283-
settings[settings_key] = settings[settings_key]
284+
try:
285+
settings[settings_key] = settings[settings_key]
286+
# If a new setting was added
287+
except KeyError:
288+
settings[settings_key] = DEFAULT_SETTINGS[settings_key]
289+
# Debug
290+
logging.info(f"Resetting {settings_key}"
291+
f" setting to {DEFAULT_SETTINGS[settings_key]} because it didn't exist")
284292

285293
if updated:
286294
settings["popup"]["FF_ver_welcome"] = True

FF_Menubar.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(
9696
self.tools_menu.addAction(open_terminal_action)
9797

9898
# Show File in Finder Action
99-
show_action = QAction("&Open selected file in Finder", self.parent)
99+
show_action = QAction("&View selected file in Finder/File Explorer", self.parent)
100100
show_action.triggered.connect(self.open_in_finder)
101101
show_action.setShortcut("Ctrl+Shift+O")
102102
self.tools_menu.addAction(show_action)
@@ -734,3 +734,22 @@ def get_current_item(self):
734734
return self.listbox.currentItem().text(0)
735735
else:
736736
return self.listbox.currentItem().text()
737+
738+
# When an item is double-clicked
739+
def double_clicking_item(self):
740+
# Loading Setting
741+
action = FF_Settings.SettingsWindow.load_setting("double_click_action")
742+
743+
# Action according to the set option
744+
if action == "View file in Finder/File Explorer":
745+
self.open_in_finder()
746+
elif action == "Open file":
747+
self.open_file()
748+
elif action == "Info about file":
749+
self.file_info()
750+
else:
751+
logging.error("Select option for double_click_action is NOT valid. Resetting it.\n")
752+
# Resetting it because the option isn't valid
753+
FF_Settings.SettingsWindow.update_setting("double_click_action",
754+
FF_Files.DEFAULT_SETTINGS["double_click_action"])
755+

FF_Search_UI.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def generate_button(text, command, icon=None):
356356
self.result_listbox.setCurrentRow(0)
357357

358358
# On double-click
359-
self.result_listbox.itemDoubleClicked.connect(menu_bar.open_in_finder)
359+
self.result_listbox.itemDoubleClicked.connect(menu_bar.double_clicking_item)
360360

361361
# Update Seconds needed Label
362362
seconds_text.setText(

FF_Settings.py

Lines changed: 59 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
import sys
1717

1818
# PySide6 Gui Imports
19-
from PySide6.QtGui import QFont, QAction, Qt
19+
from PySide6.QtGui import QFont, Qt
2020
from PySide6.QtWidgets import QMainWindow, QLabel, QPushButton, QListWidget, QFileDialog, QComboBox, \
2121
QMessageBox, QCheckBox, QWidget, QGridLayout, QSizePolicy, QSpacerItem, QLineEdit
2222

2323
# Projects Libraries
2424
import FF_Additional_UI
2525
import FF_Files
26-
import FF_About_UI
2726
import FF_Main_UI
27+
import FF_Menubar
2828

2929

3030
# The class for the help window
@@ -191,20 +191,15 @@ def ask_delete_change():
191191
ask_delete_checkbox.toggled.connect(ask_delete_change)
192192

193193
# Loading Settings
194-
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings")) as read_load_file:
195-
# Loading Settings
196-
ask_searching_settings = load(read_load_file)["popup"]["delete_question"]
197-
198-
# Changing Settings
199-
if ask_searching_settings:
200-
ask_delete_checkbox.setChecked(True)
194+
if self.load_setting("popup")["delete_question"]:
195+
ask_delete_checkbox.setChecked(True)
201196

202197
# Display
203198
ask_delete_checkbox.show()
204199
ask_delete_checkbox.adjustSize()
205200
self.Settings_Layout.addWidget(ask_delete_checkbox, 0, 1)
206201

207-
# Language
202+
# Filter Preset
208203
# Define the Label
209204
filter_preset_label = QLabel("Filter Preset on launch:", parent=self.Settings_Window)
210205
filter_preset_label.setToolTip("The filter preset loaded at launch")
@@ -226,19 +221,11 @@ def ask_delete_change():
226221
def reset_filter_preset():
227222
# Debug
228223
logging.info("Setting filter preset to default\n")
229-
# Loading settings
230-
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings")) as settings_preset_file:
231-
settings = load(settings_preset_file)
232-
# Modifying Settings
233-
settings["filter_preset_name"] = FF_Files.DEFAULT_SETTINGS["filter_preset_name"]
234-
224+
# Update settings
225+
self.update_setting("filter_preset_name", FF_Files.DEFAULT_SETTINGS["filter_preset_name"])
235226
# Updating line edit
236227
filter_line_edit.setText(FF_Files.DEFAULT_SETTINGS["filter_preset_name"])
237228

238-
# Dump new settings
239-
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings"), "w") as settings_preset_file:
240-
dump(settings, settings_preset_file)
241-
242229
try:
243230
# Removing filter preset
244231
os.remove(os.path.join(FF_Files.FF_LIB_FOLDER, "Default.FFFilter"))
@@ -279,41 +266,36 @@ def select_preset():
279266
filter_line_edit.setText(os.path.basename(file_path))
280267

281268
# Updating settings
282-
283-
# Loading settings
284-
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings")) as settings_preset_file:
285-
settings = load(settings_preset_file)
286-
# Modifying Settings
287-
settings["filter_preset_name"] = os.path.basename(file_path)
288-
289-
# Dump new settings
290-
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings"), "w") as settings_preset_file:
291-
dump(settings, settings_preset_file)
269+
self.update_setting("filter_preset_name", os.path.basename(file_path))
292270

293271
# Debug
294272
logging.info(f"Set filter preset to {file_path}\n")
295273

296274
select_preset_button = generate_button("Select .FFFilter Preset", select_preset, 150)
297275
self.Settings_Layout.addWidget(select_preset_button, 1, 3)
298276

299-
# Language
277+
# Double-clicking
300278
# Define the Label
301-
language_label = QLabel("Language:", parent=self.Settings_Window)
279+
double_click_label = QLabel("Action when double-clicking:", parent=self.Settings_Window)
302280
# Change Font
303-
language_label.setFont(QFont(FF_Files.DEFAULT_FONT, FF_Files.SMALLER_FONT_SIZE))
281+
double_click_label.setFont(QFont(FF_Files.DEFAULT_FONT, FF_Files.SMALLER_FONT_SIZE))
304282
# Display the Label
305-
self.Settings_Layout.addWidget(language_label, 2, 0)
283+
self.Settings_Layout.addWidget(double_click_label, 2, 0)
306284

307285
# Drop Down Menu
308-
# Language Menu
286+
# Double-Click Menu
309287
# Defining
310-
combobox_language = QComboBox(self.Settings_Window)
288+
combobox_double_click = QComboBox(self.Settings_Window)
311289
# Adding Options
312-
combobox_language.addItems(["English"])
290+
combobox_double_click.addItems(["View file in Finder/File Explorer", "Open file", "Info about file"])
291+
combobox_double_click.setCurrentText(self.load_setting("double_click_action"))
313292
# Display
314-
self.Settings_Layout.addWidget(combobox_language, 2, 1)
315-
316-
# Push Button
293+
self.Settings_Layout.addWidget(combobox_double_click, 2, 1, 2, 2)
294+
combobox_double_click.setFixedWidth(230)
295+
# When changed, update settings
296+
combobox_double_click.currentTextChanged.connect(
297+
lambda: self.update_setting(setting_key="double_click_action",
298+
new_value=combobox_double_click.currentText()))
317299

318300
# Reset Settings
319301
# Define the Label
@@ -377,29 +359,12 @@ def reset_settings():
377359
# Defining
378360
combobox_cache = QComboBox(self.Settings_Window)
379361
# Adding Options
380-
combobox_cache_items = ["On Launch", "after a Day", "after a Week", "Never"]
362+
combobox_cache_items = ["on Launch", "after a Day", "after a Week", "Never"]
381363
combobox_cache.addItems(combobox_cache_items)
382-
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings")) as read_define_file:
383-
combobox_cache.setCurrentText(load(read_define_file)["cache"])
384-
385-
# Updating on change
386-
def update_cache_settings():
387-
# Saving the Settings and replacing the old settings with the new one
388-
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings")) as read_file:
389-
# Loading Settings
390-
settings = load(read_file)
391-
392-
# Changing Settings
393-
settings["cache"] = combobox_cache.currentText()
394-
395-
# Dumping new Settings
396-
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings"), "w") as write_rile:
397-
dump(settings, write_rile)
398-
399-
# Debug
400-
logging.info(f"Changed Cache Settings to : {combobox_cache.currentText()}")
364+
combobox_cache.setCurrentText(self.load_setting("cache"))
401365

402-
combobox_cache.currentIndexChanged.connect(update_cache_settings)
366+
# Changing cache setting on update
367+
combobox_cache.currentIndexChanged.connect(lambda: self.update_setting("cache", combobox_cache.currentText()))
403368

404369
# Display
405370
self.Settings_Layout.addWidget(combobox_cache, 5, 1)
@@ -423,65 +388,54 @@ def menu_bar_icon_change():
423388
else:
424389
FF_Main_UI.menu_bar_icon.hide()
425390

426-
# Saving the Settings and replacing the old settings with the new one
427-
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings")) as read_file:
428-
# Loading Settings
429-
settings = load(read_file)
430-
431-
# Changing Settings
432-
settings["display_menu_bar_icon"] = menu_bar_icon_checkbox.isChecked()
433-
434-
logging.info(f"Changed PopUp Settings Menu bar Question:"
435-
f" Display menu bar icon {menu_bar_icon_checkbox.isChecked()}")
436-
# Dumping new Settings
437-
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings"), "w") as write_file:
438-
dump(settings, write_file)
391+
# Update the setting
392+
self.update_setting("display_menu_bar_icon", menu_bar_icon_checkbox.isChecked())
439393

440394
# Connecting the checkbox to the function above
441395
menu_bar_icon_checkbox.toggled.connect(menu_bar_icon_change)
442396

443-
# Loading Settings
444-
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings")) as read_load_file:
445-
# Loading Settings
446-
menu_bar_icon_setting = load(read_load_file)["display_menu_bar_icon"]
447-
448-
# Changing Settings
449-
if menu_bar_icon_setting:
450-
menu_bar_icon_checkbox.setChecked(True)
397+
# Loading Setting
398+
menu_bar_icon_setting = self.load_setting("display_menu_bar_icon")
399+
# Changing Settings
400+
if menu_bar_icon_setting:
401+
menu_bar_icon_checkbox.setChecked(True)
451402

452403
# Display
453404
self.Settings_Layout.addWidget(menu_bar_icon_checkbox, 6, 1)
454405

455406
# Menu-bar
456-
menu_bar = self.Settings_Window.menuBar()
407+
FF_Menubar.MenuBar(self.Settings_Window, "settings", None, )
457408

458-
# Menus
459-
window_menu = menu_bar.addMenu("&Window")
460-
help_menu = menu_bar.addMenu("&Help")
461-
462-
# Close Window
463-
close_action = QAction("&Close Window", self.Settings_Window)
464-
close_action.triggered.connect(self.Settings_Window.hide)
465-
close_action.setShortcut("Ctrl+W")
466-
window_menu.addAction(close_action)
409+
# Debug
410+
logging.info("Finished Setting up Help UI\n")
467411

468-
# About File Find
469-
about_action = QAction("&About File Find", self.Settings_Window)
470-
about_action.triggered.connect(lambda: FF_About_UI.AboutWindow(self.Settings_Window))
471-
help_menu.addAction(about_action)
412+
# Updating settings when they are changed
413+
@staticmethod
414+
def update_setting(setting_key, new_value):
415+
# loading the settings
416+
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings")) as read_file:
417+
# Loading Settings
418+
settings = load(read_file)
472419

473-
# Help
474-
help_action = QAction("&About File Find", self.Settings_Window)
475-
help_action.triggered.connect(lambda: FF_About_UI.AboutWindow(self.Settings_Window))
476-
help_menu.addAction(help_action)
420+
# Changing Settings
421+
settings[setting_key] = new_value
477422

478-
# Tutorial
479-
tutorial_action = QAction("&Tutorial", self.Settings_Window)
480-
tutorial_action.triggered.connect(lambda: FF_Additional_UI.welcome_popups(parent, force_popups=True))
481-
help_menu.addAction(tutorial_action)
423+
# Dumping new Settings
424+
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings"), "w") as write_file:
425+
dump(settings, write_file)
482426

483427
# Debug
484-
logging.info("Finished Setting up Help UI\n")
428+
logging.info(f"Changed {setting_key} setting to : {new_value}")
429+
430+
# Loading the value of setting, can be used everywhere
431+
@staticmethod
432+
def load_setting(setting_key):
433+
# Loading Settings
434+
with open(os.path.join(FF_Files.FF_LIB_FOLDER, "Settings")) as read_file:
435+
# Loading Settings with JSON
436+
setting_value = load(read_file)[setting_key]
437+
438+
return setting_value
485439

486440

487441
settings_window_global = None

0 commit comments

Comments
 (0)