From 1dc57a051c46a0f687bee59b37b8f5100c6a8d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Fri, 16 Sep 2016 23:41:31 +0200 Subject: [PATCH] =?UTF-8?q?tilf=C3=B8j=20beskrivelser=20og=20datoer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- klandr.py | 88 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/klandr.py b/klandr.py index 08581ce..e65739c 100755 --- a/klandr.py +++ b/klandr.py @@ -5,12 +5,36 @@ 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"}] -with open("klandringer.json", "r") as jsonfile: - klandringer = json.loads(jsonfile.read()) +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", @@ -34,6 +58,7 @@ def menu_klandringer(): 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")]) @@ -47,6 +72,8 @@ def menu_klandringer(): if klandring != None: if tag == "Ændr": edit_klandring(klandring) + elif tag == "Beskriv": + describe_klandring(klandring) elif tag == "Slet": delete_klandring(klandring) else: @@ -61,26 +88,43 @@ def menu_select_klandring(): return tag def create_klandring(): - klandringer.append({"klandrer":"","klandret":"","title":""}) + 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,klandringer[id]["title"],1,11,40,40), - ("Klandrer:",2,1,klandringer[id]["klandrer"],2,11,20,20), - ("Klandret:",3,1,klandringer[id]["klandret"],3,11,20,20)]) + 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: - klandringer[id]["title"] = elements[0] - klandringer[id]["klandrer"] = elements[1] - klandringer[id]["klandret"] = elements[2] - save_klandringer() + 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) @@ -91,15 +135,29 @@ def delete_klandring(strid): if code == d.OK: del klandringer[id] d.msgbox("Klandringen er slettet!") - save_klandringer() + save() menu_klandringer() -def save_klandringer(): +def save(): with open("klandringer.json","w") as jsonfile: - jsonfile.write(json.dumps(klandringer)) + 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_main() +menu_select_date() + +#menu_main()