def update_path(self): """Update the path label based on current values""" values = self.values.copy() tags = {} tags['type'] = values['ctype'] if values['groups']: tags['group'] = values.pop('groups') tags.update({k: v for (k, v) in values.items() if v}) temp_char = Character() temp_char.merge_all({**self.prefs.get('tag_defaults'), **tags}) template_path = self.prefs.get('types.{}.sheet_template'.format( temp_char.type_key)) char_name = values['name'] if char_name: filename = char_name + path.splitext(template_path)[1] else: filename = '' base_path = create_path_from_character(temp_char, prefs=self.prefs) final_path = path.join(base_path, filename) path_exists = path.exists(final_path) if path_exists: self.buttonBox.button( QtWidgets.QDialogButtonBox.Ok).setEnabled(False) else: self.buttonBox.button( QtWidgets.QDialogButtonBox.Ok).setEnabled(True) if path_exists and char_name: self.path_dislpay.setText("Character already exists") else: self.path_dislpay.setText(final_path)
def _minimal_character(ctype: str, groups, dead, foreign, location, prefs): """ Create a minimal character object Args: ctype (str): Character type groups (list): One or more names of groups the character belongs to. dead (bool|str): Whether to add the @dead tag. Pass False to exclude it (the default), an empty string to inlcude it with no details given, and a non-empty string to include the tag along with the contents of the argument. foreign (bool|str): Details of non-standard residence. Leave empty to exclude the @foreign tag. location (str): Details about where the character lives. Leave empty to exclude the @location tag. prefs (Settings): Settings object Returns: Character object """ temp_char = Character() tags = {} tags['description'] = prefs.get('character_header') tags['type'] = ctype.title() if groups: tags['group'] = groups if dead is not False: tags['dead'] = dead if foreign is not False: tags['foreign'] = foreign if location is not False: tags['location'] = location temp_char.merge_all({**prefs.get('tag_defaults'), **tags}) return temp_char