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 os.path
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 = [
[
@@ -16,6 +32,7 @@ def gui():
'*.*')), key='-JAVA FILE-'), # ('ALL Files','*.*')
],
]
logging.info('set java_file_list_column GUI')
file_list_column = [
[
@@ -29,18 +46,21 @@ def gui():
)
],
]
logging.info('set file_list_column GUI')
diagramm_viewer_column = [
[sg.Text("Choose your Code for preview. ", size=(100, 10))],
[sg.Text(size=(40, 1), key="-TOUT-")],
[sg.Image(key='-IMAGE-')],
]
logging.info('set diagramm_viewer_column GUI')
buttons_column = [
[sg.Button(button_text='Create Image', key='-CREATE-')],
# * fun feature
[sg.Button(button_text='Donate', key='-DONATE-')],
]
logging.info('set buttons_column GUI')
layout = [
[
@@ -53,22 +73,32 @@ def gui():
sg.Column(diagramm_viewer_column),
]
]
logging.info('init layout GUI')
window = sg.Window('Nassi Viewer', layout, resizable=True)
return window
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]
@@ -78,12 +108,18 @@ def gui():
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-"],
@@ -97,17 +133,20 @@ def gui():
title='Created')
except:
logging.error(
('Failed to create Image with values = ' + str(values)))
pass
elif values['-JAVA FOLDER-']:
print('No Output')
logging.error('No Output')
sg.popup_annoying('No Output', title='Error',
auto_close_duration=5, auto_close=True)
elif values['-OUTPUT FOLDER-']:
print('No Input')
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

View File

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

2
run.py
View File

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