def __init__(self): filepath = Path(phy_config_dir()) / 'plugin_reordercolumns.json' # Default config dflts = { 'last_columns': ['quality', 'comment'], 'text_align': 'right', 'tight_columns': False, } # Create config file with defaults if it does not exist if not filepath.exists(): logger.debug("Create default config at %s.", filepath) with open(filepath, 'w', encoding='utf-8') as f: json.dump(dflts, f, ensure_ascii=False, indent=4) # Load config logger.debug("Load %s for config.", filepath) with open(filepath, 'r') as f: try: data = json.load(f) except json.decoder.JSONDecodeError as e: logger.warning("Error decoding JSON: %s", e) data = dflts self.last_columns = data.get('last_columns', dflts['last_columns']) self.text_align = data.get('text_align', dflts['text_align']) self.tight_columns = data.get('tight_columns', dflts['tight_columns'])
def download_test_file(name, config_dir=None, force=False): """Download a test file.""" config_dir = config_dir or phy_config_dir() path = op.join(config_dir, 'test_data', name) _ensure_dir_exists(op.dirname(path)) if not force and op.exists(path): return path url = _BASE_URL + name download_file(url, output_path=path) return path
def __init__(self): filepath = Path(phy_config_dir()) / 'plugin_writecomments.json' # Default config dflts = dict() dflts['delimiter'] = '_' # Comment delimiter dflts['pairs'] = { # Character-comment pairs 'a': 'axon', 'm': 'misaligned', 's': 'spontaneous', 'n': 'noisefloor', } # Create config file with defaults if it does not exist if not filepath.exists(): logger.debug("Create default config at %s.", filepath) with open(filepath, 'w', encoding='utf-8') as f: json.dump(dflts, f, ensure_ascii=False, indent=4) # Load config logger.debug("Load %s for config.", filepath) with open(filepath, 'r') as f: try: data = json.load(f) except json.decoder.JSONDecodeError as e: logger.warning("Error decoding JSON: %s", e) data = dflts self.delimiter = data.get('delimiter', dflts['delimiter']) self.pairs = data.get('pairs', dflts['pairs']) # Allow lower case keys only for k in self.pairs.keys(): if not k.islower(): self.pairs[k.lower()] = self.pairs[k] del self.pairs[k] self.pairs_inv = {v: k for k, v in self.pairs.items()} logger.debug("Available short hand notations are %s.", ', '.join(self.pairs.keys()))
def __init__(self, name='GUI', config_dir=None, **kwargs): super(GUIState, self).__init__(**kwargs) self.name = name self.config_dir = config_dir or phy_config_dir() _ensure_dir_exists(op.join(self.config_dir, self.name)) self.load()
def __init__(self, name='GUI', config_dir=None, **kwargs): super(GUIState, self).__init__(**kwargs) self.name = name self.config_dir = config_dir or phy_config_dir() _ensure_dir_exists(op.join(self.config_dir, self.name)) self.load()
def _gui_state_path(gui_name, config_dir=None): """Return the path to the GUI state, given the GUI name and the config dir.""" return Path(config_dir or phy_config_dir()) / gui_name / 'state.json'