def read(self): data = {} for d in (settings_dir, workspace_dir): try: data.update(json.load(d()/self.name)) except ValueError, e: self.svc.log.error(_('Settings file corrupted: {file}'), file=d()) except py.error.ENOENT: pass
def read(self): data = {} for d in (settings_dir, workspace_dir): try: data.update(json.load(d()/self.name)) except ValueError as e: self.svc.log.error(_('Settings file corrupted: {file}'), file=d()) except py.error.ENOENT: pass except Exception as e: self.svc.log.exception(e) return data
def restore_state(self, pre=False): try: data = json.load(self.state_config) except: self.log.warning("Can't open window state file {config}", config=self.state_config) return if pre: # in pre mode we restore the paned config and the window position/size, etc self.boss.window.paned.set_config(data.get('panedstate', '')) # restore window size and position if data.has_key('pida_main_window'): cdata = data['pida_main_window'] # test if data is valid. we don't place the window where it # is not fully visible try: height = max(int(cdata['height']), 100) width = max(int(cdata['width']), 100) x = max(int(cdata['x']), 0) y = max(int(cdata['y']), 0) if x + width <= gtk.gdk.screen_width() and \ y + height <= gtk.gdk.screen_height(): self.boss.window.resize(width, height) self.boss.window.move(x, y) else: self.log.debug( "Won't restore window size outside screen") except (ValueError, KeyError): pass return for service in self.boss.get_services(): name = service.get_name() info = data.get(name, {}) if not info: continue for action in service.actions.list_actions(): if isinstance(action, TYPE_REMEMBER_TOGGLE): if action.get_name() in info: action.set_active(data[name][action.get_name()])
def restore_state(self, pre=False): try: data = json.load(self.state_config) except: self.log.warning("Can't open window state file {config}", config=self.state_config) return if pre: # in pre mode we restore the paned config and the window position/size, etc self.boss.window.paned.set_config(data.get('panedstate', '')) # restore window size and position if data.has_key('pida_main_window'): cdata = data['pida_main_window'] # test if data is valid. we don't place the window where it # is not fully visible try: height = max(int(cdata['height']), 100) width = max(int(cdata['width']), 100) x = max(int(cdata['x']), 0) y = max(int(cdata['y']), 0) if x + width <= gtk.gdk.screen_width() and \ y + height <= gtk.gdk.screen_height(): self.boss.window.resize(width, height) self.boss.window.move(x, y) else: self.log.debug("Won't restore window size outside screen") except (ValueError, KeyError): pass return for service in self.boss.get_services(): name = service.get_name() info = data.get(name, {}) if not info: continue for action in service.actions.list_actions(): if isinstance(action, TYPE_REMEMBER_TOGGLE): if action.get_name() in info: action.set_active(data[name][action.get_name()])
def test_load_fallback(tmpfile): ret = json.load(tmpfile, fallback=1) assert ret == 1
def test_load_valid(tmpfile): test_dump(tmpfile) assert json.load(tmpfile) == {'name': 1}
def test_load_missing(tmpfile): with pytest.raises(py.error.ENOENT): json.load(tmpfile)
def test_load_invalid(tmpfile): tmpfile.write('{ invalid') with py.test.raises(ValueError): json.load(tmpfile)
def test_load_fallback(tmpfile): ret = json.load(tmpfile, fallback=1) assert ret==1
def must_open_workspace_manager(): data = json.load(settings_dir()/'appcontroller.json', fallback={}) return bool(data.get('open_workspace_manager', False))
def load_window_config(): return json.load(window_config(), fallback={})
def load_prio(): return json.load(prio_path(), fallback={})