Пример #1
0
    def save(self):
        configuration = Configuration()
        preferences = configuration.get("preferences")
        preferences["theme-light"] = self.theme_light.get_active()
        preferences["todos"] = int(self.todos.get_value())
        preferences["todo-file"] = self.todo_file.get_file().get_path()
        preferences["projects"] = self.projects.get_items()
        preferences["contexts"] = self.contexts.get_items()
        preferences["tags"] = self.tags.get_items()
        preferences["hide-completed"] = self.hide_completed.get_active()
        preferences["filter-projects"] = self.filter_projects.get_active()
        preferences["filter-contexts"] = self.filter_contexts.get_active()
        preferences["show-hidden-tags"] = self.show_hidden_tags.get_active()
        preferences["keybindings"] = [
            {
                "name": "new_task",
                "keybind": self.new_task_keybinding.get_text(),
            },
            {
                "name": "show_tasks",
                "keybind": self.show_tasks_keybinding.get_text(),
            },
        ]
        configuration.set("preferences", preferences)
        configuration.save()
        autostart_file = "todotxt-indicator-autostart.desktop"
        autostart_file = os.path.join(os.getenv("HOME"), ".config/autostart",
                                      autostart_file)
        if self.autostart.get_active():
            if not os.path.exists(os.path.dirname(autostart_file)):
                os.makedirs(os.path.dirname(autostart_file))
            shutil.copyfile(config.AUTOSTART, autostart_file)
        else:
            if os.path.exists(autostart_file):
                os.remove(autostart_file)

        for plugin in self.plugins.get_items():
            try:
                if plugin["installed"]:
                    shutil.move(
                        configuration.get_plugin_to_load_dir() + "/" +
                        plugin["name"],
                        configuration.get_plugin_dir(),
                    )
                else:
                    shutil.move(
                        configuration.get_plugin_dir() + "/" + plugin["name"],
                        configuration.get_plugin_to_load_dir(),
                    )
            except Exception as e:
                print("Ignore error. Maybe no operation needed. %s" % e)
Пример #2
0
    def save(self):
        configuration = Configuration()
        preferences = configuration.get('preferences')
        preferences['theme-light'] = self.theme_light.get_active()
        preferences['todos'] = int(self.todos.get_value())
        preferences['todo-file'] = self.todo_file.get_file().get_path()
        preferences['projects'] = self.projects.get_items()
        preferences['contexts'] = self.contexts.get_items()
        preferences['tags'] = self.tags.get_items()
        preferences['hide-completed'] = self.hide_completed.get_active()
        preferences['filter-projects'] = self.filter_projects.get_active()
        preferences['keybindings'] = [
            {
                'name': 'new_task',
                'keybind': self.new_task_keybinding.get_text()
            },
            {
                'name': 'show_tasks',
                'keybind': self.show_tasks_keybinding.get_text()
            },
        ]
        configuration.set('preferences', preferences)
        configuration.save()
        autostart_file = 'todotxt-indicator-autostart.desktop'
        autostart_file = os.path.join(os.getenv('HOME'), '.config/autostart',
                                      autostart_file)
        if self.autostart.get_active():
            if not os.path.exists(os.path.dirname(autostart_file)):
                os.makedirs(os.path.dirname(autostart_file))
            shutil.copyfile(config.AUTOSTART, autostart_file)
        else:
            if os.path.exists(autostart_file):
                os.remove(autostart_file)

        for plugin in self.plugins.get_items():
            try:
                if plugin['installed']:
                    shutil.move(
                        configuration.get_plugin_to_load_dir() + '/' +
                        plugin['name'], configuration.get_plugin_dir())
                else:
                    shutil.move(
                        configuration.get_plugin_dir() + '/' + plugin['name'],
                        configuration.get_plugin_to_load_dir())
            except Exception as e:
                print("Ignore error. Maybe no operation needed. %s" % e)