forked from dbr/tabtabtab-nuke
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtabtabtab_prefs.py
More file actions
37 lines (26 loc) · 882 Bytes
/
tabtabtab_prefs.py
File metadata and controls
37 lines (26 loc) · 882 Bytes
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
import json
import os
PREFS_FILE = os.path.join(os.path.expanduser("~"), ".nuke", "tabtabtab_prefs.json")
DEFAULTS = {
"tabtabtab_enabled": True,
}
class TabtabtabPrefs:
def __init__(self, prefs_file=PREFS_FILE):
self._prefs_file = prefs_file
self._prefs = self._load()
def _load(self):
if os.path.exists(self._prefs_file):
with open(self._prefs_file, "r") as f:
loaded = json.load(f)
return {**DEFAULTS, **loaded}
return dict(DEFAULTS)
def get(self, key):
return self._prefs.get(key, DEFAULTS.get(key))
def set(self, key, value):
self._prefs[key] = value
def save(self):
with open(self._prefs_file, "w") as f:
json.dump(self._prefs, f, indent=2)
def reload(self):
self._prefs = self._load()
prefs_singleton = TabtabtabPrefs()