From 6bc6e63fd8d6d1dec4c9ef0a4b625819587a7540 Mon Sep 17 00:00:00 2001 From: oleting Date: Sun, 27 Dec 2020 19:47:20 +0100 Subject: [PATCH] + warning overwrite --- errors/__init__.py | 0 errors/custom.py | 8 ++++++++ gui/gui.py | 25 ++++++++++++++++--------- gui/utils.py | 20 ++++++++++++++++---- interpreter/interpret_source.py | 10 +--------- 5 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 errors/__init__.py create mode 100644 errors/custom.py diff --git a/errors/__init__.py b/errors/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/errors/custom.py b/errors/custom.py new file mode 100644 index 0000000..0d95315 --- /dev/null +++ b/errors/custom.py @@ -0,0 +1,8 @@ +class InterpreterError(Exception): + pass + +class JavaSyntaxError(Exception): + pass + +class ScopeNotFoundException(Exception): + pass diff --git a/gui/gui.py b/gui/gui.py index d2d48d8..26047d0 100644 --- a/gui/gui.py +++ b/gui/gui.py @@ -1,4 +1,4 @@ -from gui.utils import nassi, output +from gui.utils import nassi, output, file_there from interpreter.interpret_source import JavaSyntaxError, ScopeNotFoundException import PySimpleGUI as sg @@ -147,17 +147,24 @@ class Gui: file_path = os.path.join( values["-JAVA FOLDER-"], ) - output_path = values['-OUTPUT FOLDER-'] - nassi(filepath=file_path, output_path=output_path, outputname=output_name, gui=self, - font_filepath=font_filepath) - - fnames = output(values) - sg.popup_annoying('Successful created!', title='Created', - auto_close_duration=2, auto_close=True, text_color='green') - window['-OUTPUT FILE LIST-'].update(fnames) + output_path = values['-OUTPUT FOLDER-'] + + if file_there((output_path + '/' + output_name)) is False: + proceed = sg.popup_yes_no('File already exist! Continue?', title='File alreday exist!') + print(proceed) + if proceed == 'Yes': + nassi(filepath=file_path, output_path=output_path, outputname=output_name, gui=self, + font_filepath=font_filepath) + + fnames = output(values) + sg.popup_annoying('Successful created!', title='Created', + auto_close_duration=2, auto_close=True, text_color='green') + window['-OUTPUT FILE LIST-'].update(fnames) + else: + pass except JavaSyntaxError as JsE: logging.error( ('||SyntaxError in Java File|| Failed to create Image with values = ' + str(values))) diff --git a/gui/utils.py b/gui/utils.py index 6618e3d..534025c 100644 --- a/gui/utils.py +++ b/gui/utils.py @@ -4,17 +4,19 @@ import os from interpreter.NassiShneidermann import NassiShneidermanDiagram from draw.Iinstruction import * -def nassi(filepath:str, output_path: str, outputname, gui, font_filepath=None): + +def nassi(filepath: str, output_path: str, outputname, gui, font_filepath=None): NSD = NassiShneidermanDiagram(gui.debug_mode) - #if font_filepath is None: + # if font_filepath is None: # pass - #else: - #if font_filepath is not None or font_filepath != "": + # else: + # if font_filepath is not None or font_filepath != "": if font_filepath != None: NSD.set_font(str(font_filepath)) NSD.load_from_file(filepath) NSD.convert_to_image(output_path, outputname, 500) + def output(values): output_path = values['-OUTPUT FOLDER-'] try: @@ -28,3 +30,13 @@ def output(values): and f.lower().endswith(('.png', '.gif')) ] return fnames + + +def file_there(file): + try: + open((file + '.png')) + return False + except FileNotFoundError: + return True + except: + return False diff --git a/interpreter/interpret_source.py b/interpreter/interpret_source.py index 441e81a..65ba5bb 100644 --- a/interpreter/interpret_source.py +++ b/interpreter/interpret_source.py @@ -3,17 +3,9 @@ from os import remove import re from typing import Callable, List, Tuple +from errors.custom import InterpreterError, JavaSyntaxError, ScopeNotFoundException from draw.Iinstruction import * -class InterpreterError(Exception): - pass - -class JavaSyntaxError(Exception): - pass - -class ScopeNotFoundException(Exception): - pass - COMMENT_REGEX = r"""^//|^#|^COMMENT|^--""" REMOVE_KEYWORDS = [' ', "public", "private", "void", ';']