From 7c809ac711b4bc1c708c3ebf702c49a6cc03f699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Fri, 16 Sep 2016 23:58:04 +0200 Subject: [PATCH] =?UTF-8?q?tilf=C3=B8j=20batch=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- klandr.py | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/klandr.py b/klandr.py index e65739c..599de85 100755 --- a/klandr.py +++ b/klandr.py @@ -49,7 +49,8 @@ def menu_main(): menu_klandringer() elif tag == "Afsluttende": menu_afsluttende() - + else: + quit() # Begin klandringer @@ -60,13 +61,16 @@ def menu_klandringer(): ("Ændr", "Ændre en eksisterende klandring"), ("Beskriv", "Beskriv en eksisterende klandring"), #("Omarrangér", "Omarrangere de eksisterende klandringer"), - ("Slet", "Slette en eksisterende klandring")]) + ("Slet", "Slette en eksisterende klandring"), + ("Batch", "Gå i batch-mode")]) if code == d.CANCEL: menu_main() elif code == d.OK: if tag == "Ny": create_klandring() + elif tag == "Batch": + batch_mode() else: klandring = menu_select_klandring() if klandring != None: @@ -76,8 +80,8 @@ def menu_klandringer(): describe_klandring(klandring) elif tag == "Slet": delete_klandring(klandring) - else: - menu_klandringer() + + menu_klandringer() def menu_select_klandring(): klandringer_entries = [(str(i),k["klandrer"] + " v. " + k["klandret"] + " - " + k["title"]) for i,k in enumerate(klandringer)] @@ -89,7 +93,7 @@ def menu_select_klandring(): def create_klandring(): klandringer.append({"klandrer":"","klandret":"","title":"","description":"","taber":""}) - edit_klandring(-1) + return edit_klandring(-1) def edit_klandring(strid): @@ -108,8 +112,9 @@ def edit_klandring(strid): k["klandret"] = elements[2] k["taber"] = elements[3] save() - - menu_klandringer() + + return code + def describe_klandring(strid): id = int(strid) @@ -122,9 +127,8 @@ def describe_klandring(strid): if code == d.OK: k["description"] = text save() - - menu_klandringer() - + + return code def delete_klandring(strid): id = int(strid) @@ -136,13 +140,23 @@ def delete_klandring(strid): del klandringer[id] d.msgbox("Klandringen er slettet!") save() - - menu_klandringer() + return code + +def batch_mode(): + #code = create_klandring() + for i,k in enumerate(klandringer): + code = describe_klandring(i) + if code != d.OK: + break + code = edit_klandring(i) + if code != d.OK: + break + def save(): with open("klandringer.json","w") as jsonfile: jsonfile.write(json.dumps(complete_klandringer)) - + # End klandringer def new_date(): @@ -155,7 +169,8 @@ def new_date(): return date else: menu_select_date() - + + # End definitions menu_select_date()