Config system finally fixed

This commit is contained in:
Mathieu Comandon 2010-03-02 00:26:03 +01:00
parent 75161697c8
commit 50c43b4a6e
4 changed files with 36 additions and 18 deletions

View file

@ -226,7 +226,6 @@ class LutrisWindow(gtk.Window):
def add_game(self,widget,data=None):
add_game_dialog = AddGameDialog(self)
logging.debug("opening dialog")
game_info = add_game_dialog.game_info
logging.debug(game_info)

View file

@ -115,6 +115,9 @@ class AddGameDialog(gtk.Dialog):
#Get runner
self.lutris_config.config["realname"] = realname
self.lutris_config.config["runner"] = self.runner_class
logging.debug("saving")
logging.debug(self.lutris_config.config)
logging.debug(self.lutris_config.game_config)
if self.runner_class and realname:
game_identifier = self.lutris_config.save(type="game")

View file

@ -61,6 +61,8 @@ class LutrisConfig():
#Read system configuration
if os.path.exists(constants.system_config_full_path):
self.system_config = yaml.load(file(constants.system_config_full_path, 'r').read())
if self.system_config is None:
self.system_config = {}
else:
logging.debug("Creating new system config file")
file(constants.system_config_full_path,"w+")
@ -104,8 +106,12 @@ class LutrisConfig():
self.update_global_config()
def update_global_config(self):
self.config = copy.deepcopy(self.system_config)
for key in self.system_config.keys():
if key in self.config:
self.config[key].update(self.system_config[key])
else:
self.config[key] = self.system_config[key]
for key in self.runner_config.keys():
if key in self.config:
self.config[key].update(self.runner_config[key])
@ -126,11 +132,14 @@ class LutrisConfig():
"""Save configuration file
The way to save config files can be set by the type argument
or with self.config_type"""
self.update_global_config()
logging.debug("Saving config (type %s)" % type)
logging.debug(self.config)
if type is None:
type = self.config_type
yaml_config = yaml.dump(self.config,default_flow_style=False)
logging.debug("Saving config (type %s)" % type)
print yaml_config
if type == "system":
file(constants.system_config_full_path,"w").write(yaml_config)
elif type == "runner":
@ -149,6 +158,8 @@ class LutrisConfig():
def get_path(self,runner):
if self.config is None:
return os.path.expanduser("~")
if runner in self.config:
if "game_path" in self.config[runner]:
return self.config[runner]["game_path"]

View file

@ -36,18 +36,21 @@ class ConfigVBox(gtk.VBox):
def generate_widgets(self):
#Select what data to load based on caller.
logging.debug("Caller : %s" % self.caller)
logging.debug("Save in key : %s" % self.save_in_key)
if self.caller == "system":
lutris_config = self.lutris_config.system_config
self.real_config = self.lutris_config.system_config
elif self.caller == "runner":
lutris_config = self.lutris_config.runner_config
self.real_config = self.lutris_config.runner_config
elif self.caller == "game":
lutris_config = self.lutris_config.game_config
self.real_config = self.lutris_config.game_config
#Select part of config to load or create it.
if self.save_in_key in lutris_config:
config = lutris_config[self.save_in_key]
if self.save_in_key in self.real_config:
config = self.real_config[self.save_in_key]
else:
config = lutris_config[self.save_in_key] = {}
logging.debug("Creating key : %s" % self.save_in_key)
config = self.real_config[self.save_in_key] = {}
#Go thru all options.
for option in self.options:
@ -86,7 +89,7 @@ class ConfigVBox(gtk.VBox):
checkbox.show()
self.pack_start(checkbox,False,True,5)
def checkbox_toggle(self,widget,option_name):
self.lutris_config.config[self.save_in_key][option_name] = widget.get_active()
self.real_config[self.save_in_key][option_name] = widget.get_active()
#Entry
def generate_entry(self,option_name,label,value=None):
@ -103,7 +106,7 @@ class ConfigVBox(gtk.VBox):
self.pack_start(hbox,False,True,5)
def entry_changed(self,entry,option_name):
entry_text = entry.get_text()
self.lutris_config.config[self.save_in_key][option_name] = entry_text
self.real_config[self.save_in_key][option_name] = entry_text
#ComboBox
def generate_combobox(self,option_name,choices,label,value=None):
@ -137,7 +140,7 @@ class ConfigVBox(gtk.VBox):
if active < 0:
return None
option_value = model[active][1]
self.lutris_config.config[self.save_in_key][option] = option_value
self.real_config[self.save_in_key][option] = option_value
#Range
def generate_range(self,option_name,min,max,label,value=None):
@ -155,7 +158,7 @@ class ConfigVBox(gtk.VBox):
self.pack_start(hbox,False,True,5)
def on_spin_button_changed(self,spin_button,option):
value = spin_button.get_value_as_int()
self.lutris_config.config[self.save_in_key][option] = value
self.real_config[self.save_in_key][option] = value
#File chooser
@ -195,8 +198,10 @@ class ConfigVBox(gtk.VBox):
self.pack_start(hbox,False,True,5)
def on_chooser_file_set(self,filechooser_widget,option):
directory = filechooser_widget.get_filename()
self.lutris_config.config[self.save_in_key][option] = directory
filename = filechooser_widget.get_filename()
logging.debug(self.save_in_key)
logging.debug(self.lutris_config.config)
self.real_config[self.save_in_key][option] = filename
def generate_multiple_file_chooser(self,option_name,label,value=None):
hbox = gtk.HBox()
@ -252,5 +257,5 @@ class ConfigVBox(gtk.VBox):
self.files_list_store.append([filename])
if not filename in self.files:
self.files.append(filename)
self.lutris_config.config[self.save_in_key][option] = self.files
self.real_config[self.save_in_key][option] = self.files
self.files_chooser_dialog = None