Skip to content

Commit

Permalink
Updated saveSample/Sim/Summary with msg
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcurbelo committed Nov 19, 2024
1 parent 16c5b3c commit ce565c8
Showing 1 changed file with 64 additions and 6 deletions.
70 changes: 64 additions & 6 deletions GUI_GO.py
Original file line number Diff line number Diff line change
Expand Up @@ -8811,6 +8811,53 @@ def _loadFile(self):

self.activate_tab_1()

def notify_field_saved(self, field='workspace', success=True):
"""
Notify the user about the status of saving a given field with a temporary message.
:param field: The name of the entity (e.g., 'sample', 'workspace').
:param success: Whether the operation succeeded (True) or failed (False).
"""
# Set message and style based on success or failure
if success:
message_text = f"The {field.lower()} has been successfully saved!"
message_style = """
QLabel {
background-color: lightgreen; color: black; padding: 10px; border-radius: 5px;
}
"""
else:
message_text = f"Failed to save the {field.lower()}! Please check your inputs or run the simulation first."
message_style = """
QLabel {
background-color: orange; color: black; padding: 10px; border-radius: 5px;
}
"""

# Create and style the QLabel for the message
message_label = QLabel(message_text, self)
message_label.setStyleSheet(message_style)
message_label.setAlignment(Qt.AlignCenter)

# Set position dynamically based on the parent widget's size
if success:
width = 450 # Increased width to accommodate longer messages
else:
width = 600
height = 60
x = (self.width() - width) // 2
y = (self.height() - height) // 2
message_label.setGeometry(x, y, width, height)
message_label.show()

# Hide the message after 3 seconds
QTimer.singleShot(3000, message_label.deleteLater)

# Log the action in the terminal
if success:
print(f"The {field.lower()} has been successfully saved!")
else:
print(f"The {field.lower()} was not saved successfully! Please, check if you have to run any simulation before.")


def _loadSample(self):
"""
Expand Down Expand Up @@ -8954,8 +9001,8 @@ def _saveFile(self):
optParams = self._goWidget.goParameters # retrieve data fitting algorithm parameters

ds.saveFileHDF5(filename, self.sample, data_dict, fitParams, optParams, self.version) # save the information


self.notify_field_saved(field='workspace')

else:
# messageBox = QMessageBox()
Expand All @@ -8968,6 +9015,8 @@ def _saveFile(self):
self.saveSummary.setEnabled(False)

self.activate_tab_1()



def _saveAsFile(self):
"""
Expand Down Expand Up @@ -9023,6 +9072,8 @@ def _saveAsFile(self):

self.activate_tab_1()

self.notify_field_saved(field='workspace')

def _saveSimulation(self):
"""
Purpose: Calculate and save the simulation to the current file
Expand All @@ -9049,6 +9100,10 @@ def _saveSimulation(self):
if type(sim_dict) is not list:
ds.saveSimulationHDF5(self.fname, sim_dict, self.version)

self.notify_field_saved(field='simulation')
else:
self.notify_field_saved(field='simulation', success=False)

def _saveSample(self):
"""
Purpose: Save the sample information from the current project space
Expand All @@ -9063,6 +9118,8 @@ def _saveSample(self):
ds.WriteSampleHDF5(self.fname, self.sample, self.version)
self.activate_tab_1()

self.notify_field_saved(field='sample')

def _importDataSet(self):
"""
Purpose: import data from h5 filetype
Expand Down Expand Up @@ -9254,6 +9311,11 @@ def _summary(self):
file.write("localSearch = %s \n\n" % globOpt['dual annealing'][6])
file.close()

self.notify_field_saved(field='summary')

else:
self.notify_field_saved(field='summary', success=False)

def _exitApplication(self):
# exit the program
sys.exit()
Expand Down Expand Up @@ -9294,9 +9356,6 @@ def _preferences(self):
self.reflectivity_engine = userinput[0]
self.temperature = userinput[1]




def _license(self):
"""
Purpose: demonstrate license if ever obtained
Expand Down Expand Up @@ -9324,7 +9383,6 @@ def _userguide(self):

QDesktopServices.openUrl(QUrl.fromLocalFile(file_path))


def activate_tab_1(self):
# sample workspace
self.sample = copy.deepcopy(self._sampleWidget._createSample()) # get previous sample information from table
Expand Down

0 comments on commit ce565c8

Please sign in to comment.