Skip to content

Commit 3975fc6

Browse files
committed
Added change workspace location functionality
* #37
1 parent 10c42fe commit 3975fc6

File tree

3 files changed

+80
-23
lines changed

3 files changed

+80
-23
lines changed

MLC/GUI/Autogenerated/autogenerated.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ def setupUi(self, MLCManager):
220220
self.menu_close.setObjectName("menu_close")
221221
self.menu_about = QtWidgets.QAction(MLCManager)
222222
self.menu_about.setObjectName("menu_about")
223+
self.edit_workspace = QtWidgets.QAction(MLCManager)
224+
self.edit_workspace.setObjectName("edit_workspace")
225+
self.menuMLC.addAction(self.edit_workspace)
223226
self.menuMLC.addAction(self.menu_properties)
224227
self.menuMLC.addSeparator()
225228
self.menuMLC.addAction(self.menu_close)
@@ -241,6 +244,7 @@ def setupUi(self, MLCManager):
241244
self.menu_about.triggered.connect(MLCManager.menu_about)
242245
self.experiment_list.customContextMenuRequested['QPoint'].connect(MLCManager.on_experiment_list_context_menu)
243246
self.rename_button.clicked.connect(MLCManager.on_rename_button_clicked)
247+
self.edit_workspace.triggered.connect(MLCManager.on_edit_workspace_clicked)
244248
# QtCore.QMetaObject.connectSlotsByName(MLCManager)
245249

246250
def retranslateUi(self, MLCManager):
@@ -264,6 +268,7 @@ def retranslateUi(self, MLCManager):
264268
self.menu_close.setToolTip(_translate("MLCManager", "Close MLC Manager"))
265269
self.menu_about.setText(_translate("MLCManager", "About"))
266270
self.menu_about.setToolTip(_translate("MLCManager", "Project Information"))
271+
self.edit_workspace.setText(_translate("MLCManager", "Edit Workspace Location"))
267272

268273
# -*- coding: utf-8 -*-
269274

MLC/GUI/Autogenerated/mlc_qtcreator/mainwindow.ui

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
<property name="title">
200200
<string>MLC</string>
201201
</property>
202+
<addaction name="edit_workspace"/>
202203
<addaction name="menu_properties"/>
203204
<addaction name="separator"/>
204205
<addaction name="menu_close"/>
@@ -248,6 +249,11 @@
248249
<string>Project Information</string>
249250
</property>
250251
</action>
252+
<action name="edit_workspace">
253+
<property name="text">
254+
<string>Edit Workspace Location</string>
255+
</property>
256+
</action>
251257
</widget>
252258
<layoutdefault spacing="6" margin="11"/>
253259
<resources/>
@@ -460,6 +466,22 @@
460466
</hint>
461467
</hints>
462468
</connection>
469+
<connection>
470+
<sender>edit_workspace</sender>
471+
<signal>triggered()</signal>
472+
<receiver>MLCManager</receiver>
473+
<slot>on_edit_workspace_clicked()</slot>
474+
<hints>
475+
<hint type="sourcelabel">
476+
<x>-1</x>
477+
<y>-1</y>
478+
</hint>
479+
<hint type="destinationlabel">
480+
<x>374</x>
481+
<y>292</y>
482+
</hint>
483+
</hints>
484+
</connection>
463485
</connections>
464486
<slots>
465487
<slot>on_new_button_clicked()</slot>
@@ -473,5 +495,6 @@
473495
<slot>menu_about()</slot>
474496
<slot>on_experiment_list_context_menu()</slot>
475497
<slot>on_rename_button_clicked()</slot>
498+
<slot>on_edit_workspace_clicked()</slot>
476499
</slots>
477500
</ui>

MLC/GUI/mlc_gui.py

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,34 @@ def __init__(self):
8686
# When an ExperimentDialog is closed, update the experiment info
8787
self.experiment_closed.connect(self.load_and_refresh_experiment_info)
8888

89+
def on_edit_workspace_clicked(self):
90+
logger.debug('[MLC_MANAGER] [EDIT_WORKSPACE] - On_edit_workspace_location triggered')
91+
new_workspace_dir = QFileDialog.getExistingDirectory(self, 'Choose the new workspace directory',
92+
'.', QFileDialog.ShowDirsOnly)
93+
94+
if not new_workspace_dir:
95+
# User clicked 'Cancel' or simply closed the Dialog
96+
return
97+
98+
# Edit the GUI Config to the new workspace location
99+
self._gui_config.set('MAIN', 'workspace', new_workspace_dir)
100+
config_filepath = os.path.join(os.path.abspath("."), MLC_GUI.GUI_CONFIG_FILE)
101+
with open(config_filepath, "w") as f:
102+
self._gui_config.write(f)
103+
104+
# Reload the MLC repository
105+
self._mlc_local = MLCLocal(new_workspace_dir)
106+
self._experiments_manager = ExperimentsManager(self._mlc_local, self._gui_config)
107+
logger.info('[MLC_GUI] [EDIT_WORKSPACE] - Workspace location has been succesfully changed. '
108+
'New Workspace directory: {0}'.format(self._gui_config.get('MAIN', 'workspace')))
109+
110+
QMessageBox.information(self, 'Edit Workspace',
111+
'Workspace location has been succesfully changed. '
112+
'New workspace location: {0}'.format(new_workspace_dir))
113+
114+
self.load_and_refresh_experiments_info()
115+
self._clean_experiment_selection()
116+
89117
def on_new_button_clicked(self):
90118
logger.debug('[MLC_MANAGER] [NEW_EXPERIMENT] - New experiment button clicked')
91119
experiment_name = ""
@@ -304,7 +332,7 @@ def on_rename_button_clicked(self):
304332

305333
while True:
306334
renamed_experiment, dialog_ok = QInputDialog.getText(self, 'Rename Experiment',
307-
'Enter the new name of the experiment:')
335+
'Enter the new name of the experiment:')
308336

309337
if dialog_ok:
310338
if renamed_experiment == "":
@@ -382,40 +410,46 @@ def on_experiment_list_context_menu(self, point):
382410

383411
menu.popup(self._autogenerated_object.experiment_list.mapToGlobal(point))
384412

413+
def on_experiment_list_clicked(self, model_index):
414+
list_view = self._autogenerated_object.experiment_list
415+
experiment_name = list_view.model().itemFromIndex(model_index).text()
416+
self._refresh_experiment_description(experiment_name)
417+
385418
def load_gui_config(self):
386419
abspath = os.path.abspath(".")
387420
config_filepath = os.path.join(abspath, MLC_GUI.GUI_CONFIG_FILE)
421+
workspace_dir = ""
388422

389423
if not os.path.isfile(config_filepath):
390424
reply = QMessageBox.question(self, 'Message',
391425
"Workspace has not been set yet. Do you want to set it?",
392426
QMessageBox.Yes | QMessageBox.No,
393427
QMessageBox.Yes)
394428

395-
if reply == QMessageBox.Yes:
396-
workspace_dir = QFileDialog.getExistingDirectory(self, 'Set workspace Directory',
397-
'.', QFileDialog.ShowDirsOnly)
398-
if workspace_dir == "":
399-
QMessageBox.critical(self, 'MLC Manager',
400-
'Workspace has not been set. Aborting program',
401-
QMessageBox.Ok)
402-
logger.debug('[MLC_GUI] [LOAD_GUI] - Workspace was not set. Aborting program')
403-
self.close()
404-
sys.exit(0)
405-
else:
406-
self._create_gui_config_from_scratch(config_filepath, workspace_dir)
407-
QMessageBox.information(self, 'MLC Manager',
408-
'Workspace was succesfully set',
409-
QMessageBox.Ok)
410-
logger.debug('[MLC_GUI] [LOAD_GUI] - Workspace was succesfully set: {0}'.format(workspace_dir))
411-
else:
429+
if reply == QMessageBox.No:
430+
QMessageBox.critical(self, 'MLC Manager',
431+
'Workspace has not been set. Aborting program',
432+
QMessageBox.Ok)
433+
logger.debug('[MLC_GUI] [LOAD_GUI] - Workspace was not set. Aborting program')
434+
self.close()
435+
sys.exit(0)
436+
437+
workspace_dir = QFileDialog.getExistingDirectory(self, 'Set workspace Directory',
438+
'.', QFileDialog.ShowDirsOnly)
439+
if workspace_dir == "":
412440
QMessageBox.critical(self, 'MLC Manager',
413441
'Workspace has not been set. Aborting program',
414442
QMessageBox.Ok)
415443
logger.debug('[MLC_GUI] [LOAD_GUI] - Workspace was not set. Aborting program')
416444
self.close()
417445
sys.exit(0)
418446

447+
self._create_gui_config_from_scratch(config_filepath, workspace_dir)
448+
QMessageBox.information(self, 'MLC Manager',
449+
'Workspace was succesfully set',
450+
QMessageBox.Ok)
451+
logger.debug('[MLC_GUI] [LOAD_GUI] - Workspace was succesfully set: {0}'.format(workspace_dir))
452+
419453
# Load GUI config
420454
self._gui_config = ConfigParser.ConfigParser()
421455
self._gui_config.read(config_filepath)
@@ -450,11 +484,6 @@ def menu_about(self):
450484
dialog = MLCAboutDialog(self)
451485
dialog.exec_()
452486

453-
def on_experiment_list_clicked(self, model_index):
454-
list_view = self._autogenerated_object.experiment_list
455-
experiment_name = list_view.model().itemFromIndex(model_index).text()
456-
self._refresh_experiment_description(experiment_name)
457-
458487
def _create_gui_config_from_scratch(self, config_filepath, workspace_dir):
459488
self._gui_config = ConfigParser.ConfigParser()
460489
self._gui_config.add_section('MAIN')

0 commit comments

Comments
 (0)