-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.py
139 lines (103 loc) · 5.38 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import tkinter as tk
from cli import CLI
from variables import black
from ttkbootstrap import Style
from tkinter import NW, BooleanVar, PhotoImage, Scrollbar, StringVar, ttk, filedialog, DISABLED, END, NORMAL, VERTICAL, NSEW, NS, EW, E
class GUI(tk.Tk):
def __init__(self):
super().__init__()
self.path = StringVar()
self.subdir = BooleanVar()
self.title("Music Track Fixer")
self.resizable(False, False)
self._center_window()
self._create_grid("20 20 20 20")
self._configure_style()
self._create_widgets()
self.cli = CLI()
def _center_window(self, per_of_screen_w=40, per_of_screen_h=60):
# Get the screen dimension
sw = self.winfo_screenwidth()
sh = self.winfo_screenheight()
# Covert the percentage of the screen to window width & height
ww = int(sw*(per_of_screen_w/100))
wh = int(sh*(per_of_screen_h/100))
# Find the center point
center_x = int(sw/2 - ww / 2)
center_y = int(sh/2 - wh / 2)
# Set the position of the window to the center of the screen
self.geometry(f'{ww}x{wh}+{center_x}+{center_y}')
def _create_grid(self, padding):
self.main_frame = ttk.Frame(self, padding=padding)
self.main_frame.pack(fill="both", expand=True)
self._configure_grid()
def _configure_grid(self):
self.main_frame.columnconfigure(2, weight=1)
# self.main_frame.columnconfigure(3, weight=4)
self.main_frame.rowconfigure(1, weight=2)
def _configure_style(self):
self.style = Style(theme="morph")
self.style.configure("TLabel", font=("Calibri", 14))
self.style.configure("TButton", font=("Calibri", 14))
self.style.configure("TEntry", font=("Calibri", 14)) # This doesn't work!
self.style.configure("TCheckbutton", font=("Calibri", 14))
def _set_path_entry_value(self, entry_value):
self.path_entry.configure(state=NORMAL)
self.path.set(entry_value)
self.path_entry.configure(state=DISABLED)
def _browse_folder(self):
directory = filedialog.askdirectory()
if directory:
self._set_path_entry_value(directory)
def _start_get_meta(self):
self.cli.start(self, "get_meta")
def _start_fix_meta(self):
self.cli.start(self, "fix_meta")
def _start_rename(self):
self.cli.start(self, "rename")
def _create_widgets(self):
# ROW 0 - PATH LABEL
self.path_label = ttk.Label(self.main_frame, text="Music Files Location:")
self.path_label.grid(row=0, column=0)
# ROW 0 - BROWSE FOLDER BUTTON
self.folder_icon = PhotoImage(file="icons/open-folder_24px.png")
self.browse_button = ttk.Button(self.main_frame, image=self.folder_icon, padding="5 0", command=self._browse_folder)
self.browse_button.grid(row=0, column=1, sticky=NW, padx="20 0")
# ROW 0 - SHOW SELECTED PATH
self.path_entry = ttk.Entry(self.main_frame, textvariable=self.path, state=DISABLED)
self.path_entry.grid(row=0, column=2, sticky=EW)
# ROW 0 - SUBDIR CHECKBUTTON
self.sub_dir_ckeckbutton = ttk.Checkbutton(self.main_frame, text="Include Subdirectories", name="sub_dir", variable=self.subdir, onvalue=1, offvalue=0, state=NORMAL)
self.sub_dir_ckeckbutton.grid(row=0, column=3, sticky=E, padx="20 0")
#=============================================================================#
# ROW 1 - OUTPUT TEXT
self.output_text = tk.Text(self.main_frame, state=DISABLED)
self.output_text.grid(row=1, column=0, columnspan=4, sticky=NSEW, pady=20)
# ROW 1 - SCROLLBAR
self.scroll = Scrollbar(self.main_frame, orient=VERTICAL, command=self.output_text.yview)
self.scroll.grid(row=1, column=0, columnspan=4, sticky=(NS, E), pady=20)
#=============================================================================#
# ROW 2 - BUTTON GET META
self.get_meta_button = ttk.Button(self.main_frame, text="Get Metadata", command=self._start_get_meta)
self.get_meta_button.grid(row=2, column=0, columnspan=4, sticky=EW)
#=============================================================================#
# ROW 3 - BUTTON FIX META
self.fix_meta_button = ttk.Button(self.main_frame, text="Fix Metadata", command=self._start_fix_meta)
self.fix_meta_button.grid(row=3, column=0, columnspan=4, sticky=EW, pady=20)
#=============================================================================#
# ROW 4 - BUTTON RENAME
self.rename_button = ttk.Button(self.main_frame, text="Rename", command=self._start_rename)
self.rename_button.grid(row=4, column=0, columnspan=4, sticky=EW)
def get_subdir_value(self):
return self.subdir.get()
def get_path_value(self):
return self.path.get()
def set_output_value(self, output_value, fg=black, delete=False):
self.output_text.configure(state=NORMAL, fg=fg)
if delete is True:
self.output_text.delete("1.0", END)
self.output_text.insert(END, output_value)
self.output_text.configure(state=DISABLED)
if __name__ == "__main__":
app = GUI()
app.mainloop()