You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
819 B
30 lines
819 B
import json
|
|
import os
|
|
|
|
class PresetManager:
|
|
def __init__(self, filepath="presets.json"):
|
|
self.filepath = filepath
|
|
self.presets = self.load_presets()
|
|
|
|
def save_preset(self, name, layout_params_list):
|
|
"""保存预案到字典"""
|
|
self.presets[name] = {
|
|
"layouts": layout_params_list
|
|
}
|
|
self.save_to_file()
|
|
|
|
def get_preset(self, name):
|
|
"""获取预案"""
|
|
return self.presets.get(name)
|
|
|
|
def load_presets(self):
|
|
"""从文件加载"""
|
|
if os.path.exists(self.filepath):
|
|
with open(self.filepath, 'r') as f:
|
|
return json.load(f)
|
|
return {}
|
|
|
|
def save_to_file(self):
|
|
"""写入文件"""
|
|
with open(self.filepath, 'w') as f:
|
|
json.dump(self.presets, f, indent=4)
|