diff --git a/.gitignore b/.gitignore index 13d1490..018bb81 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ __pycache__/ *.py[cod] *$py.class +config.json + # C extensions *.so diff --git a/cropper.py b/cropper.py index 3891e4d..b7ae113 100644 --- a/cropper.py +++ b/cropper.py @@ -46,7 +46,7 @@ def crop(args): print('convert {0} to {1}'.format(infile, inbase + '.pdf')) slides.SaveAs(inbase + '.pdf', 32) slides.close() - powerpoint.Quit() + # powerpoint.Quit() # read comments. ppt = Presentation(infile) slides = ppt.slides diff --git a/main.py b/main.py index 67ec941..f4b59d7 100644 --- a/main.py +++ b/main.py @@ -85,8 +85,30 @@ def parse_and_crop(conf): # parser.add_argument('--visual', '-v', default=False, action='store_true', help='display cropbox.') # parser.add_argument('--mute', '-m', default=False, action='store_true', help='do not display output file path.') # args = parser.parse_args() - +import os +import json from ui import Loader +defaults = { + "input": "", + "output": "", + "background_color": "", + "border": "0.0", + "zoom": "1.0", + "thresh": "1.0", + "split": "true", + "names": "", + "visual": "false", + "mute": "false" +} +config_path = 'config.json' +if os.path.isfile(config_path): + with open(config_path, 'r', encoding='utf-8') as f: + updater = json.load(f) + defaults.update(updater) +else: + with open(config_path, 'w+', encoding='utf-8') as f: + json.dump(defaults, f, ensure_ascii=False, indent=4) + conf = { "input": {"name": "源文件", "type": "readfile", "extension": ("PDF & PPT", ".pdf .pptx")}, "output": {"name": "保存路径", "type": "savefile"}, @@ -99,6 +121,10 @@ conf = { "visual": {"name": "显示裁切框", "type": "str", "default": "false"}, "mute": {"name": "显示保存文件", "type": "str", "default": "false"}, } + +# write defaults. +for key in defaults: + conf[key]['default'] = defaults[key] root = tk.Tk() Loader(master=root, conf=conf, execution=parse_and_crop, title="PDF/PPT自动裁边") root.mainloop() \ No newline at end of file