22import  sys 
33import  os 
44import  threading 
5+ import  time 
56from  PySide6 .QtWidgets  import  (
67    QApplication ,
78    QWidget ,
1718    QGroupBox  # For update settings group 
1819)
1920from  PySide6 .QtGui  import  QIcon , QPainter , QPixmap , QPalette 
20- from  PySide6 .QtCore  import  QSize , Qt , QSettings , QPropertyAnimation , QEasingCurve  # Import QPropertyAnimation and QEasingCurve for animations 
21+ from  PySide6 .QtCore  import  QSize , Qt , QSettings , QPropertyAnimation , QEasingCurve ,  QMetaObject ,  Q_ARG ,  Signal ,  Slot  # Import QPropertyAnimation and QEasingCurve for animations 
2122import  multiprocessing 
2223
2324from  qfluentwidgets  import  Theme , setTheme  # Keep for freeze_support, but remove direct Process usage 
@@ -247,7 +248,7 @@ def init_ui(self):
247248    def  show_settings (self ):
248249        settings_dialog  =  SettingsDialog (self )
249250        self ._settings_dialog  =  settings_dialog   # 保存对话框引用 
250-         settings_dialog .exec () # Use exec() for modal dialog  
251+         settings_dialog .show () # 使用show()而不是exec(),保持对话框非模态  
251252
252253def  run_zip ():
253254    from  zip_gui  import  ZipAppRunner 
@@ -266,14 +267,22 @@ def run_image_app():
266267
267268# --- Settings Dialog Class --- 
268269class  SettingsDialog (QDialog ):
270+     # 定义信号用于线程间通信 
271+     update_status_signal  =  Signal (str , bool )
272+     
269273    def  __init__ (self , parent_window : IconButtonsWindow ):
270274        super ().__init__ (parent_window )
271275        self .parent_window  =  parent_window  # Store reference to the main window 
272276        self .setWindowTitle ("Settings" )
273277                #self.setFixedSize(800, 600) # Increased size for better aesthetics and more content 
278+         
279+         # 连接信号 
280+         self .update_status_signal .connect (self ._update_status_label )
281+         
274282        self .init_ui ()
275283        self .load_settings ()
276284        self ._apply_theme_from_parent () # Apply theme based on parent's current theme 
285+         self ._connect_settings_signals () # Connect settings signals for real-time saving 
277286
278287        # Animation for showing the dialog 
279288        self .animation  =  QPropertyAnimation (self , b"windowOpacity" )
@@ -564,15 +573,16 @@ def init_ui(self):
564573        # Spacer to push content to top 
565574        main_layout .setRowStretch (2 , 1 )
566575
567-         # Apply Button (moved to the bottom, right-aligned) 
568-         apply_button  =  QPushButton ("Apply Settings" )
569-         apply_button .setObjectName ("settings_apply_button" )
570-         apply_button .clicked .connect (self .apply_settings )
571- 
572-         apply_button_layout  =  QHBoxLayout ()
573-         apply_button_layout .addStretch ()
574-         apply_button_layout .addWidget (apply_button )
575-         main_layout .addLayout (apply_button_layout , 3 , 0 , 1 , 2 )
576+         # 实时自动保存状态标签 
577+         self .status_label  =  QLabel ("Settings automatically saved" )
578+         self .status_label .setObjectName ("status_label" )
579+         self .status_label .setAlignment (Qt .AlignmentFlag .AlignRight )
580+         self .status_label .setVisible (False )
581+         
582+         status_layout  =  QHBoxLayout ()
583+         status_layout .addStretch ()
584+         status_layout .addWidget (self .status_label )
585+         main_layout .addLayout (status_layout , 3 , 0 , 1 , 2 )
576586
577587    def  load_settings (self ):
578588        settings  =  QSettings ("MyCompany" , "ConverterApp" )
@@ -581,16 +591,50 @@ def load_settings(self):
581591
582592
583593
584-     def  apply_settings (self ):
585-         settings  =  QSettings ("MyCompany" , "ConverterApp" )
586-         # Theme settings - always System Default 
587-         settings .setValue ("theme" , 0 )
588-         settings .sync () # Ensure settings are written to disk 
594+     def  _connect_settings_signals (self ):
595+         """连接所有设置控件的信号到实时保存""" 
596+         # 这里可以添加其他设置控件的信号连接 
597+         # 例如:self.comboBox.currentIndexChanged.connect(self.save_settings_async) 
598+         pass 
599+     
600+     @Slot (str , bool ) 
601+     def  _update_status_label (self , text , visible ):
602+         """安全更新状态标签的槽函数""" 
603+         self .status_label .setText (text )
604+         self .status_label .setVisible (visible )
605+     
606+     def  save_settings_async (self ):
607+         """在独立线程中异步保存设置""" 
608+         def  save_thread ():
609+             settings  =  QSettings ("MyCompany" , "ConverterApp" )
610+             # Theme settings - always System Default 
611+             settings .setValue ("theme" , 0 )
612+             settings .sync () # Ensure settings are written to disk 
613+             
614+             # 通过信号在主线程中安全更新UI 
615+             self .update_status_signal .emit ("Settings saved" , True )
616+             
617+             # 2秒后隐藏状态标签 
618+             time .sleep (2 )
619+             self .update_status_signal .emit ("" , False )
620+         
621+         # 启动独立线程执行保存操作 
622+         thread  =  threading .Thread (target = save_thread )
623+         thread .daemon  =  True 
624+         thread .start ()
625+         
626+         # 立即应用主题变更 
589627        if  self .parent_window :
590-             self .parent_window ._apply_system_theme_from_settings () # Reapply theme if it changed 
591-         self .accept () # Close dialog 
628+             self .parent_window ._apply_system_theme_from_settings ()
592629
630+     def  accept (self ):
631+         """重写accept方法,只保存设置而不关闭对话框""" 
632+         self .save_settings_async ()
593633
634+     def  reject (self ):
635+         """重写reject方法,保存设置并关闭对话框""" 
636+         self .save_settings_async ()
637+         super ().reject ()
594638
595639
596640if  __name__  ==  "__main__" :
0 commit comments