implemented generation of multiples NSDs and spelling
This commit is contained in:
18
gui/gui.py
18
gui/gui.py
@@ -49,7 +49,7 @@ class Gui:
|
|||||||
sg.HSeparator(),
|
sg.HSeparator(),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
sg.Text('Optional choose custom font and name.'),
|
sg.Text('Optional: choose custom font and name.'),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
sg.Text('TTF File'),
|
sg.Text('TTF File'),
|
||||||
@@ -132,33 +132,33 @@ class Gui:
|
|||||||
|
|
||||||
output_path = values['-OUTPUT FOLDER-']
|
output_path = values['-OUTPUT FOLDER-']
|
||||||
if output_name is None:
|
if output_name is None:
|
||||||
sg.popup_auto_close('You dont set a name for the image, it will be named random.')
|
sg.popup_auto_close('You didn\'t set a name for the image, it will be named randomly.')
|
||||||
output_name = secrets.token_hex(16)
|
output_name = secrets.token_hex(16)
|
||||||
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 exists! Continue?', title='File alreday exists!')
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
fnames = output(values)
|
fnames = output(values)
|
||||||
sg.popup_annoying('Successful created!', title='Created',
|
sg.popup_annoying('Successfully created!', title='Created',
|
||||||
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.warning('There will be no image created.')
|
logging.warning('Cancelled. No image created')
|
||||||
else:
|
else:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
'You did not made a decision! Try again!')
|
'You did not make a decision! Try again!')
|
||||||
sg.popup_annoying('You did not made a decision! Try again!', title='FAIL',
|
sg.popup_annoying('You did not make a decision! Try again!', title='FAIL',
|
||||||
auto_close_duration=2, auto_close=True, text_color='orange')
|
auto_close_duration=2, auto_close=True, text_color='orange')
|
||||||
else:
|
else:
|
||||||
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)
|
||||||
|
|
||||||
fnames = output(values)
|
fnames = output(values)
|
||||||
sg.popup_annoying('Successful created!', title='Created',
|
sg.popup_annoying('Successfully created!', title='Created',
|
||||||
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)
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@ class Gui:
|
|||||||
|
|
||||||
if event == '-CREDITS-':
|
if event == '-CREDITS-':
|
||||||
sg.popup(
|
sg.popup(
|
||||||
'This is made by Plexx, Weckyy and Oleting. Used PySimpleGUI and Pillow', title='Credits')
|
'This was made by Plexx, Weckyy702 and Oleting. Libraries used are PySimpleGUI and Pillow', title='Credits')
|
||||||
|
|
||||||
if event == '-DONATE-':
|
if event == '-DONATE-':
|
||||||
logging.debug(('event = ' + str(event)))
|
logging.debug(('event = ' + str(event)))
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ from interpreter.NassiShneidermann import NassiShneidermanDiagram
|
|||||||
from draw.Iinstruction import *
|
from draw.Iinstruction import *
|
||||||
|
|
||||||
|
|
||||||
def nassi(filepath: str, output_path: str, outputname: str, gui, font_filepath: Optional[str]=None):
|
def nassi(input_path: str, output_path: str, outputname: str, gui, font_filepath: Optional[str]=None):
|
||||||
NSD = NassiShneidermanDiagram(gui.debug_mode)
|
NSD = NassiShneidermanDiagram(gui.debug_mode)
|
||||||
|
|
||||||
if font_filepath != None:
|
if font_filepath != None:
|
||||||
NSD.set_font(font_filepath)
|
NSD.set_font(font_filepath)
|
||||||
NSD.load_from_file(filepath)
|
|
||||||
NSD.convert_to_image((output_path + '/' + outputname), 500)
|
NSD.load_from_file(input_path)
|
||||||
|
NSD.convert_to_image(output_path, outputname, 500)
|
||||||
|
|
||||||
|
|
||||||
def output(values):
|
def output(values):
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import draw.code_to_image as cti
|
|||||||
class NassiShneidermanDiagram:
|
class NassiShneidermanDiagram:
|
||||||
|
|
||||||
def __init__(self, do_debug: bool):
|
def __init__(self, do_debug: bool):
|
||||||
self.instructions: List[Iinstruction] = []
|
self.scopes: List[List[Iinstruction]] = []
|
||||||
self.init_logging(do_debug)
|
self.init_logging(do_debug)
|
||||||
|
|
||||||
def init_logging(self, debug: bool):
|
def init_logging(self, debug: bool):
|
||||||
@@ -23,21 +23,24 @@ class NassiShneidermanDiagram:
|
|||||||
def set_font(self, font_filepath: str):
|
def set_font(self, font_filepath: str):
|
||||||
cti.set_font(font_filepath)
|
cti.set_font(font_filepath)
|
||||||
|
|
||||||
def _get_image_height(self) -> int:
|
def _get_image_height(self, scope_index: int) -> int:
|
||||||
h = 0
|
h = 0
|
||||||
for inst in self.instructions:
|
for inst in self.scopes[scope_index]:
|
||||||
h += inst.getblksize()
|
h += inst.getblksize()
|
||||||
return int(h)
|
return int(h)
|
||||||
|
|
||||||
def convert_to_image(self, filepath: str, x_size: int=200):
|
def convert_to_image(self, output_path: str, filename: str, x_size: int=200):
|
||||||
image_y_sz = self._get_image_height()
|
for i in range(len(self.scopes)):
|
||||||
logging.info(f"Saving NSD to {filepath}.png...")
|
filepath = f"{output_path}/{filename}#{i}"
|
||||||
with NSD_writer(filepath, x_size, image_y_sz):
|
logging.info(f"Saving NSD to {filepath}.png...")
|
||||||
x, y = 0, 0
|
|
||||||
|
|
||||||
for instruction in self.instructions:
|
image_y_sz = self._get_image_height(i)
|
||||||
x, y = instruction.to_image(x, y, x_size)
|
with NSD_writer(filepath, x_size, image_y_sz):
|
||||||
logging.info("Done!")
|
scope = self.scopes[i]
|
||||||
|
x, y = 0, 0
|
||||||
|
for instruction in scope:
|
||||||
|
x, y = instruction.to_image(x, y, x_size)
|
||||||
|
logging.info("Done!")
|
||||||
|
|
||||||
def load_from_file(self, filepath:str):
|
def load_from_file(self, filepath:str):
|
||||||
self.instructions = itp.load_instructions(filepath)
|
self.scopes = itp.load_instructions(filepath)
|
||||||
@@ -3,7 +3,7 @@ from os import remove
|
|||||||
import re
|
import re
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
from errors.custom import JavaSyntaxError, ScopeNotFoundException
|
from errors.custom import InterpreterException, JavaSyntaxError, ScopeNotFoundException
|
||||||
from draw.Iinstruction import *
|
from draw.Iinstruction import *
|
||||||
|
|
||||||
COMMENT_PATTERN = re.compile(r"""^//|^/\*\*|^\*|^--""")
|
COMMENT_PATTERN = re.compile(r"""^//|^/\*\*|^\*|^--""")
|
||||||
@@ -20,7 +20,7 @@ remove_pattern = re.compile("|".join(REPLACE.keys()))
|
|||||||
variable_regex = "^("
|
variable_regex = "^("
|
||||||
for kw in FUNCTION_IDENTIFIERS:
|
for kw in FUNCTION_IDENTIFIERS:
|
||||||
variable_regex += fr"""{kw}|"""
|
variable_regex += fr"""{kw}|"""
|
||||||
variable_pattern = re.compile(variable_regex[0:-1]+"$(.*)")
|
variable_pattern = re.compile(variable_regex[0:-1]+")$(.*)")
|
||||||
|
|
||||||
function_regex = "^("
|
function_regex = "^("
|
||||||
for kw in FUNCTION_IDENTIFIERS:
|
for kw in FUNCTION_IDENTIFIERS:
|
||||||
|
|||||||
Reference in New Issue
Block a user