add config file for default configuration, fix a bug that close powerpoint after cropping

This commit is contained in:
mingyang 2021-06-03 11:32:22 +08:00
parent 3b9b8a5a16
commit 681af4b36a
3 changed files with 30 additions and 2 deletions

2
.gitignore vendored
View File

@ -4,6 +4,8 @@ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
config.json
# C extensions # C extensions
*.so *.so

View File

@ -46,7 +46,7 @@ def crop(args):
print('convert {0} to {1}'.format(infile, inbase + '.pdf')) print('convert {0} to {1}'.format(infile, inbase + '.pdf'))
slides.SaveAs(inbase + '.pdf', 32) slides.SaveAs(inbase + '.pdf', 32)
slides.close() slides.close()
powerpoint.Quit() # powerpoint.Quit()
# read comments. # read comments.
ppt = Presentation(infile) ppt = Presentation(infile)
slides = ppt.slides slides = ppt.slides

28
main.py
View File

@ -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('--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.') # parser.add_argument('--mute', '-m', default=False, action='store_true', help='do not display output file path.')
# args = parser.parse_args() # args = parser.parse_args()
import os
import json
from ui import Loader 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 = { conf = {
"input": {"name": "源文件", "type": "readfile", "extension": ("PDF & PPT", ".pdf .pptx")}, "input": {"name": "源文件", "type": "readfile", "extension": ("PDF & PPT", ".pdf .pptx")},
"output": {"name": "保存路径", "type": "savefile"}, "output": {"name": "保存路径", "type": "savefile"},
@ -99,6 +121,10 @@ conf = {
"visual": {"name": "显示裁切框", "type": "str", "default": "false"}, "visual": {"name": "显示裁切框", "type": "str", "default": "false"},
"mute": {"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() root = tk.Tk()
Loader(master=root, conf=conf, execution=parse_and_crop, title="PDF/PPT自动裁边") Loader(master=root, conf=conf, execution=parse_and_crop, title="PDF/PPT自动裁边")
root.mainloop() root.mainloop()