コード例 #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
ファイル: options.py プロジェクト: PyCManager/pida
 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
ファイル: test_json.py プロジェクト: xmonader/pida
def test_load_fallback(tmpfile):
    ret = json.load(tmpfile, fallback=1)
    assert ret == 1
コード例 #6
0
ファイル: test_json.py プロジェクト: xmonader/pida
def test_load_valid(tmpfile):

    test_dump(tmpfile)
    assert json.load(tmpfile) == {'name': 1}
コード例 #7
0
ファイル: test_json.py プロジェクト: xmonader/pida
def test_load_missing(tmpfile):
    with pytest.raises(py.error.ENOENT):
        json.load(tmpfile)
コード例 #8
0
ファイル: test_json.py プロジェクト: xmonader/pida
def test_load_invalid(tmpfile):
    tmpfile.write('{ invalid')

    with py.test.raises(ValueError):
        json.load(tmpfile)
コード例 #9
0
ファイル: test_json.py プロジェクト: fermat618/pida
def test_load_fallback(tmpfile):
    ret = json.load(tmpfile, fallback=1)
    assert ret==1
コード例 #10
0
ファイル: test_json.py プロジェクト: fermat618/pida
def test_load_valid(tmpfile):

    test_dump(tmpfile)
    assert json.load(tmpfile) == {'name': 1}
コード例 #11
0
ファイル: test_json.py プロジェクト: fermat618/pida
def test_load_missing(tmpfile):
    with pytest.raises(py.error.ENOENT):
        json.load(tmpfile)
コード例 #12
0
ファイル: test_json.py プロジェクト: fermat618/pida
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
ファイル: options.py プロジェクト: PyCManager/pida
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={})