Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 61 additions & 5 deletions tugui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class TuPostProcessingGui(tk.Tk):
. the plot area (right side) where the selected curves are shown
. a status bar (bottom window) showing log messages.
"""

# Flag stating if the output directory has been set directly
__is_dir_directly_set: bool = False

def __init__(self, window_title: str, width: int, height: int) -> None:
"""
App windows's constructor
Expand Down Expand Up @@ -358,6 +362,12 @@ def retrieve_simulation_info(self) -> None:
self.plireader = PliReader.init_PliReader(self.pli_entry.var.get())
print("Path to the .pli file: " + self.plireader.pli_path)

# Update the default directory of the file selection window and, if not
# already done, set the output directory to the one of the currently
# opened file
self.__set_directories_and_status_message(
self.plireader.pli_path, "Selected .pli file: ")

# Instantiate the MacReader class
self.macreader = MacReader(
os.path.dirname(self.plireader.pli_path) + os.sep + self.plireader.mac_path,
Expand Down Expand Up @@ -774,6 +784,16 @@ def select_output_folder(self, event: Union[tk.Event, None] = None) -> None:

# Update the output directory to the one currently selected
self.output_dir = foldername
# Update the output directory to the one currently selected
self.__is_dir_directly_set = True

# Provide a message to the status bar and to the log file
mssg = self.status_bar.label.cget('text').split(',')
if mssg[0]:
output_message = mssg[0] + ", Output folder: " + self.output_dir
else:
output_message = "Selected output folder: " + self.output_dir
self.status_bar.set_text(output_message)

print("Selected output folder:", self.output_dir)

Expand All @@ -796,11 +816,11 @@ def load_inp_file(self, event: Union[tk.Event, None] = None) -> None:

# Store the selected file as an instance attribute
self.loaded_inp_file = filename
# Change the start directory for the file selection window
self.initial_dir = os.path.dirname(filename)

# Provide a message to the status bar
self.status_bar.set_text("Selected .inp file: " + self.loaded_inp_file)
# Update the default directory of the file selection window and, if not
# already done, set the output directory to the one of the currently
# opened file
self.__set_directories_and_status_message(
self.loaded_inp_file, "Loaded .inp file: ")

# Generate the '<<InpLoaded>>' virtual event
self.event_generate('<<InpLoaded>>')
Expand Down Expand Up @@ -984,6 +1004,42 @@ def reset_main_window(self, event: Union[tk.Event, None] = None) -> None:
self.status_bar.set_text("")
# Re-build the plot tabs
self.build_tabs_area()
# Delete the output directory attribute, if any
if hasattr(self, 'output_dir'):
delattr(self, 'output_dir')

def __set_directories_and_status_message(
self, file_name: str, first_text: str) -> None:
"""
Method that updates the default directory of the file selection window
with the one of the currently loaded .pli or .inp file.
The same is performed for the output directory, if it has not already
been set directly by the user.
A descriptive message is assembled by prefixing it with the given string
and indicating the path of the output folder.
The status bar widget is updated with the assembled text.

Parameters
----------
file_name : str
The path of the selected file.
first_text : str
The first part of the text message shown in the status bar widget.
"""
# Update the default directory of the file selection window to the one of
# the currently opened file
self.initial_dir = os.path.dirname(file_name)
# If not already done, set the output directory to the one of the
# currently opened file
if not hasattr(self, 'output_dir') or not self.__is_dir_directly_set:
self.output_dir = self.initial_dir

# Provide a message to the status bar and to the log file
output_message = (first_text + file_name + ", Output folder: "
+ self.output_dir)
self.status_bar.set_text(output_message)
# FIXME: to print into log file
print(output_message)


def new_postprocessing(event: Union[tk.Event, None] = None) -> None:
Expand Down