add folder input
This commit is contained in:
68
gui/gui.py
68
gui/gui.py
@@ -5,7 +5,7 @@
|
|||||||
__author__ = "oleting"
|
__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 gui.new_window_layouts import Layout_std, Layout_settings
|
||||||
from errors.custom import JavaSyntaxError, ScopeNotFoundException, InterpreterException, NoPathError
|
from errors.custom import JavaSyntaxError, ScopeNotFoundException, InterpreterException, NoPathError
|
||||||
from interpreter.NassiShneidermann import OB
|
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.')
|
'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)
|
||||||
|
|
||||||
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)
|
font_filepath=font_filepath, behaviour=exists_choice, types=types, remove_tags=modifier, comments=comments)
|
||||||
|
|
||||||
if file_is_empty:
|
if file_is_empty:
|
||||||
sg.popup_annoying('Our interpreter did not find anything. --> blame Kons or yourself!', title='Empty')
|
sg.popup_annoying('Our interpreter did not find anything. --> blame Kons or yourself!', title='Empty')
|
||||||
if path:
|
if path:
|
||||||
fnames = output(path)
|
fnames = filter_folder(path)
|
||||||
sg.popup_annoying('Successfully 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)
|
||||||
else:
|
else:
|
||||||
fnames = output(output_path, output_name)
|
fnames = filter_folder(output_path, output_name)
|
||||||
sg.popup_annoying('There are some images created!', title='Cancel',
|
sg.popup_annoying('There are some images created!', title='Cancel',
|
||||||
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)
|
||||||
@@ -147,6 +147,62 @@ class Gui:
|
|||||||
except:
|
except:
|
||||||
raise
|
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-']:
|
elif values['-JAVA IN-']:
|
||||||
sg.popup_annoying('No Output', title='Error',
|
sg.popup_annoying('No Output', title='Error',
|
||||||
auto_close_duration=5, auto_close=True)
|
auto_close_duration=5, auto_close=True)
|
||||||
@@ -172,7 +228,7 @@ class Gui:
|
|||||||
try:
|
try:
|
||||||
logging.debug(('event = ' + str(event) +
|
logging.debug(('event = ' + str(event) +
|
||||||
' value = ' + str(values['-OUTPUT FOLDER-'])))
|
' value = ' + str(values['-OUTPUT FOLDER-'])))
|
||||||
fnames = output(values['-OUTPUT FOLDER-'])
|
fnames = filter_folder(values['-OUTPUT FOLDER-'])
|
||||||
window['-OUTPUT FILE LIST-'].update(fnames)
|
window['-OUTPUT FILE LIST-'].update(fnames)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(str(e))
|
logging.error(str(e))
|
||||||
@@ -256,7 +312,7 @@ class Gui:
|
|||||||
# handle event REFRESH
|
# handle event REFRESH
|
||||||
if event == '-REFRESH-':
|
if event == '-REFRESH-':
|
||||||
try:
|
try:
|
||||||
fnames = output(values['-OUTPUT FOLDER-'])
|
fnames = filter_folder(values['-OUTPUT FOLDER-'])
|
||||||
window['-OUTPUT FILE LIST-'].update(fnames)
|
window['-OUTPUT FILE LIST-'].update(fnames)
|
||||||
except NoPathError:
|
except NoPathError:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ class Layout_std:
|
|||||||
sg.FileBrowse(file_types=(('Java-File', '*.java'), ('ALL Files',
|
sg.FileBrowse(file_types=(('Java-File', '*.java'), ('ALL Files',
|
||||||
'*.*')), key='-JAVA FILE-'),
|
'*.*')), 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.Text('Output Folder'),
|
||||||
sg.In(size=(25, 1), enable_events=True, key="-OUTPUT FOLDER-"),
|
sg.In(size=(25, 1), enable_events=True, key="-OUTPUT FOLDER-"),
|
||||||
|
|||||||
18
gui/utils.py
18
gui/utils.py
@@ -14,7 +14,7 @@ import os
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
#types=types, remove_tages=modifier, comments=comments
|
#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)
|
NSD = NassiShneidermanDiagram(gui.debug_mode)
|
||||||
output_directory = check_and_create_output_directory(output_path + '/' + outputname)
|
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
|
return output_directory
|
||||||
|
|
||||||
|
def filter_folder(path, name=None, ends_with=('.png', '.gif')):
|
||||||
|
|
||||||
|
if path == '':
|
||||||
def output(output_path, output_name=None):
|
|
||||||
|
|
||||||
if output_path == '':
|
|
||||||
raise NoPathError
|
raise NoPathError
|
||||||
if output_name:
|
if name:
|
||||||
output_path = output_path + '/' + output_name
|
path = path + '/' + name
|
||||||
try:
|
try:
|
||||||
file_list = os.listdir(output_path)
|
file_list = os.listdir(path)
|
||||||
except:
|
except:
|
||||||
file_list = []
|
file_list = []
|
||||||
fnames = [
|
fnames = [
|
||||||
f
|
f
|
||||||
for f in file_list
|
for f in file_list
|
||||||
if os.path.isfile(os.path.join(output_path, f))
|
if os.path.isfile(os.path.join(path, f))
|
||||||
and f.lower().endswith(('.png', '.gif'))
|
and f.lower().endswith(ends_with)
|
||||||
]
|
]
|
||||||
return fnames
|
return fnames
|
||||||
Reference in New Issue
Block a user