klandr/klandr.py
Christoffer Müller Madsen 1dc57a051c tilføj beskrivelser og datoer
2016-09-16 23:41:31 +02:00

164 lines
5.0 KiB
Python
Executable File

#! /usr/bin/env python3
from dialog import Dialog
import json
d = Dialog(dialog="dialog")
d.set_background_title("Klandr")
klandringer = None
with open("klandringer.json", "r") as jsonfile:
contents = jsonfile.read()
if contents == "":
complete_klandringer = {}
else:
complete_klandringer = json.loads(contents)
# Begin definitions
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()
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():
code, tag = d.menu("Hvad du vil gøre med klandringerne?",
title="Klandringer",
choices=[("Ny", "Oprette en ny klandring"),
("Ændr", "Ændre en eksisterende klandring"),
("Beskriv", "Beskriv en eksisterende klandring"),
#("Omarrangér", "Omarrangere de eksisterende klandringer"),
("Slet", "Slette en eksisterende klandring")])
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 == "Beskriv":
describe_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":"","description":"","taber":""})
edit_klandring(-1)
def edit_klandring(strid):
id = int(strid)
k = klandringer[id]
code, elements = d.form("Ændr detaljer om klandring",
title="Ændr klandring",
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)])
if code == d.OK:
k["title"] = elements[0]
k["klandrer"] = elements[1]
k["klandret"] = elements[2]
k["taber"] = elements[3]
save()
menu_klandringer()
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()
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!")
save()
menu_klandringer()
def save():
with open("klandringer.json","w") as jsonfile:
jsonfile.write(json.dumps(complete_klandringer))
# End klandringer
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()
# End definitions
menu_select_date()
#menu_main()