-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
executable file
·87 lines (73 loc) · 2.24 KB
/
settings.py
File metadata and controls
executable file
·87 lines (73 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
import os, time, json, dbus
from settings_utils import audio, network, wallpaper
from pyvdm.interface import CapabilityLibrary, SRC_API
DBG = 1
class DesktopSettings(SRC_API):
def _probe_environment(self):
def _probe(module):
for _candidate in module.__all__:
_class = getattr(module, _candidate)
if _class.exists():
return _class()
return None
##
self.settings = {
'audio' : _probe(audio),
'network' : _probe(network),
'wallpaper': _probe(wallpaper),
}
pass
def _gather_records(self):
return {
key:_settings.get_all_status()
for key,_settings in self.settings.items()
if _settings is not None
}
def _resume_status(self, records):
for name,status in records.items():
if name in self.settings and self.settings[name] is not None:
self.settings[name].set_all_status(status)
pass
def onStart(self):
self._probe_environment()
self._init_records = self._gather_records()
return 0
def onStop(self):
return 0
def onSave(self, stat_file):
## gathering records
records = self._gather_records()
## write to file
with open(stat_file, 'w') as f:
json.dump(records, f)
return 0
def onResume(self, stat_file, new):
## load stat file with failure check
with open(stat_file, 'r') as f:
_file = f.read().strip()
if len(_file)==0:
return 0
else:
try:
records = json.loads(_file)
except:
return -1
## resume settings from records
self._resume_status(records)
return 0
def onClose(self):
self._resume_status( self._init_records )
return 0
pass
if __name__ == '__main__':
_plugin = DesktopSettings()
_plugin.onStart()
## gathering record
records = _plugin._gather_records()
print( json.dumps(records, indent=4) )
_plugin.onClose()
## test resume
time.sleep( 2.0 )
_plugin._resume_status(records)
pass