Exemple #1
0
 def _on_option_change(self, option):
     # hacky highjacking to put the options into a extra config :-)
     data = load_window_config()
     data[option.name] = option.value
     json.dump(data, window_config())
     # call normal callback
     self._set_action_keypress_from_option(option)
Exemple #2
0
 def save_state(self, *args):
     if not self.started:
         return
     data = {}
     data['panedstate'] = self.boss.window.paned.get_config()
     # save window size and position
     size = self.boss.window.get_size()
     pos = self.boss.window.get_position()
     data['pida_main_window'] = {
         "width": size[0],
         "height": size[1],
         "x": pos[0],
         "y": pos[1],
     }
     for service in self.boss.get_services():
         cur = {}
         if not hasattr(service, "actions"):
             continue
         for action in service.actions.list_actions():
             if isinstance(action, TYPE_REMEMBER_TOGGLE):
                 cur[action.get_name()] = action.props.active
         if cur:
             data[service.get_name()] = cur
     
     try:
         json.dump(data, self.state_config)
     except:
         self.log.warning("Can't open state file {config}",
                          config=self.state_config)
Exemple #3
0
 def _on_option_change(self, option):
     # hacky highjacking to put the options into a extra config :-)
     data = load_window_config()
     data[option.name] = option.value
     json.dump(data, window_config())
     # call normal callback
     self._set_action_keypress_from_option(option)
Exemple #4
0
    def save_state(self, *args):
        if not self.started:
            return
        data = {}
        data['panedstate'] = self.boss.window.paned.get_config()
        # save window size and position
        size = self.boss.window.get_size()
        pos = self.boss.window.get_position()
        data['pida_main_window'] = {
            "width": size[0],
            "height": size[1],
            "x": pos[0],
            "y": pos[1],
        }
        for service in self.boss.get_services():
            cur = {}
            if not hasattr(service, "actions"):
                continue
            for action in service.actions.list_actions():
                if isinstance(action, TYPE_REMEMBER_TOGGLE):
                    cur[action.get_name()] = action.props.active
            if cur:
                data[service.get_name()] = cur

        try:
            json.dump(data, self.state_config)
        except:
            self.log.warning("Can't open state file {config}",
                             config=self.state_config)
Exemple #5
0
    def set_priority_list(self, lang, type_, lst, save=True):
        """
        Sets a new priority list on a given language and type_
        
        @lang: internal language name
        @type_: LANGUAGE_PLUGIN_TYPES id
        """
        clist = self.features[type_].get_or_create(lang)
        if hasattr(clist, "set_sort_list"):
            clist.set_sort_list(lst)
        else:
            self.log.warning(
                _("Try to set a priority list on non priority sublist"))

        # save list in options
        pp = load_prio()
        if lst:
            if lang not in pp:
                pp[lang] = {}
            pp[lang][type_] = lst

        else:
            if lang not in pp:
                return
            if type_ not in pp[lang]:
                return
            del pp[lang][type_]
            if not pp[lang]:
                del pp[lang]
        if save:
            json.dump(pp, prio_path())
Exemple #6
0
    def dump(self, workspace):
        data = dict((opt.name, opt.value)
                    for opt in self if opt.workspace is workspace)
        if workspace:
            config_dir = workspace_dir
        else:
            config_dir = settings_dir

        json.dump(data, config_dir()/self.name)
Exemple #7
0
    def dump(self, workspace):
        data = dict((opt.name, opt.value)
                    for opt in self if opt.workspace is workspace)
        if workspace:
            config_dir = workspace_dir
        else:
            config_dir = settings_dir

        json.dump(data, config_dir()/self.name)
Exemple #8
0
def test_dump(tmpfile):
    json.dump({'name': 1}, tmpfile)
    assert tmpfile.read() == '{\n  "name": 1\n}'
Exemple #9
0
def test_dump(tmpfile):
    json.dump({'name':1}, tmpfile)
    assert tmpfile.read() == '{\n  "name": 1\n}'
Exemple #10
0
 def dump_data(self, path, data):
     try:
         json.dump(data, path)
     except Exception as e:
         self.svc.log.exception(e)
Exemple #11
0
 def dump_data(self, path, data):
     try:
         json.dump(data, path)
     except Exception, e:
         self.svc.log.exception(e)