+ use class and logging

This commit is contained in:
oleting
2020-12-26 10:53:11 +01:00
parent e8962c7497
commit 039a8489b3
3 changed files with 130 additions and 98 deletions

View File

@@ -2,11 +2,25 @@ 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.get_debug_mode(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):
sg.theme(theme)
logging.info(('Theme = ' + theme))
java_file_list_column = [
[
@@ -16,6 +30,7 @@ def gui():
'*.*')), key='-JAVA FILE-'), # ('ALL Files','*.*')
],
]
logging.info('set java_file_list_column GUI')
file_list_column = [
[
@@ -29,18 +44,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 +71,30 @@ 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, theme: str, 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 +104,15 @@ 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 +126,19 @@ 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,6 +4,7 @@ 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
class NassiShneidermanDiagram:

2
run.py
View File

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