2016-09-16 20:30:48 +00:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
from dialog import Dialog
|
|
|
|
import json
|
|
|
|
|
|
|
|
d = Dialog(dialog="dialog")
|
|
|
|
d.set_background_title("Klandr")
|
|
|
|
|
|
|
|
#klandringer = [{"klandrer":"Person 1","klandret":"Person 2","title":"Title to be","description":"Description to be"}]
|
2016-09-16 20:41:46 +00:00
|
|
|
with open("klandringer.json", "r") as jsonfile:
|
|
|
|
klandringer = json.loads(jsonfile.read())
|
2016-09-16 20:30:48 +00:00
|
|
|
|
|
|
|
# Begin definitions
|
|
|
|
|
|
|
|
def menu_main():
|
|
|
|
code, tag = d.menu("Vælg punkt på dagsordenen",
|
|
|
|
title="Hovedmenu",
|
|
|
|
choices=[("Indledende", "Indledende bemærkninger"),
|
|
|
|
("Klandringer", "Så mange klandringer"),
|
|
|
|
("Afsluttende", "Afsluttende bemærkninger")])
|
|
|
|
|
|
|
|
if code == d.OK:
|
|
|
|
if tag == "Indledende":
|
|
|
|
menu_indledende()
|
|
|
|
elif tag == "Klandringer":
|
|
|
|
menu_klandringer()
|
|
|
|
elif tag == "Afsluttende":
|
|
|
|
menu_afsluttende()
|
|
|
|
|
|
|
|
|
|
|
|
# Begin klandringer
|
|
|
|
|
|
|
|
def menu_klandringer():
|
2016-09-16 20:41:46 +00:00
|
|
|
code, tag = d.menu("Hvad du vil gøre med klandringerne?",
|
2016-09-16 20:30:48 +00:00
|
|
|
title="Klandringer",
|
2016-09-16 20:41:46 +00:00
|
|
|
choices=[("Ny", "Oprette en ny klandring"),
|
|
|
|
("Ændr", "Ændre en eksisterende klandring"),
|
|
|
|
#("Omarrangér", "Omarrangere de eksisterende klandringer"),
|
|
|
|
("Slet", "Slette en eksisterende klandring")])
|
2016-09-16 20:30:48 +00:00
|
|
|
|
|
|
|
if code == d.CANCEL:
|
|
|
|
menu_main()
|
|
|
|
elif code == d.OK:
|
|
|
|
if tag == "Ny":
|
|
|
|
create_klandring()
|
|
|
|
else:
|
|
|
|
klandring = menu_select_klandring()
|
|
|
|
if klandring != None:
|
|
|
|
if tag == "Ændr":
|
|
|
|
edit_klandring(klandring)
|
|
|
|
elif tag == "Slet":
|
|
|
|
delete_klandring(klandring)
|
|
|
|
else:
|
|
|
|
menu_klandringer()
|
|
|
|
|
|
|
|
def menu_select_klandring():
|
|
|
|
klandringer_entries = [(str(i),k["klandrer"] + " v. " + k["klandret"] + " - " + k["title"]) for i,k in enumerate(klandringer)]
|
|
|
|
code, tag = d.menu("Vælg den klandring du vil ændre/slette",
|
|
|
|
title="Vælg klandring",
|
|
|
|
choices=klandringer_entries)
|
|
|
|
if code == d.OK:
|
|
|
|
return tag
|
|
|
|
|
|
|
|
def create_klandring():
|
|
|
|
klandringer.append({"klandrer":"","klandret":"","title":""})
|
|
|
|
edit_klandring(-1)
|
|
|
|
|
|
|
|
|
|
|
|
def edit_klandring(strid):
|
|
|
|
id = int(strid)
|
|
|
|
code, elements = d.form("Ændr detaljer om klandring",
|
|
|
|
title="Ændr klandring",
|
2016-09-16 20:41:46 +00:00
|
|
|
elements=[("Titel:",1,1,klandringer[id]["title"],1,11,40,40),
|
2016-09-16 20:30:48 +00:00
|
|
|
("Klandrer:",2,1,klandringer[id]["klandrer"],2,11,20,20),
|
|
|
|
("Klandret:",3,1,klandringer[id]["klandret"],3,11,20,20)])
|
|
|
|
|
|
|
|
if code == d.OK:
|
|
|
|
klandringer[id]["title"] = elements[0]
|
|
|
|
klandringer[id]["klandrer"] = elements[1]
|
|
|
|
klandringer[id]["klandret"] = elements[2]
|
2016-09-16 20:41:46 +00:00
|
|
|
save_klandringer()
|
|
|
|
|
|
|
|
menu_klandringer()
|
|
|
|
|
2016-09-16 20:30:48 +00:00
|
|
|
|
|
|
|
def delete_klandring(strid):
|
|
|
|
id = int(strid)
|
|
|
|
code = d.yesno("Vil du virkelig slette denne klandring?\n\nDenne handling er ufortrydelig!",
|
|
|
|
title="Slet klandring!",
|
|
|
|
yes_label="Ja",
|
|
|
|
no_label="Nej",)
|
|
|
|
if code == d.OK:
|
|
|
|
del klandringer[id]
|
|
|
|
d.msgbox("Klandringen er slettet!")
|
2016-09-16 20:41:46 +00:00
|
|
|
save_klandringer()
|
|
|
|
|
2016-09-16 20:30:48 +00:00
|
|
|
menu_klandringer()
|
|
|
|
|
2016-09-16 20:41:46 +00:00
|
|
|
def save_klandringer():
|
|
|
|
with open("klandringer.json","w") as jsonfile:
|
|
|
|
jsonfile.write(json.dumps(klandringer))
|
|
|
|
|
2016-09-16 20:30:48 +00:00
|
|
|
# End klandringer
|
|
|
|
# End definitions
|
|
|
|
|
|
|
|
menu_main()
|