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

View File

@@ -25,6 +25,11 @@ class Layout_std:
sg.FileBrowse(file_types=(('Java-File', '*.java'), ('ALL Files',
'*.*')), key='-JAVA FILE-'),
],
[
sg.Text('Input Folder'),
sg.In(size=(25, 1), enable_events=True, key="-INPUT FOLDER-"),
sg.FolderBrowse(),
],
[
sg.Text('Output Folder'),
sg.In(size=(25, 1), enable_events=True, key="-OUTPUT FOLDER-"),

View File

@@ -14,7 +14,7 @@ import os
import logging
#types=types, remove_tages=modifier, comments=comments
def nassi(input_path: str, output_path: str, outputname: str, types, remove_tags, comments, gui, behaviour: Overwrite_behaviour, font_filepath: Optional[str]=None):
def nassi_file(input_path: str, output_path: str, outputname: str, types, remove_tags, comments, gui, behaviour: Overwrite_behaviour, font_filepath: Optional[str]=None):
NSD = NassiShneidermanDiagram(gui.debug_mode)
output_directory = check_and_create_output_directory(output_path + '/' + outputname)
@@ -43,22 +43,20 @@ def check_and_create_output_directory(output_directory):
return output_directory
def output(output_path, output_name=None):
def filter_folder(path, name=None, ends_with=('.png', '.gif')):
if output_path == '':
if path == '':
raise NoPathError
if output_name:
output_path = output_path + '/' + output_name
if name:
path = path + '/' + name
try:
file_list = os.listdir(output_path)
file_list = os.listdir(path)
except:
file_list = []
fnames = [
f
for f in file_list
if os.path.isfile(os.path.join(output_path, f))
and f.lower().endswith(('.png', '.gif'))
if os.path.isfile(os.path.join(path, f))
and f.lower().endswith(ends_with)
]
return fnames