1- import os
2- import configparser
1+ import os , configparser
32from pathlib import Path
43from kernel import KernelManager
5-
4+ from cpu import CPUManager
5+ from disk import DiskManager
6+ from gpu_launch import GPULaunchManager
67
78class ConfigManager :
8- """
9- Handles saving and loading of application configuration settings.
10- """
119
1210 @staticmethod
1311 def get_config_path (profile_name = "Default" ):
1412 """
15- Get the configuration file path, creating directories if needed .
13+ Get the configuration file path for a given profile .
1614 """
1715 config_dir = Path (os .path .expanduser ("~/.config/volt-gui" ))
1816 config_dir .mkdir (parents = True , exist_ok = True )
@@ -24,7 +22,7 @@ def get_config_path(profile_name="Default"):
2422 @staticmethod
2523 def get_available_profiles ():
2624 """
27- Get list of available profile names .
25+ Get a list of all available configuration profiles .
2826 """
2927 config_dir = Path (os .path .expanduser ("~/.config/volt-gui" ))
3028 profiles = ["Default" ]
@@ -39,64 +37,56 @@ def get_available_profiles():
3937 @staticmethod
4038 def save_config (cpu_widgets , gpu_widgets , kernel_widgets , disk_widgets , profile_name = "Default" ):
4139 """
42- Save all widget settings to the configuration file.
40+ Save configuration settings to a profile file.
4341 """
4442 config = configparser .ConfigParser ()
4543
46- config ['CPU' ] = {
47- 'governor' : cpu_widgets ['gov_combo' ].currentText (),
48- 'max_freq' : cpu_widgets ['max_freq_combo' ].currentText (),
49- 'min_freq' : cpu_widgets ['min_freq_combo' ].currentText (),
50- 'scheduler' : cpu_widgets ['sched_combo' ].currentText ()
51- }
52-
53- config ['Mesa' ] = {}
54- for widget_key , widget in gpu_widgets ['mesa' ].items ():
55- if hasattr (widget , 'currentText' ) and widget_key != 'mesa_apply_button' :
56- config ['Mesa' ][widget_key ] = widget .currentText ()
57-
58- config ['NVIDIA' ] = {}
59- for widget_key , widget in gpu_widgets ['nvidia' ].items ():
60- if hasattr (widget , 'currentText' ) and widget_key != 'nvidia_apply_button' :
61- config ['NVIDIA' ][widget_key ] = widget .currentText ()
62-
63- config ['RenderSelector' ] = {}
64- for widget_key , widget in gpu_widgets ['render_selector' ].items ():
65- if hasattr (widget , 'currentText' ) and widget_key != 'render_selector_apply_button' :
66- config ['RenderSelector' ][widget_key ] = widget .currentText ()
67-
68- config ['RenderPipeline' ] = {}
69- for widget_key , widget in gpu_widgets ['render_pipeline' ].items ():
70- if hasattr (widget , 'currentText' ) and widget_key != 'render_pipeline_apply_button' :
71- config ['RenderPipeline' ][widget_key ] = widget .currentText ()
72-
73- if 'launch_options_input' in gpu_widgets ['launch_options' ]:
74- launch_options = gpu_widgets ['launch_options' ]['launch_options_input' ].text ().replace ('%' , '%%' )
44+ cpu_config = {}
45+ for setting_key in CPUManager .CPU_SETTINGS .keys ():
46+ if setting_key in cpu_widgets and hasattr (cpu_widgets [setting_key ], 'currentText' ):
47+ cpu_config [setting_key ] = cpu_widgets [setting_key ].currentText ()
48+ if cpu_config :
49+ config ['CPU' ] = cpu_config
50+
51+ gpu_config = {}
52+ for setting_key in GPULaunchManager .GPU_SETTINGS .keys ():
53+ for category_name , category_widgets in gpu_widgets .items ():
54+ if category_name != 'LaunchOptions' and setting_key in category_widgets :
55+ if hasattr (category_widgets [setting_key ], 'currentText' ):
56+ gpu_config [setting_key ] = category_widgets [setting_key ].currentText ()
57+ break
58+ if gpu_config :
59+ config ['GPU' ] = gpu_config
60+
61+ if 'LaunchOptions' in gpu_widgets and 'launch_options_input' in gpu_widgets ['LaunchOptions' ]:
62+ launch_options = gpu_widgets ['LaunchOptions' ]['launch_options_input' ].text ().replace ('%' , '%%' )
7563 config ['LaunchOptions' ] = {'launch_options' : launch_options }
7664
77- if kernel_widgets :
78- kernel_config = {}
79- for setting_name in KernelManager .KERNEL_SETTINGS .keys ():
80- value = kernel_widgets [f'{ setting_name } _input' ].text ().strip ()
65+ kernel_config = {}
66+ for setting_key in KernelManager .KERNEL_SETTINGS .keys ():
67+ widget_key = f'{ setting_key } _input'
68+ if widget_key in kernel_widgets :
69+ value = kernel_widgets [widget_key ].text ().strip ()
8170 if value :
82- kernel_config [setting_name ] = value
83- if kernel_config :
84- config ['Kernel' ] = kernel_config
85-
86- if disk_widgets and 'disk_combos' in disk_widgets :
87- disk_config = {}
88- for disk_name , scheduler_combo in disk_widgets ['disk_combos' ].items ():
89- disk_config [disk_name ] = scheduler_combo .currentText ()
90- if disk_config :
91- config ['Disk' ] = disk_config
71+ kernel_config [setting_key ] = value
72+ if kernel_config :
73+ config ['Kernel' ] = kernel_config
74+
75+ disk_config = {}
76+ for disk_name , disk_widgets_dict in disk_widgets ['disk_settings' ].items ():
77+ for setting_key in DiskManager .DISK_SETTINGS .keys ():
78+ if setting_key in disk_widgets_dict :
79+ disk_config [f"{ disk_name } _{ setting_key } " ] = disk_widgets_dict [setting_key ].currentText ()
80+ if disk_config :
81+ config ['Disk' ] = disk_config
9282
9383 with open (ConfigManager .get_config_path (profile_name ), 'w' ) as configfile :
9484 config .write (configfile )
9585
9686 @staticmethod
9787 def load_config (cpu_widgets , gpu_widgets , kernel_widgets , disk_widgets , profile_name = "Default" ):
9888 """
99- Load settings from configuration file and apply to widgets .
89+ Load configuration settings from a profile file .
10090 """
10191 config = configparser .ConfigParser ()
10292 config_path = ConfigManager .get_config_path (profile_name )
@@ -107,52 +97,42 @@ def load_config(cpu_widgets, gpu_widgets, kernel_widgets, disk_widgets, profile_
10797 config .read (config_path )
10898
10999 if 'CPU' in config :
110- cpu_widgets ['gov_combo' ].setCurrentText (config ['CPU' ].get ('governor' , 'unset' ))
111- cpu_widgets ['max_freq_combo' ].setCurrentText (config ['CPU' ].get ('max_freq' , 'unset' ))
112- cpu_widgets ['min_freq_combo' ].setCurrentText (config ['CPU' ].get ('min_freq' , 'unset' ))
113- cpu_widgets ['sched_combo' ].setCurrentText (config ['CPU' ].get ('scheduler' , 'unset' ))
114-
115- if 'Mesa' in config and 'mesa' in gpu_widgets :
116- for widget_key , value in config ['Mesa' ].items ():
117- if widget_key in gpu_widgets ['mesa' ] and hasattr (gpu_widgets ['mesa' ][widget_key ], 'setCurrentText' ):
118- gpu_widgets ['mesa' ][widget_key ].setCurrentText (value )
119-
120- if 'NVIDIA' in config and 'nvidia' in gpu_widgets :
121- for widget_key , value in config ['NVIDIA' ].items ():
122- if widget_key in gpu_widgets ['nvidia' ] and hasattr (gpu_widgets ['nvidia' ][widget_key ], 'setCurrentText' ):
123- gpu_widgets ['nvidia' ][widget_key ].setCurrentText (value )
124-
125- if 'RenderSelector' in config and 'render_selector' in gpu_widgets :
126- for widget_key , value in config ['RenderSelector' ].items ():
127- if widget_key in gpu_widgets ['render_selector' ] and hasattr (gpu_widgets ['render_selector' ][widget_key ], 'setCurrentText' ):
128- gpu_widgets ['render_selector' ][widget_key ].setCurrentText (value )
129-
130- if 'RenderPipeline' in config and 'render_pipeline' in gpu_widgets :
131- for widget_key , value in config ['RenderPipeline' ].items ():
132- if widget_key in gpu_widgets ['render_pipeline' ] and hasattr (gpu_widgets ['render_pipeline' ][widget_key ], 'setCurrentText' ):
133- gpu_widgets ['render_pipeline' ][widget_key ].setCurrentText (value )
100+ for setting_key in CPUManager .CPU_SETTINGS .keys ():
101+ if setting_key in config ['CPU' ] and setting_key in cpu_widgets :
102+ cpu_widgets [setting_key ].setCurrentText (config ['CPU' ][setting_key ])
103+
104+ if 'GPU' in config :
105+ for setting_key in GPULaunchManager .GPU_SETTINGS .keys ():
106+ if setting_key in config ['GPU' ]:
107+ for category_name , category_widgets in gpu_widgets .items ():
108+ if category_name != 'LaunchOptions' and setting_key in category_widgets :
109+ category_widgets [setting_key ].setCurrentText (config ['GPU' ][setting_key ])
110+ break
134111
135- if 'LaunchOptions' in config and 'launch_options ' in gpu_widgets and 'launch_options_input' in gpu_widgets ['launch_options ' ]:
112+ if 'LaunchOptions' in config and 'LaunchOptions ' in gpu_widgets and 'launch_options_input' in gpu_widgets ['LaunchOptions ' ]:
136113 launch_options = config ['LaunchOptions' ].get ('launch_options' , '' ).replace ('%%' , '%' )
137- gpu_widgets ['launch_options ' ]['launch_options_input' ].setText (launch_options )
114+ gpu_widgets ['LaunchOptions ' ]['launch_options_input' ].setText (launch_options )
138115
139116 if kernel_widgets and 'Kernel' in config :
140- for setting_name , value in config ['Kernel' ].items ():
141- if setting_name in KernelManager .KERNEL_SETTINGS :
142- input_widget = kernel_widgets [f'{ setting_name } _input' ]
143- input_widget .setText (value )
144-
145- if disk_widgets and 'disk_combos' in disk_widgets and 'Disk' in config :
146- for disk_name , scheduler in config ['Disk' ].items ():
147- if disk_name in disk_widgets ['disk_combos' ]:
148- disk_widgets ['disk_combos' ][disk_name ].setCurrentText (scheduler )
117+ for setting_key in KernelManager .KERNEL_SETTINGS .keys ():
118+ if setting_key in config ['Kernel' ]:
119+ widget_key = f'{ setting_key } _input'
120+ if widget_key in kernel_widgets :
121+ kernel_widgets [widget_key ].setText (config ['Kernel' ][setting_key ])
122+
123+ if disk_widgets and 'disk_settings' in disk_widgets and 'Disk' in config :
124+ for config_key , value in config ['Disk' ].items ():
125+ if '_' in config_key :
126+ disk_name , setting_key = config_key .rsplit ('_' , 1 )
127+ if disk_name in disk_widgets ['disk_settings' ] and setting_key in disk_widgets ['disk_settings' ][disk_name ]:
128+ disk_widgets ['disk_settings' ][disk_name ][setting_key ].setCurrentText (value )
149129
150130 return True
151131
152132 @staticmethod
153133 def delete_profile (profile_name ):
154134 """
155- Delete a profile configuration file .
135+ Delete a configuration profile. Cannot delete the Default profile .
156136 """
157137 if profile_name == "Default" :
158138 return False
@@ -162,85 +142,4 @@ def delete_profile(profile_name):
162142 config_path .unlink ()
163143 return True
164144
165- return False
166-
167- @staticmethod
168- def save_current_profile_preference (profile_name ):
169- """
170- Save the currently selected profile as the last used profile.
171- """
172- config_dir = Path (os .path .expanduser ("~/.config/volt-gui" ))
173- config_dir .mkdir (parents = True , exist_ok = True )
174-
175- config_path = config_dir / "volt-session.ini"
176- config = configparser .ConfigParser ()
177-
178- if config_path .exists ():
179- try :
180- config .read (config_path )
181- except :
182- pass
183-
184- if not config .has_section ('Session' ):
185- config .add_section ('Session' )
186-
187- config .set ('Session' , 'last_profile' , profile_name )
188-
189- try :
190- with open (config_path , 'w' ) as configfile :
191- config .write (configfile )
192- except Exception as e :
193- print (f"Warning: Failed to save session config: { e } " )
194-
195- @staticmethod
196- def load_current_profile_preference ():
197- """
198- Load the last used profile from session config.
199- """
200- config_path = Path (os .path .expanduser ("~/.config/volt-gui/volt-session.ini" ))
201-
202- if not config_path .exists ():
203- return "Default"
204-
205- config = configparser .ConfigParser ()
206- try :
207- config .read (config_path )
208- if config .has_section ('Session' ) and config .has_option ('Session' , 'last_profile' ):
209- last_profile = config .get ('Session' , 'last_profile' )
210- available_profiles = ConfigManager .get_available_profiles ()
211- if last_profile in available_profiles :
212- return last_profile
213- except Exception as e :
214- print (f"Warning: Failed to load session config: { e } " )
215-
216- return "Default"
217-
218- @staticmethod
219- def load_options_settings ():
220- """
221- Load options settings from configuration file.
222- """
223- options_path = Path (os .path .expanduser ("~/.config/volt-gui/volt-options.ini" ))
224- use_system_tray = True
225- start_minimized = False
226-
227- if not options_path .exists ():
228- return use_system_tray , start_minimized
229-
230- config = configparser .ConfigParser ()
231- try :
232- config .read (options_path )
233-
234- if 'SystemTray' in config and 'run_in_tray' in config ['SystemTray' ]:
235- use_system_tray = config ['SystemTray' ]['run_in_tray' ] == 'enable'
236-
237- if 'StartupBehavior' in config and 'start_minimized' in config ['StartupBehavior' ]:
238- if use_system_tray :
239- start_minimized = config ['StartupBehavior' ].get ('start_minimized' , 'disable' ) == 'enable'
240- else :
241- start_minimized = False
242-
243- except Exception as e :
244- print (f"Warning: Failed to load options settings: { e } " )
245-
246- return use_system_tray , start_minimized
145+ return False
0 commit comments