|
53 | 53 | from PyQt5.QtWidgets import QFileDialog |
54 | 54 | from PyQt5.QtWidgets import QInputDialog |
55 | 55 | from PyQt5.QtWidgets import QMainWindow |
| 56 | +from PyQt5.QtWidgets import QMenu |
56 | 57 | from PyQt5.QtWidgets import QMessageBox |
57 | 58 |
|
58 | 59 | logger = get_gui_logger() |
@@ -159,17 +160,17 @@ def on_clone_button_clicked(self): |
159 | 160 | dialog_ok = False |
160 | 161 |
|
161 | 162 | if self._experiment_selected is None: |
162 | | - logger.info("[MLC MANAGER] [OPEN_BUTTON] - No experiment was selected yet. Don't do anything") |
| 163 | + logger.info("[MLC MANAGER] [CLONE_BUTTON] - No experiment was selected yet. Don't do anything") |
163 | 164 | return |
164 | 165 | experiment_name = self._experiment_selected |
165 | 166 |
|
166 | 167 | while True: |
167 | 168 | cloned_experiment, dialog_ok = QInputDialog.getText(self, 'Clone Experiment', |
168 | | - 'Enter the name of the new cloned experiment:') |
| 169 | + 'Enter the name of the new cloned experiment:') |
169 | 170 |
|
170 | 171 | if dialog_ok: |
171 | 172 | if cloned_experiment == "": |
172 | | - logger.info('[MLC_MANAGER] [CLONE_EXPERIMENT] - Cloned experiment name cannot an empty string.') |
| 173 | + logger.info('[MLC_MANAGER] [CLONE_EXPERIMENT] - Cloned experiment name cannot be an empty string.') |
173 | 174 | msg_ok = QMessageBox.information(self, 'Clone Experiment', |
174 | 175 | 'Cloned experiment name experiment cannot be an empty string. ' |
175 | 176 | 'Please, insert a valid name', |
@@ -216,7 +217,6 @@ def on_clone_button_clicked(self): |
216 | 217 | break |
217 | 218 | logger.debug('[MLC_MANAGER] New experiment could not be cloned') |
218 | 219 |
|
219 | | - |
220 | 220 | def on_remove_button_clicked(self): |
221 | 221 | logger.debug("[MLC_MANAGER] [REMOVE_EXPERIMENT] - Remove button clicked") |
222 | 222 | if self._experiment_selected is None: |
@@ -292,6 +292,96 @@ def on_export_button_clicked(self): |
292 | 292 | "Experiment could not be exported. " |
293 | 293 | "Error {0}".format(err)) |
294 | 294 |
|
| 295 | + def on_rename_button_clicked(self): |
| 296 | + logger.debug("[MLC_MANAGER] [EXPORT_BUTTON] - Export button_clicked") |
| 297 | + cloned_experiment = "" |
| 298 | + dialog_ok = False |
| 299 | + |
| 300 | + if self._experiment_selected is None: |
| 301 | + logger.info("[MLC MANAGER] [RENAME_BUTTON] - No experiment was selected yet. Don't do anything") |
| 302 | + return |
| 303 | + experiment_name = self._experiment_selected |
| 304 | + |
| 305 | + while True: |
| 306 | + renamed_experiment, dialog_ok = QInputDialog.getText(self, 'Rename Experiment', |
| 307 | + 'Enter the new name of the experiment:') |
| 308 | + |
| 309 | + if dialog_ok: |
| 310 | + if renamed_experiment == "": |
| 311 | + logger.info('[MLC_MANAGER] [RENAME_EXPERIMENT] - The experiment name cannot be an empty string.') |
| 312 | + msg_ok = QMessageBox.information(self, 'Rename Experiment', |
| 313 | + 'Renamed experiment name experiment cannot be an empty string. ' |
| 314 | + 'Please, insert a valid name', |
| 315 | + QMessageBox.Ok | QMessageBox.Cancel, |
| 316 | + QMessageBox.Ok) |
| 317 | + |
| 318 | + if msg_ok == QMessageBox.Ok: |
| 319 | + continue |
| 320 | + else: |
| 321 | + break |
| 322 | + |
| 323 | + # Check if the experiment already exists |
| 324 | + if renamed_experiment in self._experiments_manager.get_experiment_list(): |
| 325 | + msg_ok = QMessageBox.question(self, 'Rename Experiment', |
| 326 | + ('The experiment name has already been taken. ' |
| 327 | + 'Do you want to choose a different experiment name?'), |
| 328 | + QMessageBox.Yes | QMessageBox.No, |
| 329 | + QMessageBox.Yes) |
| 330 | + if msg_ok == QMessageBox.Yes: |
| 331 | + continue |
| 332 | + else: |
| 333 | + break |
| 334 | + |
| 335 | + # Create the new experiment and refresh the View |
| 336 | + if not self._experiments_manager.rename_experiment(experiment_name, renamed_experiment): |
| 337 | + logger.error('[MLC_MANAGER] [CLONE_EXPERIMENT] - Experiment {0} could not be renamed. ' |
| 338 | + 'Check it to be correct in your workspace'.format(experiment_name)) |
| 339 | + QMessageBox.critical(self, 'Clone Experiment', |
| 340 | + 'Experiment {0} could not be renamed. ' |
| 341 | + 'Check the experiment to be correct in your workspace' |
| 342 | + .format(experiment_name)) |
| 343 | + return |
| 344 | + |
| 345 | + self._refresh_experiment_list_view() |
| 346 | + self._clean_experiment_selection() |
| 347 | + |
| 348 | + QMessageBox.information(self, 'Rename Experiment', |
| 349 | + 'Experiment {0} was succesfully renamed. Renamed Experiment: {1}' |
| 350 | + .format(experiment_name, renamed_experiment)) |
| 351 | + logger.debug('[MLC_MANAGER] [RENAME_EXPERIMENT] - Experiment {0} was succesfully renamed. ' |
| 352 | + 'Renamed Experiment {1}'.format(experiment_name, renamed_experiment)) |
| 353 | + return |
| 354 | + else: |
| 355 | + break |
| 356 | + logger.debug('[MLC_MANAGER] New experiment could not be renamed') |
| 357 | + |
| 358 | + def on_experiment_list_context_menu(self, point): |
| 359 | + logger.debug('[MLC_MANAGER] [LIST_CONTEXT_MENU] - Context Menu displayed') |
| 360 | + |
| 361 | + menu = QMenu(self) |
| 362 | + |
| 363 | + action_open = QAction("Open", self) |
| 364 | + action_open.triggered.connect(self.on_open_button_clicked) |
| 365 | + menu.addAction(action_open) |
| 366 | + |
| 367 | + action_remove = QAction("Remove", self) |
| 368 | + action_remove.triggered.connect(self.on_remove_button_clicked) |
| 369 | + menu.addAction(action_remove) |
| 370 | + |
| 371 | + action_clone = QAction("Clone", self) |
| 372 | + action_clone.triggered.connect(self.on_clone_button_clicked) |
| 373 | + menu.addAction(action_clone) |
| 374 | + |
| 375 | + action_export = QAction("Export", self) |
| 376 | + action_export.triggered.connect(self.on_export_button_clicked) |
| 377 | + menu.addAction(action_export) |
| 378 | + |
| 379 | + action_rename = QAction("Rename", self) |
| 380 | + action_rename.triggered.connect(self.on_rename_button_clicked) |
| 381 | + menu.addAction(action_rename) |
| 382 | + |
| 383 | + menu.popup(self._autogenerated_object.experiment_list.mapToGlobal(point)) |
| 384 | + |
295 | 385 | def load_gui_config(self): |
296 | 386 | abspath = os.path.abspath(".") |
297 | 387 | config_filepath = os.path.join(abspath, MLC_GUI.GUI_CONFIG_FILE) |
|
0 commit comments