diff --git a/Nassi-Shneiderman-Diagramm-Generator-1.exe b/Nassi-Shneiderman-Diagramm-Generator-1.exe new file mode 100644 index 0000000..2901601 Binary files /dev/null and b/Nassi-Shneiderman-Diagramm-Generator-1.exe differ diff --git a/draw/code_to_image.py b/draw/code_to_image.py index 4ede92b..19d2e26 100644 --- a/draw/code_to_image.py +++ b/draw/code_to_image.py @@ -116,6 +116,6 @@ def draw_while_loop_back(condition: str, x: int, y: int, xsize: int, ysize: int) #the x, y offset then the x,y draw size (the canvas) return x + xsize * .1, y, xsize * .9 -def NSD_save(filepath: str, filename: str): +def NSD_save(filepath: str): """Save the created file""" - img.save(filepath + '/' + filename + datei_endung ,"PNG") \ No newline at end of file + img.save(filepath + datei_endung ,"PNG") \ No newline at end of file diff --git a/draw/code_to_image_wrapper.py b/draw/code_to_image_wrapper.py index 4def001..b65896f 100644 --- a/draw/code_to_image_wrapper.py +++ b/draw/code_to_image_wrapper.py @@ -1,9 +1,8 @@ import draw.code_to_image as cti class NSD_writer(object): - def __init__(self, filepath: str, filename: str, x_sz: int, y_sz: int) -> None: + def __init__(self, filepath: str, x_sz: int, y_sz: int) -> None: self.filepath = filepath - self.filename = filename self.x_sz = x_sz self.y_sz = y_sz @@ -11,4 +10,4 @@ class NSD_writer(object): cti.NSD_init(self.x_sz, self.y_sz) def __exit__(self, _, __, ___): - cti.NSD_save(self.filepath, self.filename) \ No newline at end of file + cti.NSD_save(self.filepath) \ No newline at end of file diff --git a/gui/gui.py b/gui/gui.py index 01ca9a5..1e078d0 100644 --- a/gui/gui.py +++ b/gui/gui.py @@ -32,7 +32,7 @@ class Gui: sg.Text('Java File'), sg.In(size=(25, 1), enable_events=True, key="-JAVA FOLDER-"), sg.FileBrowse(file_types=(('Java-File', '*.java'), ('ALL Files', - '*.*')), key='-JAVA FILE-'), # ('ALL Files','*.*') + '*.*')), key='-JAVA FILE-'), ], [ sg.Text('Output Folder'), @@ -43,17 +43,18 @@ class Gui: sg.HSeparator(), ], [ - sg.Text('Optional choose custom font'), + sg.Text('Optional choose custom font and name.'), ], [ sg.Text('TTF File'), sg.In(size=(25, 1), enable_events=True, key="-TTF FOLDER-"), sg.FileBrowse(file_types=(('TTF-File', '*.ttf'), ('ALL Files', - '*.*')), key='-TTF FILE-'), # ('ALL Files','*.*') + '*.*')), key='-TTF FILE-'), ], [ sg.Text('Output name'), - sg.In(size=(25, 1), enable_events=True), + sg.In(size=(25, 1), enable_events=True, key='-OUTPUT NAME-'), + sg.Button('Done', key='-SET OUTPUT NAME-'), ], ] @@ -91,7 +92,6 @@ class Gui: sg.VSeparator(), sg.Column(file_list_column), sg.VSeparator(), - sg.Column(diagramm_viewer_column), ] ] @@ -111,41 +111,12 @@ class Gui: while True: logging.info('test') event, values = window.read() + if event == 'Exit' or event == sg.WIN_CLOSED: logging.debug(('Exit GUI')) break - - if event == '-CREDITS-': - sg.popup( - 'This is made by Plexx, Weckyy and Oleting. Used PySimpleGUI and Pillow', title='Credits') - - if event == '-DONATE-': - logging.debug(('event = ' + str(event))) - sg.popup_notify( - ('You donated $' + str(random.randint(500, 100000000)) + '.'), title='Thanks') - - if event == '-OUTPUT FOLDER-': - logging.debug(('event = ' + str(event) + - ' value = ' + str(values['-OUTPUT FOLDER-']))) - fnames = output(values) - window['-OUTPUT FILE LIST-'].update(fnames) - elif event == '-OUTPUT FILE LIST-': - logging.debug(('event = ' + str(event) + - ' value = ' + str(values['-OUTPUT FILE LIST-']))) - try: - filename = os.path.join( - values["-OUTPUT FOLDER-"], values["-OUTPUT FILE LIST-"][0] - ) - window["-TOUT-"].update(filename) - window["-IMAGE-"].update(filename=filename) - except: - pass - if event == '-JAVA FOLDER-': - logging.debug(('event = ' + str(event) + - ' value = ' + str(values['-JAVA FOLDER-']))) - folder = values['-JAVA FOLDER-'] - window['-JAVA FOLDER-'].update(values['-JAVA FILE-']) - + + # execute Column if event == '-CREATE-': logging.debug(('event = ' + str(event) + 'values = ' + str(values))) @@ -163,7 +134,6 @@ class Gui: if file_there((output_path + '/' + output_name)) is True: 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) @@ -173,8 +143,7 @@ class Gui: auto_close_duration=2, auto_close=True, text_color='green') window['-OUTPUT FILE LIST-'].update(fnames) elif proceed == 'No': - logging.error('test') - pass + logging.warning('There will be no image created.') else: logging.warning( 'You did not made a decision! Try again!') @@ -222,6 +191,45 @@ class Gui: except: pass + if event == '-CREDITS-': + sg.popup( + 'This is made by Plexx, Weckyy and Oleting. Used PySimpleGUI and Pillow', title='Credits') + + if event == '-DONATE-': + logging.debug(('event = ' + str(event))) + sg.popup_notify( + ('You donated $' + str(random.randint(500, 100000000)) + '.'), title='Thanks') + + # needed Input + + if event == '-OUTPUT FOLDER-': + logging.debug(('event = ' + str(event) + + ' value = ' + str(values['-OUTPUT FOLDER-']))) + fnames = output(values) + window['-OUTPUT FILE LIST-'].update(fnames) + elif event == '-OUTPUT FILE LIST-': + logging.debug(('event = ' + str(event) + + ' value = ' + str(values['-OUTPUT FILE LIST-']))) + try: + filename = os.path.join( + values["-OUTPUT FOLDER-"], values["-OUTPUT FILE LIST-"][0] + ) + window["-TOUT-"].update(filename) + window["-IMAGE-"].update(filename=filename) + except: + pass + + if event == '-JAVA FOLDER-': + logging.debug(('event = ' + str(event) + + ' value = ' + str(values['-JAVA FOLDER-']))) + folder = values['-JAVA FOLDER-'] + window['-JAVA FOLDER-'].update(values['-JAVA FILE-']) + + # optional Input + + if event == '-SET OUTPUT NAME-': + output_name = values['-OUTPUT NAME-'] + if event == '-TTF FOLDER-': logging.debug(('event = ' + str(event) + ' value = ' + str(values['-TTF FOLDER-']))) diff --git a/gui/utils.py b/gui/utils.py index a2ca460..13d20aa 100644 --- a/gui/utils.py +++ b/gui/utils.py @@ -12,7 +12,7 @@ def nassi(filepath: str, output_path: str, outputname: str, gui, font_filepath: if font_filepath != None: NSD.set_font(font_filepath) NSD.load_from_file(filepath) - NSD.convert_to_image(output_path, outputname, 500) + NSD.convert_to_image((output_path + '/' + outputname), 500) def output(values): diff --git a/interpreter/NassiShneidermann.py b/interpreter/NassiShneidermann.py index 03e3c7e..6ad95a3 100644 --- a/interpreter/NassiShneidermann.py +++ b/interpreter/NassiShneidermann.py @@ -29,10 +29,10 @@ class NassiShneidermanDiagram: h += inst.getblksize() return int(h) - def convert_to_image(self, filepath: str, filename: str, x_size: int=200): + def convert_to_image(self, filepath: str, x_size: int=200): image_y_sz = self._get_image_height() - logging.info(f"Saving NSD to {filename}.png...") - with NSD_writer(filepath, filename, x_size, image_y_sz): + logging.info(f"Saving NSD to {filepath}.png...") + with NSD_writer(filepath, x_size, image_y_sz): x, y = 0, 0 for instruction in self.instructions: