add folder input

This commit is contained in:
oleting
2021-02-10 16:16:34 +01:00
parent 555143dba1
commit 28eef05d88
3 changed files with 75 additions and 16 deletions

View File

@@ -5,7 +5,7 @@
__author__ = "oleting"
from gui.utils import nassi, output
from gui.utils import nassi_file, filter_folder
from gui.new_window_layouts import Layout_std, Layout_settings
from errors.custom import JavaSyntaxError, ScopeNotFoundException, InterpreterException, NoPathError
from interpreter.NassiShneidermann import OB
@@ -108,18 +108,18 @@ class Gui:
'You didn\'t set a name for the image, it will be named randomly.')
output_name = secrets.token_hex(16)
path, file_is_empty = nassi(input_path=file_path, output_path=output_path, outputname=output_name, gui=self,
path, file_is_empty = nassi_file(input_path=file_path, output_path=output_path, outputname=output_name, gui=self,
font_filepath=font_filepath, behaviour=exists_choice, types=types, remove_tags=modifier, comments=comments)
if file_is_empty:
sg.popup_annoying('Our interpreter did not find anything. --> blame Kons or yourself!', title='Empty')
if path:
fnames = output(path)
fnames = filter_folder(path)
sg.popup_annoying('Successfully created!', title='Created',
auto_close_duration=2, auto_close=True, text_color='green')
window['-OUTPUT FILE LIST-'].update(fnames)
else:
fnames = output(output_path, output_name)
fnames = filter_folder(output_path, output_name)
sg.popup_annoying('There are some images created!', title='Cancel',
auto_close_duration=2, auto_close=True, text_color='green')
window['-OUTPUT FILE LIST-'].update(fnames)
@@ -146,6 +146,62 @@ class Gui:
sg.popup_error(('Failed to create an image of one function correctly. ' + str(e)) + 'There may be some images created. ')
except:
raise
elif values['-INPUT FOLDER-'] and values['-OUTPUT FOLDER-']:
logging.debug(
('Try create Image with values = ' + str(values)))
try:
folder_path = os.path.join(
values['-INPUT FOLDER-'],
)
output_path = values['-OUTPUT FOLDER-']
if output_name is None:
sg.popup_auto_close(
'You didn\'t set a name for the image, it will be named randomly.')
output_name = secrets.token_hex(16)
for n_file in filter_folder(folder_path, ends_with='.java'):
path, file_is_empty = nassi_file(input_path=folder_path + "/" + n_file, output_path=output_path, outputname=output_name, gui=self,
font_filepath=font_filepath, behaviour=exists_choice, types=types, remove_tags=modifier, comments=comments)
if file_is_empty:
sg.popup_annoying('Our interpreter did not find anything. --> blame Kons or yourself!', title='Empty')
if path:
fnames = filter_folder(path)
sg.popup_annoying('Successfully created!', title='Created',
auto_close_duration=2, auto_close=True, text_color='green')
window['-OUTPUT FILE LIST-'].update(fnames)
else:
fnames = filter_folder(output_path, output_name)
sg.popup_annoying('There are some images created!', title='Cancel',
auto_close_duration=2, auto_close=True, text_color='green')
window['-OUTPUT FILE LIST-'].update(fnames)
except JavaSyntaxError as JsE:
logging.error(
('||SyntaxError in Java File|| Failed to create Image with values = ' + str(values)))
sg.popup_error(str(JsE))
except ScopeNotFoundException as SnFe:
logging.error(
('||ScopeNotFoundExeption|| Failed to create Image with values = ' + str(values)))
sg.popup_error(str(SnFe))
except FileNotFoundError as FnFe:
logging.error(
('||FileNotFoundError|| Failed to create Image with values = ' + str(values)))
sg.popup_error(
(str(FnFe) + 'File ' + str(file_path) + ' or ' + str(output_path) + ' or ' + str(font_filepath) + ' is not reachable.'))
except InterpreterException:
logging.error(
('||InterpreterException|| Failed to create Image with values = ' + str(values)))
except Exception as e:
logging.error(
('Failed to create Image with values = ' + str(values)) + str(e))
sg.popup_error(('Failed to create an image of one function correctly. ' + str(e)) + 'There may be some images created. ')
except:
raise
elif values['-JAVA IN-']:
sg.popup_annoying('No Output', title='Error',
@@ -172,7 +228,7 @@ class Gui:
try:
logging.debug(('event = ' + str(event) +
' value = ' + str(values['-OUTPUT FOLDER-'])))
fnames = output(values['-OUTPUT FOLDER-'])
fnames = filter_folder(values['-OUTPUT FOLDER-'])
window['-OUTPUT FILE LIST-'].update(fnames)
except Exception as e:
logging.error(str(e))
@@ -256,7 +312,7 @@ class Gui:
# handle event REFRESH
if event == '-REFRESH-':
try:
fnames = output(values['-OUTPUT FOLDER-'])
fnames = filter_folder(values['-OUTPUT FOLDER-'])
window['-OUTPUT FILE LIST-'].update(fnames)
except NoPathError:
pass