tilføj muligheden for at lave, ændre og slette klandringer

This commit is contained in:
Christoffer Müller Madsen 2016-09-16 22:41:46 +02:00
parent defa66c3c9
commit 1988c6249f

View File

@ -6,10 +6,8 @@ d = Dialog(dialog="dialog")
d.set_background_title("Klandr") d.set_background_title("Klandr")
#klandringer = [{"klandrer":"Person 1","klandret":"Person 2","title":"Title to be","description":"Description to be"}] #klandringer = [{"klandrer":"Person 1","klandret":"Person 2","title":"Title to be","description":"Description to be"}]
#f = open("klandringer.json", "r", encoding="utf-8") with open("klandringer.json", "r") as jsonfile:
#print(f) klandringer = json.loads(jsonfile.read())
#klandringer = json.loads(str(f))
# Begin definitions # Begin definitions
@ -32,11 +30,12 @@ def menu_main():
# Begin klandringer # Begin klandringer
def menu_klandringer(): def menu_klandringer():
code, tag = d.menu("Vælg hvad du vil gøre med klandringerne.", code, tag = d.menu("Hvad du vil gøre med klandringerne?",
title="Klandringer", title="Klandringer",
choices=[("Ny", "Opret en ny klandring"), choices=[("Ny", "Oprette en ny klandring"),
("Ændr", "Ændr en eksisterende klandring"), ("Ændr", "Ændre en eksisterende klandring"),
("Slet", "Slet en eksisterende klandring")]) #("Omarrangér", "Omarrangere de eksisterende klandringer"),
("Slet", "Slette en eksisterende klandring")])
if code == d.CANCEL: if code == d.CANCEL:
menu_main() menu_main()
@ -70,7 +69,7 @@ def edit_klandring(strid):
id = int(strid) id = int(strid)
code, elements = d.form("Ændr detaljer om klandring", code, elements = d.form("Ændr detaljer om klandring",
title="Ændr klandring", title="Ændr klandring",
elements=[("Titel:",1,1,klandringer[id]["title"],1,11,20,20), elements=[("Titel:",1,1,klandringer[id]["title"],1,11,40,40),
("Klandrer:",2,1,klandringer[id]["klandrer"],2,11,20,20), ("Klandrer:",2,1,klandringer[id]["klandrer"],2,11,20,20),
("Klandret:",3,1,klandringer[id]["klandret"],3,11,20,20)]) ("Klandret:",3,1,klandringer[id]["klandret"],3,11,20,20)])
@ -78,6 +77,10 @@ def edit_klandring(strid):
klandringer[id]["title"] = elements[0] klandringer[id]["title"] = elements[0]
klandringer[id]["klandrer"] = elements[1] klandringer[id]["klandrer"] = elements[1]
klandringer[id]["klandret"] = elements[2] klandringer[id]["klandret"] = elements[2]
save_klandringer()
menu_klandringer()
def delete_klandring(strid): def delete_klandring(strid):
id = int(strid) id = int(strid)
@ -88,12 +91,15 @@ def delete_klandring(strid):
if code == d.OK: if code == d.OK:
del klandringer[id] del klandringer[id]
d.msgbox("Klandringen er slettet!") d.msgbox("Klandringen er slettet!")
save_klandringer()
menu_klandringer() menu_klandringer()
def save_klandringer():
with open("klandringer.json","w") as jsonfile:
jsonfile.write(json.dumps(klandringer))
# End klandringer # End klandringer
# End definitions # End definitions
menu_main() menu_main()
print(json.dumps(klandringer))