This commit is contained in:
weckyy702
2020-12-27 22:22:24 +01:00
6 changed files with 56 additions and 49 deletions

Binary file not shown.

View File

@@ -116,6 +116,6 @@ def draw_while_loop_back(condition: str, x: int, y: int, xsize: int, ysize: int)
#the x, y offset then the x,y draw size (the canvas) #the x, y offset then the x,y draw size (the canvas)
return x + xsize * .1, y, xsize * .9 return x + xsize * .1, y, xsize * .9
def NSD_save(filepath: str, filename: str): def NSD_save(filepath: str):
"""Save the created file""" """Save the created file"""
img.save(filepath + '/' + filename + datei_endung ,"PNG") img.save(filepath + datei_endung ,"PNG")

View File

@@ -1,9 +1,8 @@
import draw.code_to_image as cti import draw.code_to_image as cti
class NSD_writer(object): class NSD_writer(object):
def __init__(self, filepath: str, filename: str, x_sz: int, y_sz: int) -> None: def __init__(self, filepath: str, x_sz: int, y_sz: int) -> None:
self.filepath = filepath self.filepath = filepath
self.filename = filename
self.x_sz = x_sz self.x_sz = x_sz
self.y_sz = y_sz self.y_sz = y_sz
@@ -11,4 +10,4 @@ class NSD_writer(object):
cti.NSD_init(self.x_sz, self.y_sz) cti.NSD_init(self.x_sz, self.y_sz)
def __exit__(self, _, __, ___): def __exit__(self, _, __, ___):
cti.NSD_save(self.filepath, self.filename) cti.NSD_save(self.filepath)

View File

@@ -32,7 +32,7 @@ class Gui:
sg.Text('Java File'), sg.Text('Java File'),
sg.In(size=(25, 1), enable_events=True, key="-JAVA FOLDER-"), sg.In(size=(25, 1), enable_events=True, key="-JAVA FOLDER-"),
sg.FileBrowse(file_types=(('Java-File', '*.java'), ('ALL Files', sg.FileBrowse(file_types=(('Java-File', '*.java'), ('ALL Files',
'*.*')), key='-JAVA FILE-'), # ('ALL Files','*.*') '*.*')), key='-JAVA FILE-'),
], ],
[ [
sg.Text('Output Folder'), sg.Text('Output Folder'),
@@ -43,17 +43,18 @@ class Gui:
sg.HSeparator(), sg.HSeparator(),
], ],
[ [
sg.Text('Optional choose custom font'), sg.Text('Optional choose custom font and name.'),
], ],
[ [
sg.Text('TTF File'), sg.Text('TTF File'),
sg.In(size=(25, 1), enable_events=True, key="-TTF FOLDER-"), sg.In(size=(25, 1), enable_events=True, key="-TTF FOLDER-"),
sg.FileBrowse(file_types=(('TTF-File', '*.ttf'), ('ALL Files', sg.FileBrowse(file_types=(('TTF-File', '*.ttf'), ('ALL Files',
'*.*')), key='-TTF FILE-'), # ('ALL Files','*.*') '*.*')), key='-TTF FILE-'),
], ],
[ [
sg.Text('Output name'), sg.Text('Output name'),
sg.In(size=(25, 1), enable_events=True), sg.In(size=(25, 1), enable_events=True, key='-OUTPUT NAME-'),
sg.Button('Done', key='-SET OUTPUT NAME-'),
], ],
] ]
@@ -91,7 +92,6 @@ class Gui:
sg.VSeparator(), sg.VSeparator(),
sg.Column(file_list_column), sg.Column(file_list_column),
sg.VSeparator(), sg.VSeparator(),
sg.Column(diagramm_viewer_column), sg.Column(diagramm_viewer_column),
] ]
] ]
@@ -111,41 +111,12 @@ class Gui:
while True: while True:
logging.info('test') logging.info('test')
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.debug(('Exit GUI')) logging.debug(('Exit GUI'))
break break
if event == '-CREDITS-': # execute Column
sg.popup(
'This is made by Plexx, Weckyy and Oleting. Used PySimpleGUI and Pillow', title='Credits')
if event == '-DONATE-':
logging.debug(('event = ' + str(event)))
sg.popup_notify(
('You donated $' + str(random.randint(500, 100000000)) + '.'), title='Thanks')
if event == '-OUTPUT FOLDER-':
logging.debug(('event = ' + str(event) +
' value = ' + str(values['-OUTPUT FOLDER-'])))
fnames = output(values)
window['-OUTPUT FILE LIST-'].update(fnames)
elif event == '-OUTPUT FILE LIST-':
logging.debug(('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.debug(('event = ' + str(event) +
' value = ' + str(values['-JAVA FOLDER-'])))
folder = values['-JAVA FOLDER-']
window['-JAVA FOLDER-'].update(values['-JAVA FILE-'])
if event == '-CREATE-': if event == '-CREATE-':
logging.debug(('event = ' + str(event) + logging.debug(('event = ' + str(event) +
'values = ' + str(values))) 'values = ' + str(values)))
@@ -163,7 +134,6 @@ class Gui:
if file_there((output_path + '/' + output_name)) is True: if file_there((output_path + '/' + output_name)) is True:
proceed = sg.popup_yes_no( proceed = sg.popup_yes_no(
'File already exist! Continue?', title='File alreday exist!') 'File already exist! Continue?', title='File alreday exist!')
print(proceed)
if proceed == 'Yes': if proceed == 'Yes':
nassi(filepath=file_path, output_path=output_path, outputname=output_name, gui=self, nassi(filepath=file_path, output_path=output_path, outputname=output_name, gui=self,
font_filepath=font_filepath) font_filepath=font_filepath)
@@ -173,8 +143,7 @@ class Gui:
auto_close_duration=2, auto_close=True, text_color='green') auto_close_duration=2, auto_close=True, text_color='green')
window['-OUTPUT FILE LIST-'].update(fnames) window['-OUTPUT FILE LIST-'].update(fnames)
elif proceed == 'No': elif proceed == 'No':
logging.error('test') logging.warning('There will be no image created.')
pass
else: else:
logging.warning( logging.warning(
'You did not made a decision! Try again!') 'You did not made a decision! Try again!')
@@ -222,6 +191,45 @@ class Gui:
except: except:
pass pass
if event == '-CREDITS-':
sg.popup(
'This is made by Plexx, Weckyy and Oleting. Used PySimpleGUI and Pillow', title='Credits')
if event == '-DONATE-':
logging.debug(('event = ' + str(event)))
sg.popup_notify(
('You donated $' + str(random.randint(500, 100000000)) + '.'), title='Thanks')
# needed Input
if event == '-OUTPUT FOLDER-':
logging.debug(('event = ' + str(event) +
' value = ' + str(values['-OUTPUT FOLDER-'])))
fnames = output(values)
window['-OUTPUT FILE LIST-'].update(fnames)
elif event == '-OUTPUT FILE LIST-':
logging.debug(('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.debug(('event = ' + str(event) +
' value = ' + str(values['-JAVA FOLDER-'])))
folder = values['-JAVA FOLDER-']
window['-JAVA FOLDER-'].update(values['-JAVA FILE-'])
# optional Input
if event == '-SET OUTPUT NAME-':
output_name = values['-OUTPUT NAME-']
if event == '-TTF FOLDER-': if event == '-TTF FOLDER-':
logging.debug(('event = ' + str(event) + logging.debug(('event = ' + str(event) +
' value = ' + str(values['-TTF FOLDER-']))) ' value = ' + str(values['-TTF FOLDER-'])))

View File

@@ -12,7 +12,7 @@ def nassi(filepath: str, output_path: str, outputname: str, gui, font_filepath:
if font_filepath != None: if font_filepath != None:
NSD.set_font(font_filepath) NSD.set_font(font_filepath)
NSD.load_from_file(filepath) NSD.load_from_file(filepath)
NSD.convert_to_image(output_path, outputname, 500) NSD.convert_to_image((output_path + '/' + outputname), 500)
def output(values): def output(values):

View File

@@ -29,10 +29,10 @@ class NassiShneidermanDiagram:
h += inst.getblksize() h += inst.getblksize()
return int(h) return int(h)
def convert_to_image(self, filepath: str, filename: str, x_size: int=200): def convert_to_image(self, filepath: str, x_size: int=200):
image_y_sz = self._get_image_height() image_y_sz = self._get_image_height()
logging.info(f"Saving NSD to {filename}.png...") logging.info(f"Saving NSD to {filepath}.png...")
with NSD_writer(filepath, filename, x_size, image_y_sz): with NSD_writer(filepath, x_size, image_y_sz):
x, y = 0, 0 x, y = 0, 0
for instruction in self.instructions: for instruction in self.instructions: