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,11 +2,27 @@ 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)
def get_debug_mode(self, mode: bool):
loging_level = logging.INFO
if mode:
loging_level = logging.DEBUG
logging.basicConfig(level=loging_level)
def init_gui(self, theme: str):
self.get_debug_mode(self.debug_mode)
sg.theme(theme)
logging.info(('Theme = ' + theme))
java_file_list_column = [ java_file_list_column = [
[ [
@@ -16,6 +32,7 @@ def gui():
'*.*')), key='-JAVA FILE-'), # ('ALL Files','*.*') '*.*')), key='-JAVA FILE-'), # ('ALL Files','*.*')
], ],
] ]
logging.info('set java_file_list_column GUI')
file_list_column = [ file_list_column = [
[ [
@@ -29,18 +46,21 @@ def gui():
) )
], ],
] ]
logging.info('set file_list_column GUI')
diagramm_viewer_column = [ diagramm_viewer_column = [
[sg.Text("Choose your Code for preview. ", size=(100, 10))], [sg.Text("Choose your Code for preview. ", size=(100, 10))],
[sg.Text(size=(40, 1), key="-TOUT-")], [sg.Text(size=(40, 1), key="-TOUT-")],
[sg.Image(key='-IMAGE-')], [sg.Image(key='-IMAGE-')],
] ]
logging.info('set diagramm_viewer_column GUI')
buttons_column = [ buttons_column = [
[sg.Button(button_text='Create Image', key='-CREATE-')], [sg.Button(button_text='Create Image', key='-CREATE-')],
# * fun feature # * fun feature
[sg.Button(button_text='Donate', key='-DONATE-')], [sg.Button(button_text='Donate', key='-DONATE-')],
] ]
logging.info('set buttons_column GUI')
layout = [ layout = [
[ [
@@ -53,22 +73,32 @@ def gui():
sg.Column(diagramm_viewer_column), sg.Column(diagramm_viewer_column),
] ]
] ]
logging.info('init layout GUI')
window = sg.Window('Nassi Viewer', layout, resizable=True) window = sg.Window('Nassi Viewer', layout, resizable=True)
return window
def show_gui(self, window: sg.Window):
while True: while True:
event, values = window.read() event, values = window.read()
if event == 'Exit' or event == sg.WIN_CLOSED: if event == 'Exit' or event == sg.WIN_CLOSED:
logging.info(('event = ' + str(event)))
break break
if event == '-DONATE-': if event == '-DONATE-':
logging.info(('event = ' + str(event)))
sg.popup_notify( sg.popup_notify(
('You donated $' + str(random.randint(500, 100000000)) + '.'), title='Thanks') ('You donated $' + str(random.randint(500, 100000000)) + '.'), title='Thanks')
if event == '-OUTPUT FOLDER-': if event == '-OUTPUT FOLDER-':
logging.info(('event = ' + str(event) +
' value = ' + str(values['-OUTPUT FOLDER-'])))
fnames = output(values) fnames = output(values)
window['-OUTPUT FILE LIST-'].update(fnames) window['-OUTPUT FILE LIST-'].update(fnames)
elif event == '-OUTPUT FILE LIST-': elif event == '-OUTPUT FILE LIST-':
logging.info(('event = ' + str(event) +
' value = ' + str(values['-OUTPUT FILE LIST-'])))
try: try:
filename = os.path.join( filename = os.path.join(
values["-OUTPUT FOLDER-"], values["-OUTPUT FILE LIST-"][0] values["-OUTPUT FOLDER-"], values["-OUTPUT FILE LIST-"][0]
@@ -78,12 +108,18 @@ def gui():
except: except:
pass pass
if event == '-JAVA FOLDER-': if event == '-JAVA FOLDER-':
logging.info(('event = ' + str(event) +
' value = ' + str(values['-JAVA FOLDER-'])))
folder = values['-JAVA FOLDER-'] folder = values['-JAVA FOLDER-']
window['-JAVA FOLDER-'].update(values['-JAVA FILE-']) window['-JAVA FOLDER-'].update(values['-JAVA FILE-'])
elif event == '-CREATE-': elif event == '-CREATE-':
logging.info(('event = ' + str(event) +
'values = ' + str(values)))
try: try:
if values['-JAVA FOLDER-'] and values['-OUTPUT FOLDER-']: if values['-JAVA FOLDER-'] and values['-OUTPUT FOLDER-']:
logging.info(
('Try create Image with values = ' + str(values)))
try: try:
file_path = os.path.join( file_path = os.path.join(
values["-JAVA FOLDER-"], values["-JAVA FOLDER-"],
@@ -97,17 +133,20 @@ def gui():
title='Created') title='Created')
except: except:
logging.error(
('Failed to create Image with values = ' + str(values)))
pass pass
elif values['-JAVA FOLDER-']: elif values['-JAVA FOLDER-']:
print('No Output') logging.error('No Output')
sg.popup_annoying('No Output', title='Error', sg.popup_annoying('No Output', title='Error',
auto_close_duration=5, auto_close=True) auto_close_duration=5, auto_close=True)
elif values['-OUTPUT FOLDER-']: elif values['-OUTPUT FOLDER-']:
print('No Input') logging.error('No Input')
sg.popup_annoying('No Input', title='Error', sg.popup_annoying('No Input', title='Error',
auto_close_duration=5, auto_close=True) auto_close_duration=5, auto_close=True)
else: else:
logging.error('Unexpected Case!')
sg.popup_annoying('Unexpected Case!', title='Error') sg.popup_annoying('Unexpected Case!', title='Error')
except: except:
pass pass

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)