-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_rbr.py
115 lines (92 loc) · 3.78 KB
/
main_rbr.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
# main_rbr.py
# Chris Shepherd, Codethink Ltd, 2021-01-18
import os
import tkinter as tk
from tkinter import filedialog, messagebox
import rbrDatabase
# ------------------------------------------------------------------------------
# GUI which runs recursive scanning of folders, creation of .xml database
class gui:
def choose_folder(self, message):
return filedialog.askdirectory(title=message)
# ------------------------------------------------------------------------------
def folders_in_out(self):
in_out = ["", ""]
root_folder = self.choose_folder("Select root folder for your music")
if root_folder:
if os.path.isdir(root_folder):
in_out[0] = root_folder
out_folder = self.choose_folder("Select location for XML output")
if out_folder:
if os.path.isdir(out_folder):
in_out[1] = out_folder
else:
messagebox.showinfo("Warning", "Path doesn't exist, exiting")
else:
messagebox.showinfo("Warning", "Path doesn't exist, exiting")
return in_out
# ------------------------------------------------------------------------------
def create_db_and_print(
self, file_name_user, root_folder, out_folder, show_warning
):
db_main = rbrDatabase.rbrDatabase()
db_main.add_recursively(root_folder, show_warning)
if file_name_user == "":
file_name_user = "rbr_db"
out_file = os.path.join(out_folder, file_name_user) + ".xml"
db_main.write_pretty(out_file)
messagebox.showinfo("info", "Done! Database file : " + out_file)
# ------------------------------------------------------------------------------
def run(self, entry_db_name, show_warning):
file_name_user = entry_db_name.get()
in_out = self.folders_in_out()
if in_out[0] and in_out[1]:
self.create_db_and_print(file_name_user, in_out[0], in_out[1], show_warning)
# ------------------------------------------------------------------------------
def __init__(self):
# Create the GUI: buttons activate browsers for collection / output .xml folder
self.root_tk = tk.Tk()
self.root_tk.title("Rekordbox Recovery Tool")
self.root_folder = ""
info_message = "Rekordbox Recovery Tool, Chris Shepherd, 2022\n"
info = tk.Label(self.root_tk, text=info_message)
info.pack()
instructions = tk.Label(
self.root_tk,
text=(
"Enter name for output database, e.g. entering 'foo' creates 'foo.xml'. \
If left blank, will be named 'rbr_db.xml'"
),
)
instructions.pack()
# Text entry for database name
self.entry_db_name = tk.Entry(self.root_tk, width=20)
self.entry_db_name.pack()
# Checkbox for warning messages
self.show_warning = tk.IntVar()
check_warn = tk.Checkbutton(
self.root_tk,
text="Print compatibility warnings to console",
variable=self.show_warning,
)
check_warn.pack()
# "Run" button
run_text = tk.StringVar()
run_text.set("RUN")
run_button = tk.Button(
self.root_tk,
textvariable=run_text,
command=lambda: self.run(self.entry_db_name, self.show_warning.get()),
)
run_button.pack()
# "Close" button
close_text = tk.StringVar()
close_text.set("Close")
close_button = tk.Button(
self.root_tk,
textvariable=close_text,
command=lambda: self.root_tk.destroy(),
)
close_button.pack()
self.root_tk.mainloop()
my_gui = gui()