Skip to content

Commit 10c42fe

Browse files
committed
Added rename button with functionality
* Also added the customContextMenu asociated with the list of the MLCManager #34
1 parent 1bc9a6c commit 10c42fe

File tree

6 files changed

+1913
-1696
lines changed

6 files changed

+1913
-1696
lines changed

MLC/GUI/Autogenerated/autogenerated.py

Lines changed: 1682 additions & 1669 deletions
Large diffs are not rendered by default.

MLC/GUI/Autogenerated/mlc_qtcreator/mainwindow.ui

Lines changed: 77 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,86 +51,99 @@
5151
<property name="bottomMargin">
5252
<number>2</number>
5353
</property>
54-
<item row="2" column="0">
55-
<widget class="QToolButton" name="open_button">
54+
<item row="0" column="0">
55+
<widget class="QToolButton" name="new_button">
5656
<property name="sizePolicy">
5757
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
5858
<horstretch>0</horstretch>
5959
<verstretch>0</verstretch>
6060
</sizepolicy>
6161
</property>
6262
<property name="text">
63-
<string>Open</string>
63+
<string>Create</string>
6464
</property>
6565
</widget>
6666
</item>
67-
<item row="0" column="0">
68-
<widget class="QToolButton" name="new_button">
67+
<item row="0" column="1">
68+
<widget class="QToolButton" name="remove_button">
6969
<property name="sizePolicy">
7070
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
7171
<horstretch>0</horstretch>
7272
<verstretch>0</verstretch>
7373
</sizepolicy>
7474
</property>
7575
<property name="text">
76-
<string>New</string>
76+
<string>Remove</string>
7777
</property>
7878
</widget>
7979
</item>
80-
<item row="4" column="0">
81-
<widget class="QPushButton" name="import_button">
80+
<item row="0" column="2">
81+
<widget class="QToolButton" name="clone_button">
8282
<property name="sizePolicy">
8383
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
8484
<horstretch>0</horstretch>
8585
<verstretch>0</verstretch>
8686
</sizepolicy>
8787
</property>
8888
<property name="text">
89-
<string>Import</string>
89+
<string>Clone</string>
90+
</property>
91+
</widget>
92+
</item>
93+
<item row="1" column="0" colspan="3">
94+
<widget class="Line" name="line">
95+
<property name="orientation">
96+
<enum>Qt::Horizontal</enum>
9097
</property>
9198
</widget>
9299
</item>
93-
<item row="3" column="0" colspan="2">
100+
<item row="3" column="0" colspan="3">
94101
<widget class="Line" name="line_2">
95102
<property name="orientation">
96103
<enum>Qt::Horizontal</enum>
97104
</property>
98105
</widget>
99106
</item>
100-
<item row="2" column="1">
101-
<widget class="QToolButton" name="clone_button">
107+
<item row="4" column="1">
108+
<widget class="QPushButton" name="rename_button">
102109
<property name="sizePolicy">
103110
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
104111
<horstretch>0</horstretch>
105112
<verstretch>0</verstretch>
106113
</sizepolicy>
107114
</property>
108115
<property name="text">
109-
<string>Clone</string>
116+
<string>Rename</string>
110117
</property>
111118
</widget>
112119
</item>
113-
<item row="0" column="1">
114-
<widget class="QToolButton" name="remove_button">
120+
<item row="4" column="0">
121+
<widget class="QToolButton" name="open_button">
115122
<property name="sizePolicy">
116123
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
117124
<horstretch>0</horstretch>
118125
<verstretch>0</verstretch>
119126
</sizepolicy>
120127
</property>
121128
<property name="text">
122-
<string>Remove</string>
129+
<string>Open</string>
123130
</property>
124131
</widget>
125132
</item>
126-
<item row="1" column="0" colspan="2">
127-
<widget class="Line" name="line">
128-
<property name="orientation">
129-
<enum>Qt::Horizontal</enum>
133+
<item row="2" column="0">
134+
<widget class="QPushButton" name="import_button">
135+
<property name="sizePolicy">
136+
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
137+
<horstretch>0</horstretch>
138+
<verstretch>0</verstretch>
139+
</sizepolicy>
140+
</property>
141+
<property name="text">
142+
<string>Import</string>
130143
</property>
131144
</widget>
132145
</item>
133-
<item row="4" column="1">
146+
<item row="2" column="1">
134147
<widget class="QPushButton" name="export_button">
135148
<property name="sizePolicy">
136149
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
@@ -147,7 +160,14 @@
147160
</widget>
148161
</item>
149162
<item>
150-
<widget class="QListView" name="experiment_list"/>
163+
<widget class="QListView" name="experiment_list">
164+
<property name="contextMenuPolicy">
165+
<enum>Qt::CustomContextMenu</enum>
166+
</property>
167+
<property name="layoutMode">
168+
<enum>QListView::SinglePass</enum>
169+
</property>
170+
</widget>
151171
</item>
152172
</layout>
153173
</widget>
@@ -172,7 +192,7 @@
172192
<x>0</x>
173193
<y>0</y>
174194
<width>749</width>
175-
<height>23</height>
195+
<height>19</height>
176196
</rect>
177197
</property>
178198
<widget class="QMenu" name="menuMLC">
@@ -408,6 +428,38 @@
408428
</hint>
409429
</hints>
410430
</connection>
431+
<connection>
432+
<sender>experiment_list</sender>
433+
<signal>customContextMenuRequested(QPoint)</signal>
434+
<receiver>MLCManager</receiver>
435+
<slot>on_experiment_list_context_menu()</slot>
436+
<hints>
437+
<hint type="sourcelabel">
438+
<x>190</x>
439+
<y>360</y>
440+
</hint>
441+
<hint type="destinationlabel">
442+
<x>374</x>
443+
<y>292</y>
444+
</hint>
445+
</hints>
446+
</connection>
447+
<connection>
448+
<sender>rename_button</sender>
449+
<signal>clicked()</signal>
450+
<receiver>MLCManager</receiver>
451+
<slot>on_rename_button_clicked()</slot>
452+
<hints>
453+
<hint type="sourcelabel">
454+
<x>190</x>
455+
<y>160</y>
456+
</hint>
457+
<hint type="destinationlabel">
458+
<x>374</x>
459+
<y>292</y>
460+
</hint>
461+
</hints>
462+
</connection>
411463
</connections>
412464
<slots>
413465
<slot>on_new_button_clicked()</slot>
@@ -419,5 +471,7 @@
419471
<slot>on_import_button_clicked()</slot>
420472
<slot>on_export_button_clicked()</slot>
421473
<slot>menu_about()</slot>
474+
<slot>on_experiment_list_context_menu()</slot>
475+
<slot>on_rename_button_clicked()</slot>
422476
</slots>
423477
</ui>

MLC/GUI/ExperimentsManager.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,29 @@ def clone_experiment(self, experiment_name, cloned_experiment):
169169
self.load_experiment_info(cloned_experiment)
170170
return True
171171

172+
def rename_experiment(self, experiment_name_old, experiment_name_new):
173+
try:
174+
if not self._mlc_local.rename_experiment(experiment_name_old, experiment_name_new):
175+
logger.error("[GUI_EXPERIMENT_MANAGER] [EXPORT] - "
176+
"Experiment {0} could not be renamed because there "
177+
"is a conflict with the rename value of the experiment. "
178+
"Check the workspace to be OK or choose another experiment name"
179+
.format(experiment_name_new))
180+
return False
181+
except OSError:
182+
logger.error("[GUI_EXPERIMENT_MANAGER] [EXPORT] - "
183+
"Experiment to be renamed ({0}) could not be removed. "
184+
"Check the workspace to be OK".format(experiment_new_old))
185+
return False
186+
187+
# Everything went OK. Remove the last experiment and add the new one
188+
self._experiment_list.remove(experiment_name_old)
189+
del self._experiment_info_dict[experiment_name_old]
190+
self._experiment_list.append(experiment_name_new)
191+
self._experiment_list.sort()
192+
self.load_experiment_info(experiment_name_new)
193+
return True
194+
172195
def get_experiment_list(self):
173196
return self._experiment_list
174197

MLC/GUI/mlc_gui.py

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from PyQt5.QtWidgets import QFileDialog
5454
from PyQt5.QtWidgets import QInputDialog
5555
from PyQt5.QtWidgets import QMainWindow
56+
from PyQt5.QtWidgets import QMenu
5657
from PyQt5.QtWidgets import QMessageBox
5758

5859
logger = get_gui_logger()
@@ -159,17 +160,17 @@ def on_clone_button_clicked(self):
159160
dialog_ok = False
160161

161162
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")
163164
return
164165
experiment_name = self._experiment_selected
165166

166167
while True:
167168
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:')
169170

170171
if dialog_ok:
171172
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.')
173174
msg_ok = QMessageBox.information(self, 'Clone Experiment',
174175
'Cloned experiment name experiment cannot be an empty string. '
175176
'Please, insert a valid name',
@@ -216,7 +217,6 @@ def on_clone_button_clicked(self):
216217
break
217218
logger.debug('[MLC_MANAGER] New experiment could not be cloned')
218219

219-
220220
def on_remove_button_clicked(self):
221221
logger.debug("[MLC_MANAGER] [REMOVE_EXPERIMENT] - Remove button clicked")
222222
if self._experiment_selected is None:
@@ -292,6 +292,96 @@ def on_export_button_clicked(self):
292292
"Experiment could not be exported. "
293293
"Error {0}".format(err))
294294

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+
295385
def load_gui_config(self):
296386
abspath = os.path.abspath(".")
297387
config_filepath = os.path.join(abspath, MLC_GUI.GUI_CONFIG_FILE)

0 commit comments

Comments
 (0)