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")
|
|
|
|
|
2016-09-16 21:41:31 +00:00
|
|
|
|
|
|
|
klandringer = None
|
2016-09-16 20:41:46 +00:00
|
|
|
with open("klandringer.json", "r") as jsonfile:
|
2016-09-16 21:41:31 +00:00
|
|
|
contents = jsonfile.read()
|
|
|
|
if contents == "":
|
|
|
|
complete_klandringer = {}
|
|
|
|
else:
|
|
|
|
complete_klandringer = json.loads(contents)
|
2016-09-16 20:30:48 +00:00
|
|
|
|
2016-09-16 21:41:31 +00:00
|
|
|
|
2016-09-16 20:30:48 +00:00
|
|
|
# Begin definitions
|
|
|
|
|
2016-09-16 21:41:31 +00:00
|
|
|
def menu_select_date():
|
|
|
|
global klandringer
|
|
|
|
if complete_klandringer == {}:
|
|
|
|
date_entries = [()]
|
|
|
|
else:
|
|
|
|
date_entries = [(k,"") for k in complete_klandringer]
|
|
|
|
date_entries.append(("Ny","Opret en ny dato"))
|
|
|
|
code, tag = d.menu("Vælg den dato du vil ændre",
|
|
|
|
title="Vælg dato",
|
|
|
|
choices=date_entries)
|
|
|
|
if code == d.OK:
|
|
|
|
date = tag
|
|
|
|
if tag == "Ny":
|
|
|
|
date = new_date()
|
|
|
|
|
|
|
|
klandringer = complete_klandringer[date]
|
|
|
|
menu_main()
|
|
|
|
|
2016-09-16 20:30:48 +00:00
|
|
|
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"),
|
2016-09-16 21:41:31 +00:00
|
|
|
("Beskriv", "Beskriv en eksisterende klandring"),
|
2016-09-16 20:41:46 +00:00
|
|
|
#("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)
|
2016-09-16 21:41:31 +00:00
|
|
|
elif tag == "Beskriv":
|
|
|
|
describe_klandring(klandring)
|
2016-09-16 20:30:48 +00:00
|
|
|
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():
|
2016-09-16 21:41:31 +00:00
|
|
|
klandringer.append({"klandrer":"","klandret":"","title":"","description":"","taber":""})
|
2016-09-16 20:30:48 +00:00
|
|
|
edit_klandring(-1)
|
|
|
|
|
|
|
|
|
|
|
|
def edit_klandring(strid):
|
|
|
|
id = int(strid)
|
2016-09-16 21:41:31 +00:00
|
|
|
k = klandringer[id]
|
2016-09-16 20:30:48 +00:00
|
|
|
code, elements = d.form("Ændr detaljer om klandring",
|
|
|
|
title="Ændr klandring",
|
2016-09-16 21:41:31 +00:00
|
|
|
elements=[("Titel:",1,1,k["title"],1,11,40,40),
|
|
|
|
("Klandrer:",2,1,k["klandrer"],2,11,20,20),
|
|
|
|
("Klandret:",3,1,k["klandret"],3,11,20,20),
|
|
|
|
("Taber:",4,1,k["taber"],4,11,20,20)])
|
2016-09-16 20:30:48 +00:00
|
|
|
|
|
|
|
if code == d.OK:
|
2016-09-16 21:41:31 +00:00
|
|
|
k["title"] = elements[0]
|
|
|
|
k["klandrer"] = elements[1]
|
|
|
|
k["klandret"] = elements[2]
|
|
|
|
k["taber"] = elements[3]
|
|
|
|
save()
|
2016-09-16 20:41:46 +00:00
|
|
|
|
|
|
|
menu_klandringer()
|
|
|
|
|
2016-09-16 21:41:31 +00:00
|
|
|
def describe_klandring(strid):
|
|
|
|
id = int(strid)
|
|
|
|
k = klandringer[id]
|
|
|
|
code, text = d.editbox_str(k["description"],
|
|
|
|
height=0,
|
|
|
|
width=0,
|
|
|
|
title=k["klandrer"] + " v. " + k["klandret"] + " - " + k["title"])
|
|
|
|
|
|
|
|
if code == d.OK:
|
|
|
|
k["description"] = text
|
|
|
|
save()
|
|
|
|
|
|
|
|
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 21:41:31 +00:00
|
|
|
save()
|
2016-09-16 20:41:46 +00:00
|
|
|
|
2016-09-16 20:30:48 +00:00
|
|
|
menu_klandringer()
|
|
|
|
|
2016-09-16 21:41:31 +00:00
|
|
|
def save():
|
2016-09-16 20:41:46 +00:00
|
|
|
with open("klandringer.json","w") as jsonfile:
|
2016-09-16 21:41:31 +00:00
|
|
|
jsonfile.write(json.dumps(complete_klandringer))
|
2016-09-16 20:41:46 +00:00
|
|
|
|
2016-09-16 20:30:48 +00:00
|
|
|
# End klandringer
|
2016-09-16 21:41:31 +00:00
|
|
|
|
|
|
|
def new_date():
|
|
|
|
code, pickdate = d.calendar("Vælg en dato")
|
|
|
|
|
|
|
|
if code == d.OK:
|
|
|
|
date = str(pickdate[2]).zfill(4) + "-" + str(pickdate[1]).zfill(2) + "-" + str(pickdate[0]).zfill(2)
|
|
|
|
complete_klandringer[date] = []
|
|
|
|
save()
|
|
|
|
return date
|
|
|
|
else:
|
|
|
|
menu_select_date()
|
|
|
|
|
2016-09-16 20:30:48 +00:00
|
|
|
# End definitions
|
|
|
|
|
2016-09-16 21:41:31 +00:00
|
|
|
menu_select_date()
|
|
|
|
|
|
|
|
#menu_main()
|