19 |
19 |
20 class ToolGroupConfigurationDialog(QDialog, Ui_ToolGroupConfigurationDialog): |
20 class ToolGroupConfigurationDialog(QDialog, Ui_ToolGroupConfigurationDialog): |
21 """ |
21 """ |
22 Class implementing a configuration dialog for the tool groups. |
22 Class implementing a configuration dialog for the tool groups. |
23 """ |
23 """ |
|
24 |
24 def __init__(self, toolGroups, currentGroup, parent=None): |
25 def __init__(self, toolGroups, currentGroup, parent=None): |
25 """ |
26 """ |
26 Constructor |
27 Constructor |
27 |
28 |
28 @param toolGroups list of configured tool groups |
29 @param toolGroups list of configured tool groups |
29 @param currentGroup number of the active group (integer) |
30 @param currentGroup number of the active group (integer) |
30 @param parent parent widget (QWidget) |
31 @param parent parent widget (QWidget) |
31 """ |
32 """ |
32 super().__init__(parent) |
33 super().__init__(parent) |
33 self.setupUi(self) |
34 self.setupUi(self) |
34 |
35 |
35 self.currentGroup = currentGroup |
36 self.currentGroup = currentGroup |
36 self.toolGroups = copy.deepcopy(toolGroups) |
37 self.toolGroups = copy.deepcopy(toolGroups) |
37 for group in toolGroups: |
38 for group in toolGroups: |
38 self.groupsList.addItem(group[0]) |
39 self.groupsList.addItem(group[0]) |
39 |
40 |
40 if len(toolGroups): |
41 if len(toolGroups): |
41 self.groupsList.setCurrentRow(0) |
42 self.groupsList.setCurrentRow(0) |
42 self.on_groupsList_currentRowChanged(0) |
43 self.on_groupsList_currentRowChanged(0) |
43 |
44 |
44 @pyqtSlot() |
45 @pyqtSlot() |
45 def on_newButton_clicked(self): |
46 def on_newButton_clicked(self): |
46 """ |
47 """ |
47 Private slot to clear all entry fields. |
48 Private slot to clear all entry fields. |
48 """ |
49 """ |
49 self.nameEdit.clear() |
50 self.nameEdit.clear() |
50 |
51 |
51 @pyqtSlot() |
52 @pyqtSlot() |
52 def on_addButton_clicked(self): |
53 def on_addButton_clicked(self): |
53 """ |
54 """ |
54 Private slot to add a new entry. |
55 Private slot to add a new entry. |
55 """ |
56 """ |
56 groupName = self.nameEdit.text() |
57 groupName = self.nameEdit.text() |
57 |
58 |
58 if not groupName: |
59 if not groupName: |
59 EricMessageBox.critical( |
60 EricMessageBox.critical( |
60 self, |
61 self, |
61 self.tr("Add tool group entry"), |
62 self.tr("Add tool group entry"), |
62 self.tr("You have to give a name for the group to add.")) |
63 self.tr("You have to give a name for the group to add."), |
63 return |
64 ) |
64 |
65 return |
65 if len(self.groupsList.findItems( |
66 |
66 groupName, Qt.MatchFlag.MatchExactly)): |
67 if len(self.groupsList.findItems(groupName, Qt.MatchFlag.MatchExactly)): |
67 EricMessageBox.critical( |
68 EricMessageBox.critical( |
68 self, |
69 self, |
69 self.tr("Add tool group entry"), |
70 self.tr("Add tool group entry"), |
70 self.tr("An entry for the group name {0} already exists.") |
71 self.tr("An entry for the group name {0} already exists.").format( |
71 .format(groupName)) |
72 groupName |
72 return |
73 ), |
73 |
74 ) |
|
75 return |
|
76 |
74 self.groupsList.addItem(groupName) |
77 self.groupsList.addItem(groupName) |
75 self.toolGroups.append([groupName, []]) |
78 self.toolGroups.append([groupName, []]) |
76 |
79 |
77 @pyqtSlot() |
80 @pyqtSlot() |
78 def on_changeButton_clicked(self): |
81 def on_changeButton_clicked(self): |
79 """ |
82 """ |
80 Private slot to change an entry. |
83 Private slot to change an entry. |
81 """ |
84 """ |
82 row = self.groupsList.currentRow() |
85 row = self.groupsList.currentRow() |
83 if row < 0: |
86 if row < 0: |
84 return |
87 return |
85 |
88 |
86 groupName = self.nameEdit.text() |
89 groupName = self.nameEdit.text() |
87 |
90 |
88 if not groupName: |
91 if not groupName: |
89 EricMessageBox.critical( |
92 EricMessageBox.critical( |
90 self, |
93 self, |
91 self.tr("Add tool group entry"), |
94 self.tr("Add tool group entry"), |
92 self.tr("You have to give a name for the group to add.")) |
95 self.tr("You have to give a name for the group to add."), |
93 return |
96 ) |
94 |
97 return |
95 if len(self.groupsList.findItems( |
98 |
96 groupName, Qt.MatchFlag.MatchExactly)): |
99 if len(self.groupsList.findItems(groupName, Qt.MatchFlag.MatchExactly)): |
97 EricMessageBox.critical( |
100 EricMessageBox.critical( |
98 self, |
101 self, |
99 self.tr("Add tool group entry"), |
102 self.tr("Add tool group entry"), |
100 self.tr("An entry for the group name {0} already exists.") |
103 self.tr("An entry for the group name {0} already exists.").format( |
101 .format(groupName)) |
104 groupName |
102 return |
105 ), |
103 |
106 ) |
|
107 return |
|
108 |
104 self.toolGroups[row][0] = groupName |
109 self.toolGroups[row][0] = groupName |
105 self.groupsList.currentItem().setText(groupName) |
110 self.groupsList.currentItem().setText(groupName) |
106 |
111 |
107 @pyqtSlot() |
112 @pyqtSlot() |
108 def on_deleteButton_clicked(self): |
113 def on_deleteButton_clicked(self): |
109 """ |
114 """ |
110 Private slot to delete the selected entry. |
115 Private slot to delete the selected entry. |
111 """ |
116 """ |
112 row = self.groupsList.currentRow() |
117 row = self.groupsList.currentRow() |
113 if row < 0: |
118 if row < 0: |
114 return |
119 return |
115 |
120 |
116 res = EricMessageBox.yesNo( |
121 res = EricMessageBox.yesNo( |
117 self, |
122 self, |
118 self.tr("Delete tool group entry"), |
123 self.tr("Delete tool group entry"), |
119 self.tr("""<p>Do you really want to delete the tool group""" |
124 self.tr( |
120 """ <b>"{0}"</b>?</p>""") |
125 """<p>Do you really want to delete the tool group""" |
121 .format(self.groupsList.currentItem().text()), |
126 """ <b>"{0}"</b>?</p>""" |
122 icon=EricMessageBox.Warning) |
127 ).format(self.groupsList.currentItem().text()), |
|
128 icon=EricMessageBox.Warning, |
|
129 ) |
123 if not res: |
130 if not res: |
124 return |
131 return |
125 |
132 |
126 if row == self.currentGroup: |
133 if row == self.currentGroup: |
127 # set to default group if current group gets deleted |
134 # set to default group if current group gets deleted |
128 self.currentGroup = -1 |
135 self.currentGroup = -1 |
129 |
136 |
130 del self.toolGroups[row] |
137 del self.toolGroups[row] |
131 itm = self.groupsList.takeItem(row) |
138 itm = self.groupsList.takeItem(row) |
132 del itm |
139 del itm |
133 if row >= len(self.toolGroups): |
140 if row >= len(self.toolGroups): |
134 row -= 1 |
141 row -= 1 |
135 self.groupsList.setCurrentRow(row) |
142 self.groupsList.setCurrentRow(row) |
136 self.on_groupsList_currentRowChanged(row) |
143 self.on_groupsList_currentRowChanged(row) |
137 |
144 |
138 @pyqtSlot() |
145 @pyqtSlot() |
139 def on_downButton_clicked(self): |
146 def on_downButton_clicked(self): |
140 """ |
147 """ |
141 Private slot to move an entry down in the list. |
148 Private slot to move an entry down in the list. |
142 """ |
149 """ |
162 self.groupsList.addItem(group[0]) |
169 self.groupsList.addItem(group[0]) |
163 self.groupsList.setCurrentRow(curr - 1) |
170 self.groupsList.setCurrentRow(curr - 1) |
164 if curr - 1 == 0: |
171 if curr - 1 == 0: |
165 self.upButton.setEnabled(False) |
172 self.upButton.setEnabled(False) |
166 self.downButton.setEnabled(True) |
173 self.downButton.setEnabled(True) |
167 |
174 |
168 def on_groupsList_currentRowChanged(self, row): |
175 def on_groupsList_currentRowChanged(self, row): |
169 """ |
176 """ |
170 Private slot to set the lineedits depending on the selected entry. |
177 Private slot to set the lineedits depending on the selected entry. |
171 |
178 |
172 @param row the row of the selected entry (integer) |
179 @param row the row of the selected entry (integer) |
173 """ |
180 """ |
174 if row >= 0 and row < len(self.toolGroups): |
181 if row >= 0 and row < len(self.toolGroups): |
175 group = self.toolGroups[row] |
182 group = self.toolGroups[row] |
176 self.nameEdit.setText(group[0]) |
183 self.nameEdit.setText(group[0]) |
177 |
184 |
178 self.deleteButton.setEnabled(True) |
185 self.deleteButton.setEnabled(True) |
179 self.changeButton.setEnabled(True) |
186 self.changeButton.setEnabled(True) |
180 |
187 |
181 if row != 0: |
188 if row != 0: |
182 self.upButton.setEnabled(True) |
189 self.upButton.setEnabled(True) |
183 else: |
190 else: |
184 self.upButton.setEnabled(False) |
191 self.upButton.setEnabled(False) |
185 |
192 |
186 if row + 1 != len(self.toolGroups): |
193 if row + 1 != len(self.toolGroups): |
187 self.downButton.setEnabled(True) |
194 self.downButton.setEnabled(True) |
188 else: |
195 else: |
189 self.downButton.setEnabled(False) |
196 self.downButton.setEnabled(False) |
190 else: |
197 else: |
191 self.nameEdit.clear() |
198 self.nameEdit.clear() |
192 self.downButton.setEnabled(False) |
199 self.downButton.setEnabled(False) |
193 self.upButton.setEnabled(False) |
200 self.upButton.setEnabled(False) |
194 self.deleteButton.setEnabled(False) |
201 self.deleteButton.setEnabled(False) |
195 self.changeButton.setEnabled(False) |
202 self.changeButton.setEnabled(False) |
196 |
203 |
197 def getToolGroups(self): |
204 def getToolGroups(self): |
198 """ |
205 """ |
199 Public method to retrieve the tool groups. |
206 Public method to retrieve the tool groups. |
200 |
207 |
201 @return a list of lists containing the group name and the |
208 @return a list of lists containing the group name and the |
202 tool group entries |
209 tool group entries |
203 """ |
210 """ |
204 return self.toolGroups[:], self.currentGroup |
211 return self.toolGroups[:], self.currentGroup |
205 |
212 |
206 def __swap(self, itm1, itm2): |
213 def __swap(self, itm1, itm2): |
207 """ |
214 """ |
208 Private method used two swap two list entries given by their index. |
215 Private method used two swap two list entries given by their index. |
209 |
216 |
210 @param itm1 index of first entry (int) |
217 @param itm1 index of first entry (int) |
211 @param itm2 index of second entry (int) |
218 @param itm2 index of second entry (int) |
212 """ |
219 """ |
213 tmp = self.toolGroups[itm1] |
220 tmp = self.toolGroups[itm1] |
214 self.toolGroups[itm1] = self.toolGroups[itm2] |
221 self.toolGroups[itm1] = self.toolGroups[itm2] |