add tkinter GUI, courtesy of Potter360
This commit is contained in:
parent
86d8f7ec95
commit
681c7a0736
|
@ -1,6 +1,7 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
def align(start, end, alignment):
|
||||
"""Align (<start>, <end>) on multiples of <alignment>."""
|
||||
|
@ -211,7 +212,7 @@ ALL_TRANSFORMS = [
|
|||
ML_get_contrast,
|
||||
]
|
||||
|
||||
def main(g1a_input, g1a_output):
|
||||
def patch_addin(g1a_input, g1a_output):
|
||||
with open(g1a_input, "rb") as fp:
|
||||
data = bytearray(fp.read())
|
||||
|
||||
|
@ -330,8 +331,93 @@ def main(g1a_input, g1a_output):
|
|||
print("Success!")
|
||||
return 0
|
||||
|
||||
#---
|
||||
|
||||
import tkinter as tk
|
||||
import tkinter.filedialog
|
||||
import tkinter.ttk as ttk
|
||||
import contextlib
|
||||
import io
|
||||
|
||||
def tkinter_gui():
|
||||
window = tk.Tk()
|
||||
window.title("CASIO Graph 35+E II/G-III MonochromeLib patch")
|
||||
window.minsize(480, 320)
|
||||
|
||||
style = ttk.Style()
|
||||
style.theme_use("clam")
|
||||
style.configure("SUCCESS.TLabel", foreground="green")
|
||||
style.configure("FAILURE.TLabel", foreground="red")
|
||||
|
||||
frame = ttk.LabelFrame(window, text="Patch add-in")
|
||||
frame.pack(fill="both", expand=0, padx=6, pady=3)
|
||||
|
||||
def select():
|
||||
path = tk.filedialog.askopenfilename(
|
||||
parent=window,
|
||||
title="Select an add-in file",
|
||||
filetypes=[("CASIO add-in file", ".g1a"), ("All files", "*")])
|
||||
if path == "" or path == ():
|
||||
inputname["text"] = "<Not selected>"
|
||||
outputname["text"] = "<Not selected>"
|
||||
filepatch["state"] = "disabled"
|
||||
else:
|
||||
inputname["text"] = path
|
||||
outputname["text"] = "-E2".join(os.path.splitext(path))
|
||||
filepatch["state"] = "normal"
|
||||
resultstr["text"] = ""
|
||||
|
||||
def patch():
|
||||
with contextlib.redirect_stdout(io.StringIO()) as fp:
|
||||
rc = patch_addin(inputname["text"], outputname["text"])
|
||||
if rc == 0:
|
||||
resultstr.config(text="Success!", style="SUCCESS.TLabel")
|
||||
else:
|
||||
resultstr.config(text="Failed!", style="FAILURE.TLabel")
|
||||
log.delete("1.0", "end")
|
||||
log.insert("end", fp.getvalue())
|
||||
|
||||
buttonbox = ttk.Frame(frame)
|
||||
fileselect = ttk.Button(buttonbox, text="Select add-in file...",
|
||||
command=select)
|
||||
fileselect.grid(row=0, column=0, padx=6, pady=3)
|
||||
filepatch = ttk.Button(buttonbox, text="Patch add-in", state="disabled",
|
||||
command=patch)
|
||||
filepatch.grid(row=0, column=1, padx=6, pady=3)
|
||||
buttonbox.pack(fill="x")
|
||||
|
||||
namebox = ttk.Frame(frame)
|
||||
ttk.Label(namebox, text="Input file:").grid(row=0, column=0, sticky="w")
|
||||
inputname = ttk.Label(namebox, text="<Not selected>")
|
||||
inputname.grid(row=0, column=1, sticky="w", padx=16)
|
||||
ttk.Label(namebox, text="Output file:").grid(row=1, column=0, sticky="w")
|
||||
outputname = ttk.Label(namebox, text="<Not selected>")
|
||||
outputname.grid(row=1, column=1, sticky="w", padx=16)
|
||||
ttk.Label(namebox, text="Result:").grid(row=2, column=0, sticky="w")
|
||||
resultstr = ttk.Label(namebox, text="", font=("TkDefaultFont", 9, "bold"))
|
||||
resultstr.grid(row=2, column=1, sticky="w", padx=16)
|
||||
namebox.pack(fill="x", padx=8)
|
||||
|
||||
logframe = ttk.LabelFrame(window, text="Log")
|
||||
logframe.pack(fill="both", expand=1, padx=6, pady=3)
|
||||
|
||||
log_scrollbar = ttk.Scrollbar(logframe)
|
||||
log_scrollbar.pack(fill="y", side=tk.RIGHT)
|
||||
log = tk.Text(logframe, font="TkFixedFont", yscrollcommand=log_scrollbar.set)
|
||||
log.pack(fill="both", expand=True, side=tk.LEFT) # padx=6, pady=3)
|
||||
log_scrollbar.config(command=log.yview)
|
||||
|
||||
quit = ttk.Button(window, text="Quit", command=window.destroy)
|
||||
quit.pack(side=tk.RIGHT, padx=6, pady=6)
|
||||
|
||||
window.mainloop()
|
||||
|
||||
#---
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) == 1:
|
||||
sys.exit(tkinter_gui())
|
||||
if len(sys.argv) != 3 or "-h" in sys.argv[1:] or "--help" in sys.argv[1:]:
|
||||
print(f"usage: {sys.argv[0]} <input g1a> <output g1a>",file=sys.stderr)
|
||||
sys.exit(0)
|
||||
sys.exit(main(sys.argv[1], sys.argv[2]))
|
||||
sys.exit(patch_addin(sys.argv[1], sys.argv[2]))
|
||||
|
|
Loading…
Reference in New Issue