实现方案导入导出,根据选项自动生成文件名
This commit is contained in:
29
web/myweb.py
29
web/myweb.py
@@ -5,19 +5,30 @@ import json
|
||||
|
||||
|
||||
class Api:
|
||||
def button_click(self):
|
||||
print("button click.")
|
||||
path=os.path.split(os.path.abspath(sys.argv[0]))[0]
|
||||
print(path)
|
||||
result = wnd.create_file_dialog(dialog_type=wb.FOLDER_DIALOG,directory=path)
|
||||
print(result)
|
||||
return result[0] if result else ''
|
||||
|
||||
def save_plan(slef,plan:str):
|
||||
def __init__(self) -> None:
|
||||
self.path=os.path.split(os.path.abspath(sys.argv[0]))[0]
|
||||
|
||||
def load_plan(self):
|
||||
print("button click.")
|
||||
print(self.path)
|
||||
result = wnd.create_file_dialog(dialog_type=wb.OPEN_DIALOG,directory=self.path,
|
||||
file_types=('JSON (*.json)', 'All files (*.*)'))
|
||||
print(result)
|
||||
if(result is None):
|
||||
return None
|
||||
if(len(result)>0):
|
||||
with open(result[0],encoding="utf-8") as f:
|
||||
return json.loads(f.read())
|
||||
return None
|
||||
|
||||
def save_plan(slef,plan:dict):
|
||||
path=os.path.split(os.path.abspath(sys.argv[0]))[0]
|
||||
file_name=wnd.create_file_dialog(dialog_type=wb.SAVE_DIALOG,directory=path,save_filename="默认方案",
|
||||
file_name=wnd.create_file_dialog(dialog_type=wb.SAVE_DIALOG,directory=path,save_filename=plan["PlanBrief"],
|
||||
file_types=('JSON (*.json)', 'All files (*.*)'))
|
||||
print(file_name)
|
||||
if(file_name is None):
|
||||
return
|
||||
json_str=json.dumps(plan, sort_keys=True, indent=4, separators=(',', ': '),ensure_ascii=False)
|
||||
with open(file_name,"w+",encoding="utf-8") as f:
|
||||
f.write(json_str)
|
||||
|
Reference in New Issue
Block a user