1616import sys
1717
1818# PySide6 Gui Imports
19- from PySide6 .QtGui import QFont , QAction , Qt
19+ from PySide6 .QtGui import QFont , Qt
2020from PySide6 .QtWidgets import QMainWindow , QLabel , QPushButton , QListWidget , QFileDialog , QComboBox , \
2121 QMessageBox , QCheckBox , QWidget , QGridLayout , QSizePolicy , QSpacerItem , QLineEdit
2222
2323# Projects Libraries
2424import FF_Additional_UI
2525import FF_Files
26- import FF_About_UI
2726import 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
487441settings_window_global = None
0 commit comments