diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba0430d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6e0fa0a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Aktuelle Datei", + "type": "python", + "request": "launch", + "program": "gui.py", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/NassiShneidermann.py b/NassiShneidermann.py index a5f3d67..766e210 100644 --- a/NassiShneidermann.py +++ b/NassiShneidermann.py @@ -39,25 +39,39 @@ class NassiShneidermanDiagram: if line and not re.match(r"""^//|^#|^COMMENT|^--""", line): lines.append(line) except: - logging.error(f"Failed to open input path {filepath}!") + logging.error(f"Failed to open input file {filepath}!") return lines def load_from_file(self, filepath: str): filtered_lines = self.load_code_lines(filepath) - print(filtered_lines) - num_brace + global_scope = [] + current_scope = global_scope for line in filtered_lines: - if line.startswith("while("): + logging.debug(line) + if line.__contains__('}'): + current_scope.append("scope exit") + current_scope = global_scope[-1] # does not get correct parent scope + #TODO: get correct parent scope + if line.__contains__('{'): + current_scope.append("scope enter") + current_scope.append([]) + current_scope = current_scope[-1] + + elif not line.__contains__('}'): + current_scope.append("generic instruction") + print(global_scope) + + + -if __name__ == "__main__": - """for debugging""" - +"""if __name__ == "__main__": + #for debugging from Iinstruction import * NSD = NassiShneidermanDiagram(True) NSD.load_from_file("res/input/input.java") - NSD.convert_to_image("Nina", 500) + NSD.convert_to_image("Nina", 500)""" diff --git a/README.md b/README.md index 2a6b19f..ee43f6a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # Nassi-Shneiderman-Diagramm-Generator This python code generates a Nassi Shneiderman Diagramm from Java Source Code + + +How it works: +In the final Version, you will just have to execute the nassi.exe and choose your Code, it will display the Nassi-Shneiderman-Diagramm and give you the path of the created picture. \ No newline at end of file diff --git a/gui.py b/gui.py index 5a6064f..d3a438e 100644 --- a/gui.py +++ b/gui.py @@ -1,7 +1,11 @@ +from to_nassi import nassi + import PySimpleGUI as sg import os.path +#sg.theme_previewer() + java_file_list_column = [ [ sg.Text('Java Folder'), @@ -46,7 +50,7 @@ layout = [ ] ] -window = sg.Window('Nassi Viewer', layout) +window = sg.Window('Nassi Viewer', layout, resizable=True) while True: event, values = window.read() @@ -78,7 +82,6 @@ while True: pass if event == '-JAVA FOLDER-': folder = values['-JAVA FOLDER-'] - print(folder) try: file_list = os.listdir(folder) except: @@ -90,7 +93,17 @@ while True: and f.lower().endswith(('.java', '.txt')) ] window['-JAVA FILE LIST-'].update(fnames) - - + elif event == '-JAVA FILE LIST-': + try: + filename = os.path.join( + values["-JAVA FOLDER-"], values["-JAVA FILE LIST-"][0] + ) + + window["-TOUT-"].update(filename) + nassi(filename) + + except: + pass + window.close() diff --git a/to_nassi.py b/to_nassi.py new file mode 100644 index 0000000..239e579 --- /dev/null +++ b/to_nassi.py @@ -0,0 +1,8 @@ +from NassiShneidermann import NassiShneidermanDiagram +from Iinstruction import * + + +def nassi(filepath): + NSD = NassiShneidermanDiagram(True) + NSD.load_from_file(filepath) + NSD.convert_to_image("Nina", 500) \ No newline at end of file