From 38cf99f9531d4dc39a15b3ccbbee29e9cb34d926 Mon Sep 17 00:00:00 2001 From: oleting Date: Wed, 30 Dec 2020 16:29:40 +0100 Subject: [PATCH] . --- gui/gui.py | 11 +++++------ gui/utils.py | 30 +++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/gui/gui.py b/gui/gui.py index d1724ce..b31ad71 100644 --- a/gui/gui.py +++ b/gui/gui.py @@ -83,7 +83,6 @@ class Gui: [ sg.Text('Output name'), sg.In(size=(25, 1), enable_events=True, key='-OUTPUT NAME-'), - sg.Button('Confirm', key='-SET OUTPUT NAME-'), ], [ sg.HSeparator(), @@ -212,10 +211,10 @@ class Gui: 'You didn\'t set a name for the image, it will be named randomly.') output_name = secrets.token_hex(16) - nassi(input_path=file_path, output_path=output_path, outputname=output_name, gui=self, + folder = nassi(input_path=file_path, output_path=output_path, outputname=output_name, gui=self, font_filepath=font_filepath, behaviour=exists_choice) - fnames = output(values) + fnames = output(folder=folder) sg.popup_annoying('Successfully created!', title='Created', auto_close_duration=2, auto_close=True, text_color='green') window['-OUTPUT FILE LIST-'].update(fnames) @@ -271,7 +270,7 @@ class Gui: if event == '-OUTPUT FOLDER-': logging.debug(('event = ' + str(event) + ' value = ' + str(values['-OUTPUT FOLDER-']))) - fnames = output(values) + fnames = output(values['-OUTPUT FOLDER-']) window['-OUTPUT FILE LIST-'].update(fnames) elif event == '-OUTPUT FILE LIST-': logging.debug(('event = ' + str(event) + @@ -300,7 +299,7 @@ class Gui: # optional Input - if event == '-SET OUTPUT NAME-': + if event == '-OUTPUT NAME-': output_name = values['-OUTPUT NAME-'] if event == '-TTF FOLDER-': @@ -314,7 +313,7 @@ class Gui: if event == '-REFRESH-': try: - fnames = output(values) + fnames = output(values['-OUTPUT FOLDER-']) window['-OUTPUT FILE LIST-'].update(fnames) except NoPathError: pass diff --git a/gui/utils.py b/gui/utils.py index d24f1ad..6e5b8e0 100644 --- a/gui/utils.py +++ b/gui/utils.py @@ -1,22 +1,38 @@ -import os -from typing import Optional - from errors.custom import NoPathError from interpreter.NassiShneidermann import NassiShneidermanDiagram, Overwrite_behaviour, OB -from draw.Iinstruction import * + +from typing import Optional +import os +import logging + def nassi(input_path: str, output_path: str, outputname: str, gui, behaviour: Overwrite_behaviour, font_filepath: Optional[str]=None): NSD = NassiShneidermanDiagram(gui.debug_mode) + directory = output_path + '/' + outputname if font_filepath != None: NSD.set_font(font_filepath) + + try: + if not os.path.exists(directory): + os.makedirs(directory) + except OSError: + logging.error('Error: Creating directory. ' + directory) + except: + raise NSD.load_from_file(input_path) - NSD.convert_to_image(output_path, outputname, on_conflict=behaviour, x_size=750) + NSD.convert_to_image(directory, on_conflict=behaviour, x_size=750) + + return directory -def output(values): - output_path = values['-OUTPUT FOLDER-'] +def output(folder): + if folder: + output_path = folder + else: + raise + if output_path == '': raise NoPathError try: