annotate gui.py @ 11:2ec81711f0c7

Move python files to this repo
author Paper <mrpapersonic@gmail.com>
date Wed, 26 Jan 2022 20:36:07 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 import tkinter
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 import tkinter.filedialog
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 import msvpvf
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4 import os
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 def round_down(num, divisor):
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 return num - (num%divisor)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 def open_veg_file():
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 filepath.set(tkinter.filedialog.askopenfilename(title="Select project file", filetypes=[("Project files", ".veg .vf"), ("All Files", "*.*")]))
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 with open(filepath.get(), 'rb') as file:
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 version_of_file.set("Project file version: %s" % (str(bytearray(file.read())[0x46])))
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 window.update_idletasks()
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 # eventually add shit here
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 def save_veg_file():
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 with open(filepath.get(), 'rb') as f:
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 path = bytearray(f.read())
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 for i in listbox.curselection():
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 prefix, data = msvpvf.type_hex(i)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 path[0x18:0x27] = data
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 path[0x46] = int(default_version.get())
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 outputfn = prefix + "_V" + default_version.get() + "_" + os.path.basename(os.path.splitext(filepath.get())[0])
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 outputfn += ".vf" if prefix == "MS" else ".veg"
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 name = tkinter.filedialog.asksaveasfilename(defaultextension='.vf' if prefix == "MS" else '.veg', initialfile=outputfn, filetypes=[("Project files", ".veg .vf"), ("All Files", "*.*")])
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 with open(name, 'wb') as f:
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 f.write(path)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 window = tkinter.Tk()
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 window.geometry("225x200")
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33 filepath = tkinter.StringVar(window)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34 version_of_file = tkinter.StringVar(window)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35 selected_version = tkinter.IntVar()
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38 button = tkinter.Button(text="Open", command=open_veg_file)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39 button.pack(pady=5)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 list_items = tkinter.StringVar(value=("VEGAS Pro", "Movie Studio"))
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41 listbox = tkinter.Listbox(window, height=2, listvariable=list_items)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 listbox.select_set(0)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43 listbox.pack(pady=5)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 supported_versions = ["8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"]
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 default_version = tkinter.StringVar()
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47 default_version.set(supported_versions[3])
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49 menu = tkinter.OptionMenu(window, default_version, *supported_versions)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 menu.pack(pady=5)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51 button = tkinter.Button(text="Save", command=save_veg_file)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
52 button.pack(pady=5)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 tkinter.Label(window, textvariable=version_of_file).pack(pady=5)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55 window.title("msvpvf")
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 window.minsize(225, 200)
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
57
2ec81711f0c7 Move python files to this repo
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58 window.mainloop()