This commit is contained in:
weckyy702
2020-12-26 14:39:30 +01:00
3 changed files with 138 additions and 98 deletions

View File

@@ -2,114 +2,153 @@ from gui.utils import nassi, output
import PySimpleGUI as sg import PySimpleGUI as sg
import os.path import os.path
import random import random
import logging
def gui(): class gui:
sg.theme('DarkGrey11') def __init__(self, theme: str, debug_mode: bool):
self.debug_mode = debug_mode
window = self.init_gui(theme=theme)
self.show_gui(window=window)
java_file_list_column = [ def get_debug_mode(self, mode: bool):
[ loging_level = logging.INFO
sg.Text('Java File'), if mode:
sg.In(size=(25, 1), enable_events=True, key="-JAVA FOLDER-"), loging_level = logging.DEBUG
sg.FileBrowse(file_types=(('Java-File', '*.java'), ('ALL Files', logging.basicConfig(level=loging_level)
'*.*')), key='-JAVA FILE-'), # ('ALL Files','*.*')
],
]
file_list_column = [ def init_gui(self, theme: str):
[ self.get_debug_mode(self.debug_mode)
sg.Text('Output Folder'),
sg.In(size=(25, 1), enable_events=True, key="-OUTPUT FOLDER-"),
sg.FolderBrowse(),
],
[
sg.Listbox(
values=[], enable_events=True, size=(40, 20), key="-OUTPUT FILE LIST-"
)
],
]
diagramm_viewer_column = [ sg.theme(theme)
[sg.Text("Choose your Code for preview. ", size=(100, 10))], logging.info(('Theme = ' + theme))
[sg.Text(size=(40, 1), key="-TOUT-")],
[sg.Image(key='-IMAGE-')],
]
buttons_column = [ java_file_list_column = [
[sg.Button(button_text='Create Image', key='-CREATE-')], [
# * fun feature sg.Text('Java File'),
[sg.Button(button_text='Donate', key='-DONATE-')], 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','*.*')
layout = [ ],
[
sg.Column(java_file_list_column),
sg.VSeparator(),
sg.Column(file_list_column),
sg.VSeparator(),
sg.Column(buttons_column),
sg.VSeparator(),
sg.Column(diagramm_viewer_column),
] ]
] logging.info('set java_file_list_column GUI')
window = sg.Window('Nassi Viewer', layout, resizable=True) file_list_column = [
[
while True: sg.Text('Output Folder'),
event, values = window.read() sg.In(size=(25, 1), enable_events=True, key="-OUTPUT FOLDER-"),
if event == 'Exit' or event == sg.WIN_CLOSED: sg.FolderBrowse(),
break ],
[
if event == '-DONATE-': sg.Listbox(
sg.popup_notify( values=[], enable_events=True, size=(40, 20), key="-OUTPUT FILE LIST-"
('You donated $' + str(random.randint(500, 100000000)) + '.'), title='Thanks')
if event == '-OUTPUT FOLDER-':
fnames = output(values)
window['-OUTPUT FILE LIST-'].update(fnames)
elif event == '-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: logging.info('set file_list_column GUI')
pass
if event == '-JAVA FOLDER-':
folder = values['-JAVA FOLDER-']
window['-JAVA FOLDER-'].update(values['-JAVA FILE-'])
elif event == '-CREATE-': diagramm_viewer_column = [
try: [sg.Text("Choose your Code for preview. ", size=(100, 10))],
if values['-JAVA FOLDER-'] and values['-OUTPUT FOLDER-']: [sg.Text(size=(40, 1), key="-TOUT-")],
try: [sg.Image(key='-IMAGE-')],
file_path = os.path.join( ]
values["-JAVA FOLDER-"], logging.info('set diagramm_viewer_column GUI')
)
output_path = values['-OUTPUT FOLDER-']
nassi(file_path, output_path)
fnames = output(values) buttons_column = [
window['-OUTPUT FILE LIST-'].update(fnames) [sg.Button(button_text='Create Image', key='-CREATE-')],
sg.popup_notify('Succsessful created!', # * fun feature
title='Created') [sg.Button(button_text='Donate', key='-DONATE-')],
]
logging.info('set buttons_column GUI')
except: layout = [
pass [
sg.Column(java_file_list_column),
sg.VSeparator(),
sg.Column(file_list_column),
sg.VSeparator(),
sg.Column(buttons_column),
sg.VSeparator(),
sg.Column(diagramm_viewer_column),
]
]
logging.info('init layout GUI')
elif values['-JAVA FOLDER-']: window = sg.Window('Nassi Viewer', layout, resizable=True)
print('No Output') return window
sg.popup_annoying('No Output', title='Error',
auto_close_duration=5, auto_close=True)
elif values['-OUTPUT FOLDER-']:
print('No Input')
sg.popup_annoying('No Input', title='Error',
auto_close_duration=5, auto_close=True)
else:
sg.popup_annoying('Unexpected Case!', title='Error')
except:
pass
window.close() def show_gui(self, window: sg.Window):
while True:
event, values = window.read()
if event == 'Exit' or event == sg.WIN_CLOSED:
logging.info(('event = ' + str(event)))
break
if event == '-DONATE-':
logging.info(('event = ' + str(event)))
sg.popup_notify(
('You donated $' + str(random.randint(500, 100000000)) + '.'), title='Thanks')
if event == '-OUTPUT FOLDER-':
logging.info(('event = ' + str(event) +
' value = ' + str(values['-OUTPUT FOLDER-'])))
fnames = output(values)
window['-OUTPUT FILE LIST-'].update(fnames)
elif event == '-OUTPUT FILE LIST-':
logging.info(('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.info(('event = ' + str(event) +
' value = ' + str(values['-JAVA FOLDER-'])))
folder = values['-JAVA FOLDER-']
window['-JAVA FOLDER-'].update(values['-JAVA FILE-'])
elif event == '-CREATE-':
logging.info(('event = ' + str(event) +
'values = ' + str(values)))
try:
if values['-JAVA FOLDER-'] and values['-OUTPUT FOLDER-']:
logging.info(
('Try create Image with values = ' + str(values)))
try:
file_path = os.path.join(
values["-JAVA FOLDER-"],
)
output_path = values['-OUTPUT FOLDER-']
nassi(file_path, output_path)
fnames = output(values)
window['-OUTPUT FILE LIST-'].update(fnames)
sg.popup_notify('Succsessful created!',
title='Created')
except:
logging.error(
('Failed to create Image with values = ' + str(values)))
pass
elif values['-JAVA FOLDER-']:
logging.error('No Output')
sg.popup_annoying('No Output', title='Error',
auto_close_duration=5, auto_close=True)
elif values['-OUTPUT FOLDER-']:
logging.error('No Input')
sg.popup_annoying('No Input', title='Error',
auto_close_duration=5, auto_close=True)
else:
logging.error('Unexpected Case!')
sg.popup_annoying('Unexpected Case!', title='Error')
except:
pass
window.close()

View File

@@ -4,13 +4,14 @@ import logging
from draw.Iinstruction import Iinstruction from draw.Iinstruction import Iinstruction
from interpreter import interpret_source as itp from interpreter import interpret_source as itp
from draw import code_to_image as cti from draw import code_to_image as cti
from gui.gui import gui
class NassiShneidermanDiagram: class NassiShneidermanDiagram:
def __init__(self, debug: bool=False) -> None: def __init__(self, debug: bool=False) -> None:
self.instructions: dict[str, Iinstruction] = {} self.instructions: dict[str, Iinstruction] = {}
self.init_logging(debug) self.init_logging(gui.debug_mode)
def init_logging(self, debug: bool): def init_logging(self, debug: bool):
logLevel = logging.INFO logLevel = logging.INFO

2
run.py
View File

@@ -1,3 +1,3 @@
from gui.gui import gui from gui.gui import gui
gui() gui(theme='DarkGrey11', debug_mode=True)