diff --git a/BraceletGenerator/bicolore.py b/BraceletGenerator/bicolore.py index eff737a..6315a8c 100755 --- a/BraceletGenerator/bicolore.py +++ b/BraceletGenerator/bicolore.py @@ -29,13 +29,6 @@ from BraceletGenerator.about import About from BraceletGenerator.scrollbar import AutoScrollbar as Scrollbar - -BICOLOR_LOG = os.path.join(LOCAL_PATH, "Bicolor%i.log") -i = 0 -while os.path.exists(BICOLOR_LOG % (i)): - i += 1 -BICOLOR_LOG %= i - class Bicolore(Toplevel): """ classe de l'application éditeur de motif bicolore """ def __init__(self, master, row_nb=10, string_nb=8, diff --git a/BraceletGenerator/bracelet.py b/BraceletGenerator/bracelet.py index ce0fc9d..e953403 100755 --- a/BraceletGenerator/bracelet.py +++ b/BraceletGenerator/bracelet.py @@ -33,14 +33,6 @@ from BraceletGenerator.bicolore import Bicolore from BraceletGenerator.about import About - -BRACELET_LOG = os.path.join(LOCAL_PATH, "BraceletGenerator%i.log") -i = 0 -while os.path.exists(BRACELET_LOG % (i)): - i += 1 -BRACELET_LOG %= i -TMP_PS = os.path.join(LOCAL_PATH,".tmp.ps") - class Bracelet(Tk): """ patron de bracelet brésilien """ diff --git a/BraceletGenerator/constantes.py b/BraceletGenerator/constantes.py index f91317b..0a37460 100755 --- a/BraceletGenerator/constantes.py +++ b/BraceletGenerator/constantes.py @@ -62,16 +62,33 @@ if not os.path.exists(LOCAL_PATH): os.mkdir(LOCAL_PATH) +# bracelet log file +BRACELET_LOG = os.path.join(LOCAL_PATH, "BraceletGenerator%i.log") +i = 0 +while os.path.exists(BRACELET_LOG % (i)): + i += 1 +BRACELET_LOG %= i + +# temporary file +TMP_PS = os.path.join(LOCAL_PATH,".tmp.ps") + +# bicolore log file +BICOLOR_LOG = os.path.join(LOCAL_PATH, "Bicolor%i.log") +i = 0 +while os.path.exists(BICOLOR_LOG % (i)): + i += 1 +BICOLOR_LOG %= i + PATH_CONFIG = os.path.join(LOCAL_PATH, 'BraceletGenerator.ini') -# configuration file +# configuration file CONFIG = ConfigParser() if os.path.exists(PATH_CONFIG): CONFIG.read(PATH_CONFIG) LANGUE = CONFIG.get("General","language") else: LANGUE = "" - + CONFIG.add_section("General") CONFIG.set("General", "last_path", LOCAL_PATH) CONFIG.set("General", "recent_files", "") diff --git a/bracelet-generator b/bracelet-generator index 34478f8..216550d 100755 --- a/bracelet-generator +++ b/bracelet-generator @@ -22,14 +22,18 @@ main import sys import os -from BraceletGenerator.constantes import CONFIG +from BraceletGenerator.constantes import CONFIG, BRACELET_LOG, BICOLOR_LOG, save_config from BraceletGenerator.bracelet import Bracelet -if len(sys.argv) == 1: - Bracelet(string_nb=CONFIG.getint("Bracelet", "string_nb"), - row_nb=CONFIG.getint("Bracelet", "row_nb"), - color=CONFIG.get("Bracelet", "default_color")) -else: - fichier = os.path.realpath(sys.argv[1]) - Bracelet(fichier=fichier) - +try: + if len(sys.argv) == 1: + Bracelet(string_nb=CONFIG.getint("Bracelet", "string_nb"), + row_nb=CONFIG.getint("Bracelet", "row_nb"), + color=CONFIG.get("Bracelet", "default_color")) + else: + fichier = os.path.realpath(sys.argv[1]) + Bracelet(fichier=fichier) +finally: # remove logs even if the app crashed to avoid accumulation + os.remove(BRACELET_LOG) + os.remove(BICOLOR_LOG) + save_config()