示例#1
0
文件: options.py 项目: fermat618/pida
 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
示例#2
0
 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
示例#3
0
文件: window.py 项目: PyCManager/pida
    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()])
示例#4
0
文件: window.py 项目: fermat618/pida
    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()])
示例#5
0
def test_load_fallback(tmpfile):
    ret = json.load(tmpfile, fallback=1)
    assert ret == 1
示例#6
0
def test_load_valid(tmpfile):

    test_dump(tmpfile)
    assert json.load(tmpfile) == {'name': 1}
示例#7
0
def test_load_missing(tmpfile):
    with pytest.raises(py.error.ENOENT):
        json.load(tmpfile)
示例#8
0
def test_load_invalid(tmpfile):
    tmpfile.write('{ invalid')

    with py.test.raises(ValueError):
        json.load(tmpfile)
示例#9
0
def test_load_fallback(tmpfile):
    ret = json.load(tmpfile, fallback=1)
    assert ret==1
示例#10
0
def test_load_valid(tmpfile):

    test_dump(tmpfile)
    assert json.load(tmpfile) == {'name': 1}
示例#11
0
def test_load_missing(tmpfile):
    with pytest.raises(py.error.ENOENT):
        json.load(tmpfile)
示例#12
0
def test_load_invalid(tmpfile):
    tmpfile.write('{ invalid')

    with py.test.raises(ValueError):
        json.load(tmpfile)
示例#13
0
文件: options.py 项目: fermat618/pida
def must_open_workspace_manager():
    data = json.load(settings_dir()/'appcontroller.json', fallback={})
    return bool(data.get('open_workspace_manager', False))
示例#14
0
文件: window.py 项目: fermat618/pida
def load_window_config():
    return json.load(window_config(), fallback={})
示例#15
0
def must_open_workspace_manager():
    data = json.load(settings_dir()/'appcontroller.json', fallback={})
    return bool(data.get('open_workspace_manager', False))
示例#16
0
文件: window.py 项目: PyCManager/pida
def load_window_config():
    return json.load(window_config(), fallback={})
示例#17
0
文件: language.py 项目: xmonader/pida
def load_prio():
    return json.load(prio_path(), fallback={})