forked from nausicaa-rose/alma_enumerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathae_gui
79 lines (62 loc) · 2.79 KB
/
ae_gui
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from tkinter import Tk, N, W, E, S, StringVar, INSERT, ttk, filedialog
import settings
from AE import fetch, update
# Select file to use
def get_file_path(btn, file):
setattr(settings, file, filedialog.askopenfilename())
btn.configure(text=getattr(settings, file))
# Make sure to get the latest mms_id and api_key
def update_settings():
settings.mms_id = mms_id.get().strip()
settings.api_key = api_key.get().strip()
# Fetch item info and save to file
def fetch_it():
update_settings()
fetch(settings.mms_id, settings.output_file, settings.error_file, settings.api_key, settings.base_url)
# Update item info from file
def update_it():
update_settings()
update(settings.mms_id, settings.input_file, settings.api_key, settings.base_url)
# Set up window
root = Tk()
root.title("Alma Enumerator")
# Set up content area in window
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
# Set up input for MMS ID
mms_id = StringVar()
mms_entry = ttk.Entry(mainframe, width=14, textvariable=mms_id)
mms_entry.insert(INSERT, settings.mms_id)
mms_entry.grid(column=2, row=1, sticky=(W, E))
ttk.Label(mainframe, text="MMS ID").grid(column=3, row=1, sticky=W)
# Set up input for output file
output_btn = ttk.Button(mainframe, text=settings.output_file, command=lambda: get_file_path(output_btn, 'output_file'))
output_btn.grid(column=2, row=2 , sticky=(W, E))
ttk.Label(mainframe, text="Output File").grid(column=3, row=2, sticky=W)
# Set up input for input file
input_btn = ttk.Button(mainframe, text=settings.input_file, command=lambda: get_file_path(input_btn, 'input_file'))
input_btn.grid(column=2, row=3, sticky=(W, E))
ttk.Label(mainframe, text="Input File").grid(column=3, row=3, sticky=W)
# Set up input for error file
error_btn = ttk.Button(mainframe, text=settings.error_file, command=lambda: get_file_path(error_btn, 'error_file'))
error_btn.grid(column=2, row=4, sticky=(W, E))
ttk.Label(mainframe, text="Error File").grid(column=3, row=4, sticky=W)
# Set up input for API key
api_key = StringVar()
api_entry = ttk.Entry(mainframe, width=14, textvariable=api_key)
api_entry.insert(INSERT, settings.api_key)
api_entry.grid(column=2, row=5, sticky=(W, E))
ttk.Label(mainframe, text="API Key").grid(column=3, row=5, sticky=W)
# Add 'Fetch' and 'Update' buttons
ttk.Button(mainframe, text="Fetch", command=fetch_it).grid(column=2, row=6, sticky=W)
ttk.Button(mainframe, text="Update", command=update_it).grid(column=3, row=6, sticky=E)
# Set padding for widgets
for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
# Set focus on input for MMS ID
mms_entry.focus()
# Begin main loop
root.mainloop()