-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
93 lines (79 loc) · 2.92 KB
/
gui.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import tkinter as tk
import tkinter.font as tkFont
from chords import MAJOR_STR, MINOR_STR, MODAL_TONE, NOTES_B, NOTES_S, Chords, Scale
def get_possible_root_notes():
roots = []
for b, d in zip(NOTES_B[:12], NOTES_S[:12]):
if b == d:
roots += b
else:
roots += [d, b]
return roots
class App(tk.Tk):
def __init__(self) -> None:
super().__init__()
self.geometry("700x400")
self.resizable(0, 0)
self.title("Chords Finder")
frame = tk.Frame(master=self, bg="white")
frame.pack(fill=tk.BOTH)
self.arial = tkFont.Font(family="arial", size=15, weight="normal")
label = tk.Label(
master=frame, text="Root note", font=self.arial, background="white"
)
label.pack()
self.root = tk.StringVar(self)
notes = get_possible_root_notes()
self.root.set(notes[0])
self.x = tk.OptionMenu(frame, self.root, notes[0], *notes)
self.x.config(font=self.arial)
self.x.pack()
label = tk.Label(
master=frame, text="Base scale", font=self.arial, background="white"
)
label.pack()
self.base_scale = tk.StringVar(self)
possible_bases = [MAJOR_STR, MINOR_STR]
self.base_scale.set(possible_bases[0])
self.y = tk.OptionMenu(frame, self.base_scale, *possible_bases)
self.y.config(font=self.arial)
self.y.pack()
label = tk.Label(master=frame, text="Mode", font=self.arial, background="white")
label.pack()
self.mode = tk.StringVar(self)
possible_modes = list(MODAL_TONE.keys())
self.mode.set(possible_modes[0])
self.z = tk.OptionMenu(frame, self.mode, *possible_modes)
self.z.config(font=self.arial)
self.z.pack()
self.seventh = tk.IntVar()
tk.Checkbutton(
frame,
text="Sevenths",
variable=self.seventh,
font=self.arial,
background="white",
).pack()
self.seventh.trace("w", self.callback)
self.t = tk.Text()
self.t.insert(
tk.END,
f"{Scale(self.root.get(), self.base_scale.get(), self.mode.get())}"
f"\n{Chords(Scale(self.root.get(), self.base_scale.get(), self.mode.get()), self.seventh.get())}",
)
self.t.config(font=self.arial)
self.t.pack()
self.root.trace("w", self.callback)
self.base_scale.trace("w", self.callback)
self.mode.trace("w", self.callback)
def callback(self, *args):
self.update_output()
def update_output(self):
self.t.delete("1.0", tk.END)
self.t.insert(
tk.END,
f"{Scale(self.root.get(), self.base_scale.get(), self.mode.get())}"
f"\n{Chords(Scale(self.root.get(), self.base_scale.get(), self.mode.get()), self.seventh.get())}",
)
if __name__=="__main__":
App().mainloop()