mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-11 00:37:50 -06:00
Add an AutoSave plugin that autosaves preferences, instances and profiles
Currently using a 1 minute timer, so we do not constantly trigger a save when editing profiles. Contributes to CURA-511
This commit is contained in:
parent
0887eeb075
commit
b8cf51349c
2 changed files with 98 additions and 0 deletions
77
plugins/AutoSave/AutoSave.py
Normal file
77
plugins/AutoSave/AutoSave.py
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
# Copyright (c) 2016 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
|
from PyQt5.QtCore import QTimer
|
||||||
|
|
||||||
|
from UM.Extension import Extension
|
||||||
|
from UM.Preferences import Preferences
|
||||||
|
from UM.Application import Application
|
||||||
|
from UM.Resources import Resources
|
||||||
|
from UM.Logger import Logger
|
||||||
|
|
||||||
|
class AutoSave(Extension):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
Preferences.getInstance().preferenceChanged.connect(self._onPreferenceChanged)
|
||||||
|
|
||||||
|
machine_manager = Application.getInstance().getMachineManager()
|
||||||
|
|
||||||
|
self._profile = None
|
||||||
|
machine_manager.activeProfileChanged.connect(self._onActiveProfileChanged)
|
||||||
|
machine_manager.profileNameChanged.connect(self._onProfilesChanged)
|
||||||
|
machine_manager.profilesChanged.connect(self._onProfilesChanged)
|
||||||
|
machine_manager.machineInstanceNameChanged.connect(self._onInstancesChanged)
|
||||||
|
machine_manager.machineInstancesChanged.connect(self._onInstancesChanged)
|
||||||
|
Application
|
||||||
|
self._onActiveProfileChanged()
|
||||||
|
|
||||||
|
self._change_timer = QTimer()
|
||||||
|
self._change_timer.setInterval(1000 * 60)
|
||||||
|
self._change_timer.setSingleShot(True)
|
||||||
|
self._change_timer.timeout.connect(self._onTimeout)
|
||||||
|
|
||||||
|
self._save_preferences = False
|
||||||
|
self._save_profiles = False
|
||||||
|
self._save_instances = False
|
||||||
|
|
||||||
|
def _onPreferenceChanged(self, preference):
|
||||||
|
self._save_preferences = True
|
||||||
|
self._change_timer.start()
|
||||||
|
|
||||||
|
def _onSettingValueChanged(self, setting):
|
||||||
|
self._save_profiles = True
|
||||||
|
self._change_timer.start()
|
||||||
|
|
||||||
|
def _onActiveProfileChanged(self):
|
||||||
|
if self._profile:
|
||||||
|
self._profile.settingValueChanged.disconnect(self._onSettingValueChanged)
|
||||||
|
|
||||||
|
self._profile = Application.getInstance().getMachineManager().getActiveProfile()
|
||||||
|
|
||||||
|
if self._profile:
|
||||||
|
self._profile.settingValueChanged.connect(self._onSettingValueChanged)
|
||||||
|
|
||||||
|
def _onProfilesChanged(self):
|
||||||
|
self._save_profiles = True
|
||||||
|
self._change_timer.start()
|
||||||
|
|
||||||
|
def _onInstancesChanged(self):
|
||||||
|
self._save_instances = True
|
||||||
|
self._change_timer.start()
|
||||||
|
|
||||||
|
def _onTimeout(self):
|
||||||
|
Logger.log("d", "Autosaving preferences, instances and profiles")
|
||||||
|
|
||||||
|
if self._save_preferences:
|
||||||
|
Preferences.getInstance().writeToFile(Resources.getStoragePath(Resources.Preferences, Application.getInstance().getApplicationName() + ".cfg"))
|
||||||
|
|
||||||
|
if self._save_instances:
|
||||||
|
Application.getInstance().getMachineManager().saveMachineInstances()
|
||||||
|
|
||||||
|
if self._save_profiles:
|
||||||
|
Application.getInstance().getMachineManager().saveProfiles()
|
||||||
|
|
||||||
|
self._save_preferences = False
|
||||||
|
self._save_instances = False
|
||||||
|
self._save_profiles = False
|
21
plugins/AutoSave/__init__.py
Normal file
21
plugins/AutoSave/__init__.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Copyright (c) 2016 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
|
from . import AutoSave
|
||||||
|
|
||||||
|
from UM.i18n import i18nCatalog
|
||||||
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
def getMetaData():
|
||||||
|
return {
|
||||||
|
"plugin": {
|
||||||
|
"name": catalog.i18nc("@label", "Auto Save"),
|
||||||
|
"author": "Ultimaker",
|
||||||
|
"version": "1.0",
|
||||||
|
"description": catalog.i18nc("@info:whatsthis", "Automatically saves Preferences, Machines and Profiles after changes."),
|
||||||
|
"api": 2
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
def register(app):
|
||||||
|
return { "extension": AutoSave.AutoSave() }
|
Loading…
Add table
Add a link
Reference in a new issue