27 def __init__(self, toolBarId, actionIDs, default): |
27 def __init__(self, toolBarId, actionIDs, default): |
28 """ |
28 """ |
29 Constructor |
29 Constructor |
30 |
30 |
31 @param toolBarId id of the toolbar object (integer) |
31 @param toolBarId id of the toolbar object (integer) |
32 @param actionIDs list of action IDs belonging to the toolbar (list of integer) |
32 @param actionIDs list of action IDs belonging to the toolbar |
|
33 (list of integer) |
33 @param default flag indicating a default toolbar (boolean) |
34 @param default flag indicating a default toolbar (boolean) |
34 """ |
35 """ |
35 self.toolBarId = toolBarId |
36 self.toolBarId = toolBarId |
36 self.actionIDs = actionIDs[:] |
37 self.actionIDs = actionIDs[:] |
37 self.isDefault = default |
38 self.isDefault = default |
48 |
49 |
49 def __init__(self, toolBarManager, parent=None): |
50 def __init__(self, toolBarManager, parent=None): |
50 """ |
51 """ |
51 Constructor |
52 Constructor |
52 |
53 |
53 @param toolBarManager reference to a toolbar manager object (E5ToolBarManager) |
54 @param toolBarManager reference to a toolbar manager object |
|
55 (E5ToolBarManager) |
54 @param parent reference to the parent widget (QWidget) |
56 @param parent reference to the parent widget (QWidget) |
55 """ |
57 """ |
56 super(E5ToolBarDialog, self).__init__(parent) |
58 super(E5ToolBarDialog, self).__init__(parent) |
57 self.setupUi(self) |
59 self.setupUi(self) |
58 |
60 |
59 self.__manager = toolBarManager |
61 self.__manager = toolBarManager |
60 self.__toolbarItems = {} # maps toolbar item IDs to toolbar items |
62 self.__toolbarItems = {} |
|
63 # maps toolbar item IDs to toolbar items |
61 self.__currentToolBarItem = None |
64 self.__currentToolBarItem = None |
62 self.__removedToolBarIDs = [] # remember custom toolbars to be deleted |
65 self.__removedToolBarIDs = [] |
|
66 # remember custom toolbars to be deleted |
63 |
67 |
64 self.__widgetActionToToolBarItemID = {} |
68 self.__widgetActionToToolBarItemID = {} |
65 # maps widget action IDs to toolbar item IDs |
69 # maps widget action IDs to toolbar item IDs |
66 self.__toolBarItemToWidgetActionID = {} |
70 self.__toolBarItemToWidgetActionID = {} |
67 # maps toolbar item IDs to widget action IDs |
71 # maps toolbar item IDs to widget action IDs |
108 else: |
112 else: |
109 aID = id(action) |
113 aID = id(action) |
110 actionIDs.append(aID) |
114 actionIDs.append(aID) |
111 if aID in self.__widgetActionToToolBarItemID: |
115 if aID in self.__widgetActionToToolBarItemID: |
112 self.__widgetActionToToolBarItemID[aID] = id(tbItem) |
116 self.__widgetActionToToolBarItemID[aID] = id(tbItem) |
113 self.__toolBarItemToWidgetActionID[id(tbItem)].append(aID) |
117 self.__toolBarItemToWidgetActionID[id(tbItem)]\ |
|
118 .append(aID) |
114 tbItem.actionIDs = actionIDs |
119 tbItem.actionIDs = actionIDs |
115 self.toolbarComboBox.addItem(tb.windowTitle(), int(id(tbItem))) |
120 self.toolbarComboBox.addItem(tb.windowTitle(), int(id(tbItem))) |
116 if default: |
121 if default: |
117 self.toolbarComboBox.setItemData(self.toolbarComboBox.count() - 1, |
122 self.toolbarComboBox.setItemData( |
|
123 self.toolbarComboBox.count() - 1, |
118 QColor(Qt.darkGreen), Qt.ForegroundRole) |
124 QColor(Qt.darkGreen), Qt.ForegroundRole) |
119 self.toolbarComboBox.model().sort(0) |
125 self.toolbarComboBox.model().sort(0) |
120 |
126 |
121 self.toolbarComboBox.currentIndexChanged[int].connect( |
127 self.toolbarComboBox.currentIndexChanged[int].connect( |
122 self.__toolbarComboBox_currentIndexChanged) |
128 self.__toolbarComboBox_currentIndexChanged) |
135 if ok and name: |
141 if ok and name: |
136 if self.toolbarComboBox.findText(name) != -1: |
142 if self.toolbarComboBox.findText(name) != -1: |
137 # toolbar with this name already exists |
143 # toolbar with this name already exists |
138 E5MessageBox.critical(self, |
144 E5MessageBox.critical(self, |
139 self.trUtf8("New Toolbar"), |
145 self.trUtf8("New Toolbar"), |
140 self.trUtf8("""A toolbar with the name <b>{0}</b> already exists.""")\ |
146 self.trUtf8( |
|
147 """A toolbar with the name <b>{0}</b> already exists.""") |
141 .format(name)) |
148 .format(name)) |
142 return |
149 return |
143 |
150 |
144 tbItem = E5ToolBarItem(None, [], False) |
151 tbItem = E5ToolBarItem(None, [], False) |
145 tbItem.title = name |
152 tbItem.title = name |
146 tbItem.isChanged = True |
153 tbItem.isChanged = True |
147 self.__toolbarItems[id(tbItem)] = tbItem |
154 self.__toolbarItems[id(tbItem)] = tbItem |
148 self.__toolBarItemToWidgetActionID[id(tbItem)] = [] |
155 self.__toolBarItemToWidgetActionID[id(tbItem)] = [] |
149 self.toolbarComboBox.addItem(name, int(id(tbItem))) |
156 self.toolbarComboBox.addItem(name, int(id(tbItem))) |
150 self.toolbarComboBox.model().sort(0) |
157 self.toolbarComboBox.model().sort(0) |
151 self.toolbarComboBox.setCurrentIndex(self.toolbarComboBox.findText(name)) |
158 self.toolbarComboBox.setCurrentIndex( |
|
159 self.toolbarComboBox.findText(name)) |
152 |
160 |
153 @pyqtSlot() |
161 @pyqtSlot() |
154 def on_removeButton_clicked(self): |
162 def on_removeButton_clicked(self): |
155 """ |
163 """ |
156 Private slot to remove a custom toolbar |
164 Private slot to remove a custom toolbar. |
157 """ |
165 """ |
158 name = self.toolbarComboBox.currentText() |
166 name = self.toolbarComboBox.currentText() |
159 res = E5MessageBox.yesNo(self, |
167 res = E5MessageBox.yesNo(self, |
160 self.trUtf8("Remove Toolbar"), |
168 self.trUtf8("Remove Toolbar"), |
161 self.trUtf8("""Should the toolbar <b>{0}</b> really be removed?""")\ |
169 self.trUtf8( |
|
170 """Should the toolbar <b>{0}</b> really be removed?""") |
162 .format(name)) |
171 .format(name)) |
163 if res: |
172 if res: |
164 index = self.toolbarComboBox.currentIndex() |
173 index = self.toolbarComboBox.currentIndex() |
165 tbItemID = self.toolbarComboBox.itemData(index) |
174 tbItemID = self.toolbarComboBox.itemData(index) |
166 tbItem = self.__toolbarItems[tbItemID] |
175 tbItem = self.__toolbarItems[tbItemID] |
190 return |
199 return |
191 if self.toolbarComboBox.findText(newName) != -1: |
200 if self.toolbarComboBox.findText(newName) != -1: |
192 # toolbar with this name already exists |
201 # toolbar with this name already exists |
193 E5MessageBox.critical(self, |
202 E5MessageBox.critical(self, |
194 self.trUtf8("Rename Toolbar"), |
203 self.trUtf8("Rename Toolbar"), |
195 self.trUtf8("""A toolbar with the name <b>{0}</b> already exists.""")\ |
204 self.trUtf8( |
|
205 """A toolbar with the name <b>{0}</b> already exists.""") |
196 .format(newName)) |
206 .format(newName)) |
197 return |
207 return |
198 index = self.toolbarComboBox.currentIndex() |
208 index = self.toolbarComboBox.currentIndex() |
199 self.toolbarComboBox.setItemText(index, newName) |
209 self.toolbarComboBox.setItemText(index, newName) |
200 tbItem = \ |
210 tbItem = \ |
208 """ |
218 """ |
209 index = self.toolbarComboBox.currentIndex() |
219 index = self.toolbarComboBox.currentIndex() |
210 if index > -1: |
220 if index > -1: |
211 itemID = self.toolbarComboBox.itemData(index) |
221 itemID = self.toolbarComboBox.itemData(index) |
212 self.__currentToolBarItem = self.__toolbarItems[itemID] |
222 self.__currentToolBarItem = self.__toolbarItems[itemID] |
213 self.renameButton.setEnabled(not self.__currentToolBarItem.isDefault) |
223 self.renameButton.setEnabled( |
214 self.removeButton.setEnabled(not self.__currentToolBarItem.isDefault) |
224 not self.__currentToolBarItem.isDefault) |
215 self.__restoreDefaultsButton.setEnabled(self.__currentToolBarItem.isDefault) |
225 self.removeButton.setEnabled( |
216 self.__resetButton.setEnabled(self.__currentToolBarItem.toolBarId is not None) |
226 not self.__currentToolBarItem.isDefault) |
|
227 self.__restoreDefaultsButton.setEnabled( |
|
228 self.__currentToolBarItem.isDefault) |
|
229 self.__resetButton.setEnabled( |
|
230 self.__currentToolBarItem.toolBarId is not None) |
217 |
231 |
218 row = self.toolbarActionsList.currentRow() |
232 row = self.toolbarActionsList.currentRow() |
219 self.upButton.setEnabled(row > 0) |
233 self.upButton.setEnabled(row > 0) |
220 self.downButton.setEnabled(row < self.toolbarActionsList.count() - 1) |
234 self.downButton.setEnabled(row < self.toolbarActionsList.count() - 1) |
221 self.leftButton.setEnabled(self.toolbarActionsList.count() > 0) |
235 self.leftButton.setEnabled(self.toolbarActionsList.count() > 0) |
253 |
267 |
254 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
268 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
255 def on_actionsTree_currentItemChanged(self, current, previous): |
269 def on_actionsTree_currentItemChanged(self, current, previous): |
256 """ |
270 """ |
257 Private slot called, when the currently selected action changes. |
271 Private slot called, when the currently selected action changes. |
|
272 |
|
273 @param current reference to the current item (QTreeWidgetItem) |
|
274 @param previous reference to the previous current item |
|
275 (QTreeWidgetItem) |
258 """ |
276 """ |
259 self.__setupButtons() |
277 self.__setupButtons() |
260 |
278 |
261 @pyqtSlot(QListWidgetItem, QListWidgetItem) |
279 @pyqtSlot(QListWidgetItem, QListWidgetItem) |
262 def on_toolbarActionsList_currentItemChanged(self, current, previous): |
280 def on_toolbarActionsList_currentItemChanged(self, current, previous): |
263 """ |
281 """ |
264 Slot documentation goes here. |
282 Private slot to handle a change of the current item. |
|
283 |
|
284 @param current reference to the current item (QListWidgetItem) |
|
285 @param previous reference to the previous current item |
|
286 (QListWidgetItem) |
265 """ |
287 """ |
266 self.__setupButtons() |
288 self.__setupButtons() |
267 |
289 |
268 @pyqtSlot() |
290 @pyqtSlot() |
269 def on_upButton_clicked(self): |
291 def on_upButton_clicked(self): |
343 item.setData(Qt.TextColorRole, QColor(Qt.blue)) |
365 item.setData(Qt.TextColorRole, QColor(Qt.blue)) |
344 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
366 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
345 if oldTbItemID is not None: |
367 if oldTbItemID is not None: |
346 self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) |
368 self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) |
347 self.__toolbarItems[oldTbItemID].isChanged = True |
369 self.__toolbarItems[oldTbItemID].isChanged = True |
348 self.__toolBarItemToWidgetActionID[oldTbItemID].remove(actionID) |
370 self.__toolBarItemToWidgetActionID[oldTbItemID]\ |
|
371 .remove(actionID) |
349 self.__widgetActionToToolBarItemID[actionID] = \ |
372 self.__widgetActionToToolBarItemID[actionID] = \ |
350 id(self.__currentToolBarItem) |
373 id(self.__currentToolBarItem) |
351 self.__toolBarItemToWidgetActionID[id(self.__currentToolBarItem)]\ |
374 self.__toolBarItemToWidgetActionID[ |
352 .append(actionID) |
375 id(self.__currentToolBarItem)].append(actionID) |
353 self.toolbarActionsList.insertItem(row, item) |
376 self.toolbarActionsList.insertItem(row, item) |
354 self.__currentToolBarItem.actionIDs.insert(row, actionID) |
377 self.__currentToolBarItem.actionIDs.insert(row, actionID) |
355 self.__currentToolBarItem.isChanged = True |
378 self.__currentToolBarItem.isChanged = True |
356 self.toolbarActionsList.setCurrentRow(row) |
379 self.toolbarActionsList.setCurrentRow(row) |
357 self.__setupButtons() |
380 self.__setupButtons() |
358 |
381 |
359 @pyqtSlot(QAbstractButton) |
382 @pyqtSlot(QAbstractButton) |
360 def on_buttonBox_clicked(self, button): |
383 def on_buttonBox_clicked(self, button): |
361 """ |
384 """ |
362 Private slot called, when a button of the button box was clicked. |
385 Private slot called, when a button of the button box was clicked. |
|
386 |
|
387 @param button reference to the button clicked (QAbstractButton) |
363 """ |
388 """ |
364 if button == self.buttonBox.button(QDialogButtonBox.Cancel): |
389 if button == self.buttonBox.button(QDialogButtonBox.Cancel): |
365 self.reject() |
390 self.reject() |
366 elif button == self.buttonBox.button(QDialogButtonBox.Apply): |
391 elif button == self.buttonBox.button(QDialogButtonBox.Apply): |
367 self.__saveToolBars() |
392 self.__saveToolBars() |
377 self.__setupButtons() |
402 self.__setupButtons() |
378 |
403 |
379 def __saveToolBars(self): |
404 def __saveToolBars(self): |
380 """ |
405 """ |
381 Private method to save the configured toolbars. |
406 Private method to save the configured toolbars. |
|
407 |
|
408 @exception RuntimeError raised to indicate an invalid action |
382 """ |
409 """ |
383 # step 1: remove toolbars marked for deletion |
410 # step 1: remove toolbars marked for deletion |
384 for tbID in self.__removedToolBarIDs: |
411 for tbID in self.__removedToolBarIDs: |
385 tb = self.__manager.toolBarById(tbID) |
412 tb = self.__manager.toolBarById(tbID) |
386 self.__manager.deleteToolBar(tb) |
413 self.__manager.deleteToolBar(tb) |
405 if actionID is None: |
432 if actionID is None: |
406 actions.append(None) |
433 actions.append(None) |
407 else: |
434 else: |
408 action = self.__manager.actionById(actionID) |
435 action = self.__manager.actionById(actionID) |
409 if action is None: |
436 if action is None: |
410 raise RuntimeError("No such action, id: 0x{0:x}".format(actionID)) |
437 raise RuntimeError( |
|
438 "No such action, id: 0x{0:x}".format(actionID)) |
411 actions.append(action) |
439 actions.append(action) |
412 self.__manager.setToolBar(tb, actions) |
440 self.__manager.setToolBar(tb, actions) |
413 tbItem.isChanged = False |
441 tbItem.isChanged = False |
414 |
442 |
415 def __restoreCurrentToolbar(self, actions): |
443 def __restoreCurrentToolbar(self, actions): |
416 """ |
444 """ |
417 Private methdo to restore the current toolbar to the given list of actions. |
445 Private methdo to restore the current toolbar to the given list of |
418 |
446 actions. |
419 @param actions list of actions to set for the current toolbar (list of QAction) |
447 |
|
448 @param actions list of actions to set for the current toolbar |
|
449 (list of QAction) |
420 """ |
450 """ |
421 tbItemID = id(self.__currentToolBarItem) |
451 tbItemID = id(self.__currentToolBarItem) |
422 for widgetActionID in self.__toolBarItemToWidgetActionID[tbItemID]: |
452 for widgetActionID in self.__toolBarItemToWidgetActionID[tbItemID]: |
423 self.__widgetActionToToolBarItemID[widgetActionID] = None |
453 self.__widgetActionToToolBarItemID[widgetActionID] = None |
424 self.__toolBarItemToWidgetActionID[tbItemID] = [] |
454 self.__toolBarItemToWidgetActionID[tbItemID] = [] |
431 actionID = id(action) |
461 actionID = id(action) |
432 self.__currentToolBarItem.actionIDs.append(actionID) |
462 self.__currentToolBarItem.actionIDs.append(actionID) |
433 if actionID in self.__widgetActionToToolBarItemID: |
463 if actionID in self.__widgetActionToToolBarItemID: |
434 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
464 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
435 if oldTbItemID is not None: |
465 if oldTbItemID is not None: |
436 self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) |
466 self.__toolbarItems[oldTbItemID].actionIDs.remove( |
|
467 actionID) |
437 self.__toolbarItems[oldTbItemID].isChanged = True |
468 self.__toolbarItems[oldTbItemID].isChanged = True |
438 self.__toolBarItemToWidgetActionID[oldTbItemID].remove(actionID) |
469 self.__toolBarItemToWidgetActionID[oldTbItemID].remove( |
|
470 actionID) |
439 self.__widgetActionToToolBarItemID[actionID] = tbItemID |
471 self.__widgetActionToToolBarItemID[actionID] = tbItemID |
440 self.__toolBarItemToWidgetActionID[tbItemID].append(actionID) |
472 self.__toolBarItemToWidgetActionID[tbItemID].append( |
441 self.__toolbarComboBox_currentIndexChanged(self.toolbarComboBox.currentIndex()) |
473 actionID) |
|
474 self.__toolbarComboBox_currentIndexChanged( |
|
475 self.toolbarComboBox.currentIndex()) |
442 |
476 |
443 def __resetCurrentToolbar(self): |
477 def __resetCurrentToolbar(self): |
444 """ |
478 """ |
445 Private method to revert all changes made to the current toolbar. |
479 Private method to revert all changes made to the current toolbar. |
446 """ |
480 """ |