Skip to content

Commit 6f35b87

Browse files
author
Ezequiel Torres
committed
Fix in closeButton in ExperimentInProgress Window
* We were not asking or cancelling the experiment when the close butto was pressed in the ExperimentInProgress Window
1 parent 0bfdaf0 commit 6f35b87

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

MLC/GUI/Experiment/ExperimentInProgress.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ def __init__(self, parent, parent_signal, chart_params, from_gen, to_gen):
147147

148148
# Condition variable used to check when the experiment has been stopped or cancelled
149149
self._experiment_condition = ExperimentCondition()
150+
self._simulation_has_finished = False
151+
152+
def closeEvent(self, event):
153+
logger.debug('[EXPERIMENT_IN_PROGRESS] [CLOSE_DIALOG] - Executing overriden closeEvent function')
154+
if not self._simulation_has_finished:
155+
if not self.on_cancel_button_clicked():
156+
event.ignore()
150157

151158
def add_experiment_data(self, amount_gens, indivs_per_gen):
152159
self._amount_gens = amount_gens
@@ -167,9 +174,14 @@ def on_cancel_button_clicked(self):
167174
QMessageBox.No)
168175

169176
if response == QMessageBox.Yes:
177+
170178
self._experiment_condition.cancel_experiment()
179+
# Set the MainWindow to invisible to not see the it after press 'Yes'
180+
self.setVisible(False)
181+
return True
171182
else:
172183
self._experiment_condition.continue_experiment()
184+
return False
173185

174186
def _update_dialog(self, indivs_per_gen_counter, total_indivs_counter, gen_counter, cost):
175187
logger.debug('{0} [UPDATE_EXP_IN_PROGRESS] - Executing update_dialog function'.format(self._log_prefix))
@@ -192,6 +204,8 @@ def _simulation_finished(self):
192204
logger.debug('{0} [SIM_FINISHED] - Executing _simulation_finished function'.format(self._log_prefix))
193205
self._parent_signal.emit(self._experiment_condition.experiment_cancelled(),
194206
self._experiment_condition.experiment_failure())
207+
self._simulation_has_finished = True
208+
self.close()
195209

196210
def _update_current_gen_experiment(self, indiv_index, cost):
197211
if cost > self._chart_params["max_cost"]:
@@ -249,19 +263,20 @@ def _create_new_chart(self):
249263
def _board_setup_failure(self, error):
250264
logger.debug('{0} [SIM_FINISHED] - Board setup failure: {1}'.format(self._log_prefix, error))
251265
selection = QMessageBox.critical(self, "Board Setup error",
252-
error,
253-
QMessageBox.Ok)
266+
error,
267+
QMessageBox.Ok)
254268
self._experiment_condition.cancel_experiment()
255269
self._simulation_finished()
256270

257271
def _board_io_error(self, error):
258272
logger.debug('{0} [SIM_FINISHED] - Board IO error: {1}'.format(self._log_prefix, error))
259273
selection = QMessageBox.critical(self, "Board IO error",
260-
error,
261-
QMessageBox.Ok)
274+
error,
275+
QMessageBox.Ok)
262276
self._experiment_condition.cancel_experiment()
263277
self._simulation_finished()
264278

279+
265280
class ExperimentInProgress(Thread):
266281

267282
def __init__(self, mlc_local, experiment_name,
@@ -362,8 +377,6 @@ def simulation_started(self):
362377
def simulation_finished(self):
363378
logger.debug('{0} [SIM_FINISHED] - Executing simulation_finished function'.format(self._log_prefix))
364379
self._dialog.simulation_finished.emit()
365-
366-
def close_window(self):
367380
self._dialog.close()
368381

369382
def _check_if_project_stopped_or_cancelled(self):

MLC/GUI/Experiment/ExperimentWindow.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,17 @@ def __init__(self, mlc_local,
130130
self._board_config, self._serial_conn = mlc_local.get_board_configuration(self._experiment_name)
131131

132132
def closeEvent(self, event):
133-
logger.debug('[EXPERIMENT {0}] [CLOSE_DIALOG] - Executing overriden closeEvent function'.format(self._experiment_name))
133+
logger.debug('[EXPERIMENT {0}] [CLOSE_DIALOG] - Executing overriden closeEvent function'
134+
.format(self._experiment_name))
134135
self._ask_if_experiment_config_must_be_saved()
135136
# Close the experiment
136137
self._file_watcher.removePath(self._experiment_conf_path)
137138
self._mlc_local.close_experiment(self._experiment_name)
138139
self._experiment_closed_signal.emit(self._experiment_name)
139140

140141
def on_start_button_clicked(self):
141-
142-
logger.debug('[EXPERIMENT {0}] [START_BUTTON] - Executing on_start_button_clicked function'.format(self._experiment_name))
142+
logger.debug('[EXPERIMENT {0}] [START_BUTTON] - Executing on_start_button_clicked function'
143+
.format(self._experiment_name))
143144

144145
try:
145146
ArduinoInterfaceSingleton.get_instance(protocol_config=self._board_config,
@@ -863,7 +864,6 @@ def _ask_if_experiment_config_must_be_saved(self):
863864
self._autogenerated_object.save_config_button.setDisabled(True)
864865

865866
def _update_experiment(self, cancelled, failed):
866-
self._progress_dialog.close_window()
867867
if not cancelled and not failed:
868868
QMessageBox.information(self, 'Experiment {0}'.format(self._experiment_name),
869869
'Experiment was succesfully executed.', QMessageBox.Ok)
@@ -892,7 +892,6 @@ def _store_board_configuration(self, board_config, serial_conn):
892892
ArduinoInterfaceSingleton.get_instance(protocol_config=self._board_config,
893893
conn_setup=self._serial_conn._asdict())
894894

895-
896895
# Update board configuration in the DB
897896
self._mlc_local.save_board_configuration(self._experiment_name, self._board_config, self._serial_conn)
898897

@@ -922,4 +921,4 @@ def _report_arduino_unhandled_error(self, error):
922921
logger.debug('[EXPERIMENT {0}] [BOARD_CONFIG] - '
923922
'Unhandled error. Error Msg: {1}'
924923
.format(self._experiment_name, error))
925-
QMessageBox.critical(self, "Critical error", "Error: {0}".format(error))
924+
QMessageBox.critical(self, "Critical error", "Error: {0}".format(error))

0 commit comments

Comments
 (0)