def remove_var(self, variable, skip_update=False, skip_undo=False): """Remove the variable entry from the internal lists.""" variable = self._get_proper_variable(variable) namespace = variable.metadata.get('full_ns') var_id = variable.metadata['id'] sect, opt = self.__util.get_section_option_from_id(var_id) config_name = self.__util.split_full_ns(self.__data, namespace)[0] config_data = self.__data.config[config_name] variables = config_data.vars.now.get(sect, []) latent_variables = config_data.vars.latent.get(sect, []) if variable in latent_variables: latent_variables.remove(variable) if not config_data.vars.latent[sect]: config_data.vars.latent.pop(sect) return None if variable in variables: variables.remove(variable) if not config_data.vars.now[sect]: config_data.vars.now.pop(sect) if variable.name: config_data.vars.latent.setdefault(sect, []) config_data.vars.latent[sect].append(variable) if not skip_undo: copy_var = variable.copy() self.__undo_stack.append( rose.config_editor.stack.StackItem( variable.metadata['full_ns'], rose.config_editor.STACK_ACTION_REMOVED, copy_var, self.add_var, [copy_var, skip_update])) del self.__redo_stack[:] if not skip_update: self.trigger_update(variable.metadata['full_ns']) return variable.metadata['full_ns']
def set_var_ignored(self, variable, new_reason_dict=None, override=False, skip_update=False, skip_undo=False): """Set the ignored flag data for the variable. new_reason_dict replaces the variable.ignored_reason attribute, except for the rose.variable.IGNORED_BY_SECTION key. """ if new_reason_dict is None: new_reason_dict = {} variable = self._get_proper_variable(variable) old_reason = variable.ignored_reason.copy() if rose.variable.IGNORED_BY_SECTION in old_reason: new_reason_dict.setdefault( rose.variable.IGNORED_BY_SECTION, old_reason[rose.variable.IGNORED_BY_SECTION]) if rose.variable.IGNORED_BY_SECTION not in old_reason: if rose.variable.IGNORED_BY_SECTION in new_reason_dict: new_reason_dict.pop(rose.variable.IGNORED_BY_SECTION) variable.ignored_reason = new_reason_dict.copy() if not set(old_reason.keys()) ^ set(new_reason_dict.keys()): # No practical difference, so don't do anything. return None # Protect against user-enabling of triggered ignored. if (not override and rose.variable.IGNORED_BY_SYSTEM in old_reason and rose.variable.IGNORED_BY_SYSTEM not in new_reason_dict): if rose.config_editor.WARNING_TYPE_NOT_TRIGGER in variable.error: variable.error.pop(rose.config_editor.WARNING_TYPE_NOT_TRIGGER) my_ignored_keys = variable.ignored_reason.keys() if rose.variable.IGNORED_BY_SECTION in my_ignored_keys: my_ignored_keys.remove(rose.variable.IGNORED_BY_SECTION) old_ignored_keys = old_reason.keys() if rose.variable.IGNORED_BY_SECTION in old_ignored_keys: old_ignored_keys.remove(rose.variable.IGNORED_BY_SECTION) if len(my_ignored_keys) > len(old_ignored_keys): action_text = rose.config_editor.STACK_ACTION_IGNORED if (not old_ignored_keys and rose.config_editor.WARNING_TYPE_ENABLED in variable.error): variable.error.pop(rose.config_editor.WARNING_TYPE_ENABLED) else: action_text = rose.config_editor.STACK_ACTION_ENABLED if not my_ignored_keys: for err_type in rose.config_editor.WARNING_TYPES_IGNORE: if err_type in variable.error: variable.error.pop(err_type) if not skip_undo: copy_var = variable.copy() self.__undo_stack.append( rose.config_editor.stack.StackItem( variable.metadata['full_ns'], action_text, copy_var, self.set_var_ignored, [copy_var, old_reason, True])) del self.__redo_stack[:] self.trigger_ignored_update(variable) if not skip_update: self.trigger_update(variable.metadata['full_ns']) return variable.metadata['full_ns']
def remove_var(self, variable, skip_update=False, skip_undo=False): """Remove the variable entry from the internal lists.""" variable = self._get_proper_variable(variable) variable.error = {} # Kill any metadata errors before removing. namespace = variable.metadata.get('full_ns') var_id = variable.metadata['id'] sect = self.__util.get_section_option_from_id(var_id)[0] config_name = self.__util.split_full_ns(self.__data, namespace)[0] config_data = self.__data.config[config_name] variables = config_data.vars.now.get(sect, []) latent_variables = config_data.vars.latent.get(sect, []) if variable in latent_variables: latent_variables.remove(variable) if not config_data.vars.latent[sect]: config_data.vars.latent.pop(sect) return None if variable in variables: variables.remove(variable) if not config_data.vars.now[sect]: config_data.vars.now.pop(sect) if variable.name: config_data.vars.latent.setdefault(sect, []) config_data.vars.latent[sect].append(variable) if not skip_undo: copy_var = variable.copy() self.__undo_stack.append( rose.config_editor.stack.StackItem( variable.metadata['full_ns'], rose.config_editor.STACK_ACTION_REMOVED, copy_var, self.add_var, [copy_var, skip_update])) del self.__redo_stack[:] if not skip_update: self.trigger_update(variable.metadata['full_ns']) return variable.metadata['full_ns']
def add_var(self, variable, skip_update=False, skip_undo=False): """Add a variable to the internal list.""" existing_variable = self._get_proper_variable(variable) namespace = variable.metadata.get('full_ns') var_id = variable.metadata['id'] sect, opt = self.__util.get_section_option_from_id(var_id) config_name = self.__util.split_full_ns(self.__data, namespace)[0] config_data = self.__data.config[config_name] old_metadata = copy.deepcopy(variable.metadata) flags = self.__data.load_option_flags(config_name, sect, opt) variable.flags.update(flags) metadata = self.__data.helper.get_metadata_for_config_id(var_id, config_name) variable.process_metadata(metadata) variable.metadata.update(old_metadata) variables = config_data.vars.now.get(sect, []) copy_var = variable.copy() v_id = variable.metadata.get('id') if v_id in [v.metadata.get('id') for v in variables]: # This is the case of adding a blank variable and # renaming it to an existing variable's name. # At the moment, assume this should just be skipped. pass else: group = None if sect not in config_data.sections.now: start_stack_index = len(self.__undo_stack) group = (rose.config_editor.STACK_GROUP_ADD + "-" + str(time.time())) self.__add_section_func(config_name, sect) for item in self.__undo_stack[start_stack_index:]: item.group = group latent_variables = config_data.vars.latent.get(sect, []) for latent_var in list(latent_variables): if latent_var.metadata["id"] == v_id: latent_variables.remove(latent_var) config_data.vars.now.setdefault(sect, []) config_data.vars.now[sect].append(variable) if not skip_undo: self.__undo_stack.append( rose.config_editor.stack.StackItem( variable.metadata['full_ns'], rose.config_editor.STACK_ACTION_ADDED, copy_var, self.remove_var, [copy_var, skip_update], group=group) ) del self.__redo_stack[:] if not skip_update: self.trigger_update(variable.metadata['full_ns']) return variable.metadata['full_ns']
def set_var_comments(self, variable, comments, skip_update=False, skip_undo=False): """Set the comments field for the variable.""" variable = self._get_proper_variable(variable) copy_variable = variable.copy() old_comments = copy_variable.comments variable.comments = comments if not skip_undo: self.__undo_stack.append( rose.config_editor.stack.StackItem( variable.metadata['full_ns'], rose.config_editor.STACK_ACTION_CHANGED_COMMENTS, copy_variable, self.set_var_comments, [copy_variable, old_comments]) ) del self.__redo_stack[:] if not skip_update: self.trigger_update(variable.metadata['full_ns']) return variable.metadata['full_ns']
def set_var_value(self, variable, new_value, skip_update=False, skip_undo=False): """Set the value of the variable.""" variable = self._get_proper_variable(variable) if variable.value == new_value: # A bad valuewidget setter. return None variable.old_value = variable.value variable.value = new_value if not skip_undo: copy_var = variable.copy() self.__undo_stack.append( rose.config_editor.stack.StackItem( variable.metadata['full_ns'], rose.config_editor.STACK_ACTION_CHANGED, copy_var, self.set_var_value, [copy_var, copy_var.old_value]) ) del self.__redo_stack[:] if not skip_update: self.trigger_update(variable.metadata['full_ns']) return variable.metadata['full_ns']
def set_var_ignored(self, variable, new_reason_dict=None, override=False, skip_update=False, skip_undo=False): """Set the ignored flag data for the variable. new_reason_dict replaces the variable.ignored_reason attribute, except for the rose.variable.IGNORED_BY_SECTION key. """ if new_reason_dict is None: new_reason_dict = {} variable = self._get_proper_variable(variable) old_reason = variable.ignored_reason.copy() if rose.variable.IGNORED_BY_SECTION in old_reason: new_reason_dict.setdefault( rose.variable.IGNORED_BY_SECTION, old_reason[rose.variable.IGNORED_BY_SECTION]) if rose.variable.IGNORED_BY_SECTION not in old_reason: if rose.variable.IGNORED_BY_SECTION in new_reason_dict: new_reason_dict.pop(rose.variable.IGNORED_BY_SECTION) variable.ignored_reason = new_reason_dict.copy() if not set(old_reason.keys()) ^ set(new_reason_dict.keys()): # No practical difference, so don't do anything. return None # Protect against user-enabling of triggered ignored. if (not override and rose.variable.IGNORED_BY_SYSTEM in old_reason and rose.variable.IGNORED_BY_SYSTEM not in new_reason_dict): if rose.config_editor.WARNING_TYPE_NOT_TRIGGER in variable.error: variable.error.pop( rose.config_editor.WARNING_TYPE_NOT_TRIGGER) my_ignored_keys = variable.ignored_reason.keys() if rose.variable.IGNORED_BY_SECTION in my_ignored_keys: my_ignored_keys.remove(rose.variable.IGNORED_BY_SECTION) old_ignored_keys = old_reason.keys() if rose.variable.IGNORED_BY_SECTION in old_ignored_keys: old_ignored_keys.remove(rose.variable.IGNORED_BY_SECTION) if len(my_ignored_keys) > len(old_ignored_keys): action_text = rose.config_editor.STACK_ACTION_IGNORED if (not old_ignored_keys and rose.config_editor.WARNING_TYPE_ENABLED in variable.error): variable.error.pop(rose.config_editor.WARNING_TYPE_ENABLED) else: action_text = rose.config_editor.STACK_ACTION_ENABLED if not my_ignored_keys: for err_type in rose.config_editor.WARNING_TYPES_IGNORE: if err_type in variable.error: variable.error.pop(err_type) if not skip_undo: copy_var = variable.copy() self.__undo_stack.append( rose.config_editor.stack.StackItem( variable.metadata['full_ns'], action_text, copy_var, self.set_var_ignored, [copy_var, old_reason, True]) ) del self.__redo_stack[:] self.trigger_ignored_update(variable) if not skip_update: self.trigger_update(variable.metadata['full_ns']) return variable.metadata['full_ns']