This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
database_manager.py
297 lines (218 loc) · 9.69 KB
/
database_manager.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
from glob import glob
from tkinter import * # Python interface to the Tk GUI toolkit
from tkinter import filedialog # open file
from tkinter import ttk
from tkinter.messagebox import showinfo
import tkinter
import database
import database_tools
selected_uuid = ""
root = Tk()
root.title('Database Manager')
#menu itmes removed for space
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
frame1 = Frame(root)
frame2 = Frame(root)
frame3 = Frame(root)
scrollbar = Scrollbar(frame1) # put a scrolbar widget on the right side of the window
scrollbar.pack(side = RIGHT, fill = Y)
# put a treeview widget on the window with stylized column headers and use show="headings" to hide the first hierarchy column
column_headers=['uuid','release_name', 'system', 'region']
style = ttk.Style()
style.configure("Treeview.Heading", font=("Verdana", 11))
tv = ttk.Treeview(frame1, height=30, columns=column_headers, show="headings", yscrollcommand = scrollbar.set)
def refresh_games(search=""):
for item in tv.get_children():
tv.delete(item)
for game in database.search_roms_by_name(search):
tv.insert('', tkinter.END, values=(game['uuid'],game['release_name'],game["system"],game["region"]))
tv.pack(side=LEFT, fill=BOTH, expand=TRUE)
scrollbar.config(command = tv.yview)
def search_games(e):
for item in tv.get_children():
tv.delete(item)
for game in database.search_roms_by_name(search_entry.get()):
tv.insert('', tkinter.END, values=(game['uuid'],game['release_name'],game["system"],game["region"]))
def clear_search():
search_entry.delete(0, END)
refresh_games()
clear_search_button = ttk.Button(frame2, text = "Clear", width=15,command=clear_search)
clear_search_button.pack(side = RIGHT, anchor =NE , padx=10, pady=5)
search_label = Label(frame2, text= "Search:")
search_label.pack(side = LEFT, anchor = W, padx=1, pady=1)
search_entry = Entry(frame2,width=60)
search_entry.pack(side = RIGHT, anchor = W, padx=1, pady=1)
search_entry.bind('<KeyRelease>', search_games)
def treeview_sort_column(tv, col, text, reverse):
l = [(tv.set(k, col), k) for k in tv.get_children('')]
l.sort(reverse=reverse)
# rearrange items in sorted positions
for index, (val, k) in enumerate(l):
tv.move(k, '', index)
# reverse sort next time
tv.heading(col, text=text, command=lambda _col=col: \
treeview_sort_column(tv, _col, text,not reverse))
tv.heading('uuid', text='UUID')
tv.column('uuid', anchor='w',width=50)
tv.heading('release_name', text='Release Name',command=lambda _col="release_name":treeview_sort_column(tv, _col, 'Release Name', False))
tv.column('release_name', anchor='w', width = 400)
tv.heading('system', text='System',command=lambda _col="system":treeview_sort_column(tv, _col,"System",False))
tv.column('system', anchor='w',width=180)
tv.heading('region', text='Region',command=lambda _col="region":treeview_sort_column(tv, _col,"Region",False))
tv.column('region', anchor='w',width = 90)
for game in database.search_roms_by_name(""):
tv.insert('', tkinter.END, values=(game['uuid'],game['release_name'],game["system"],game["region"]))
rn_label = Label(frame3, text= "Release Name")
rn_label.pack( anchor = SW,padx=1, pady=1)
rn_entry = Entry(frame3,width=60)
rn_entry.pack( anchor = SW,padx=1, pady=1)
romn_label = Label(frame3, text= "Rom Extensionless File Name")
romn_label.pack( anchor = SW,padx=1, pady=1)
romn_entry = Entry(frame3,width=60)
romn_entry.pack( anchor = SW,padx=1, pady=1)
sha1_label = Label(frame3, text= "SHA1")
sha1_label.pack( anchor = SW,padx=1, pady=1)
sha1_entry = Entry(frame3,width=60)
sha1_entry.pack( anchor = SW,padx=1, pady=1)
developer_label = Label(frame3, text= "Developer")
developer_label.pack( anchor = SW,padx=1, pady=1)
developer_entry = Entry(frame3,width=60)
developer_entry.pack( anchor = SW,padx=1, pady=1)
publisher_label = Label(frame3, text= "Publisher")
publisher_label.pack( anchor = SW,padx=1, pady=1)
publisher_entry = Entry(frame3,width=60)
publisher_entry.pack( anchor = SW,padx=1, pady=1)
genre_label = Label(frame3, text= "Genre")
genre_label.pack( anchor = SW,padx=1, pady=1)
genre_entry = Entry(frame3,width=60)
genre_entry.pack( anchor = SW,padx=1, pady=1)
date_label = Label(frame3, text= "Date")
date_label.pack( anchor = SW,padx=1, pady=1)
date_entry = Entry(frame3,width=60)
date_entry.pack( anchor = SW,padx=1, pady=1)
reference_label = Label(frame3, text= "Reference URL")
reference_label.pack( anchor = SW,padx=1, pady=1)
reference_entry = Entry(frame3,width=60)
reference_entry.pack( anchor = SW,padx=1, pady=1)
manual_label = Label(frame3, text= "Manual URL")
manual_label.pack( anchor = SW,padx=1, pady=1)
manual_entry = Entry(frame3,width=60)
manual_entry.pack( anchor = SW,padx=1, pady=1)
region_label = Label(frame3, text= "Region")
region_label.pack( anchor = SW,padx=1, pady=1)
region_combo = ttk.Combobox(frame3)
region_combo["values"] = database_tools.regions
region_combo.current(1)
region_combo.pack(anchor = SW,padx=1, pady=1)
system_label = Label(frame3, text= "System")
system_label.pack( anchor = SW,padx=1, pady=1)
system_combo = ttk.Combobox(frame3)
system_combo["values"] = database_tools.systems
system_combo.current(1)
system_combo.pack(anchor = SW,padx=1, pady=1)
description_label = Label(frame3, text= "Description")
description_label.pack(anchor = SW,padx=1, pady=1)
description_text = Text(frame3,height=10, width=60)
description_text.pack(anchor = SW,padx=1, pady=1)
def clear():
global selected_uuid
selected_uuid = ""
rn_entry.delete(0, END)
romn_entry.delete(0, END)
region_combo.current(1)
system_combo.current(1)
developer_entry.delete(0, END)
sha1_entry.delete(0, END)
publisher_entry.delete(0, END)
genre_entry.delete(0, END)
date_entry.delete(0, END)
reference_entry.delete(0, END)
manual_entry.delete(0, END)
description_text.delete("1.0", END)
def delete():
if selected_uuid != "":
MsgBox = tkinter.messagebox.askquestion ('Delete Record','Are you sure you want to delete the record',icon = 'warning')
if MsgBox == 'yes':
database.delete_rom(selected_uuid)
clear()
refresh_games()
def submit():
rom = {}
rom['uuid'] = selected_uuid
rom["release_name"] = rn_entry.get()
rom["region"] = region_combo.get()
rom["system"] = system_combo.get()
rom['sha1'] = sha1_entry.get().upper()
rom["rom_extensionless_file_name"] = romn_entry.get()
rom["publisher"] = publisher_entry.get()
rom["date"] = date_entry.get()
rom["developer"] = developer_entry.get()
rom["genre"] = genre_entry.get()
rom["description"] = description_text.get("1.0","end")
rom["reference_url"] = reference_entry.get()
rom["manual_url"] = manual_entry.get()
if selected_uuid != "":
test = database.get_rom_by_uuid(rom["uuid"])
# rom already exist so we will update
if len(test) > 0:
database.update_rom(rom)
clear()
refresh_games()
else:
if database.is_new_rom(rom):
database.update_rom(rom)
clear()
refresh_games()
else:
tkinter.messagebox.showerror(title="Error", message="Either Sha1 or Rom Extensionless File Name need to be unique")
def duplicate():
global selected_uuid
if selected_uuid != "":
selected_uuid = database_tools.generate_uuid()
tkinter.messagebox.showinfo(title="Creating Duplicate", message="You are now edidting a duplicate record \n a new uuid has been generated \n SHA1 AND OR Rom Name should be changed \n submit to add new record")
export_button = ttk.Button(frame3, text = "Submit", width=15,command=submit)
export_button.pack(side = LEFT, anchor = NE, padx=10, pady=5)
duplicate_button = ttk.Button(frame3, text = "Duplicate", width=15,command=duplicate)
duplicate_button.pack(side = LEFT, anchor = NE, padx=10, pady=5)
clear_button = ttk.Button(frame3, text = "Clear", width=15,command=clear)
clear_button.pack(side = LEFT, anchor = NE, padx=10, pady=5)
close_button = ttk.Button(frame3, text = "Delete", width=15,command=delete)
close_button.pack(side = LEFT, anchor = NE, padx=10, pady=5)
frame1.grid(column=0, row=0, sticky="nsew")
frame2.grid(column=0, row=1, sticky="n")
frame3.grid(column=1, row=0, sticky="nsew")
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=1)
def item_selected(event):
global selected_uuid
for selected_item in tv.selection():
item = tv.item(selected_item)
record = item['values']
details = database.get_rom_by_uuid(record[0])
selected_uuid = details["uuid"]
rn_entry.delete(0, END)
rn_entry.insert(0, details["release_name"])
romn_entry.delete(0, END)
romn_entry.insert(0, details["rom_extensionless_file_name"])
region_combo.set(details["region"])
system_combo.set(details["system"])
developer_entry.delete(0, END)
developer_entry.insert(0, details["developer"])
sha1_entry.delete(0, END)
sha1_entry.insert(0, details["sha1"])
publisher_entry.delete(0, END)
publisher_entry.insert(0, details["publisher"])
genre_entry.delete(0, END)
genre_entry.insert(0, details["genre"])
date_entry.delete(0, END)
date_entry.insert(0, details["date"])
reference_entry.delete(0, END)
reference_entry.insert(0, details["reference_url"])
manual_entry.delete(0, END)
manual_entry.insert(0, details["manual_url"])
description_text.delete("1.0", END)
description_text.insert("1.0", details["description"])
tv.bind('<<TreeviewSelect>>', item_selected)
root.mainloop()