25 def __init__(self, toolBarId, actionIDs, default): |
25 def __init__(self, toolBarId, actionIDs, default): |
26 """ |
26 """ |
27 Constructor |
27 Constructor |
28 |
28 |
29 @param toolBarId id of the toolbar object (integer) |
29 @param toolBarId id of the toolbar object (integer) |
30 @param actionIDs list of action IDs belonging to the toolbar (list of integer) |
30 @param actionIDs list of action IDs belonging to the toolbar |
|
31 (list of integer) |
31 @param default flag indicating a default toolbar (boolean) |
32 @param default flag indicating a default toolbar (boolean) |
32 """ |
33 """ |
33 self.toolBarId = toolBarId |
34 self.toolBarId = toolBarId |
34 self.actionIDs = actionIDs[:] |
35 self.actionIDs = actionIDs[:] |
35 self.isDefault = default |
36 self.isDefault = default |
46 |
47 |
47 def __init__(self, toolBarManager, parent=None): |
48 def __init__(self, toolBarManager, parent=None): |
48 """ |
49 """ |
49 Constructor |
50 Constructor |
50 |
51 |
51 @param toolBarManager reference to a toolbar manager object (E5ToolBarManager) |
52 @param toolBarManager reference to a toolbar manager object |
|
53 (E5ToolBarManager) |
52 @param parent reference to the parent widget (QWidget) |
54 @param parent reference to the parent widget (QWidget) |
53 """ |
55 """ |
54 super().__init__(parent) |
56 super().__init__(parent) |
55 self.setupUi(self) |
57 self.setupUi(self) |
56 |
58 |
57 self.__manager = toolBarManager |
59 self.__manager = toolBarManager |
58 self.__toolbarItems = {} # maps toolbar item IDs to toolbar items |
60 self.__toolbarItems = {} |
|
61 # maps toolbar item IDs to toolbar items |
59 self.__currentToolBarItem = None |
62 self.__currentToolBarItem = None |
60 self.__removedToolBarIDs = [] # remember custom toolbars to be deleted |
63 self.__removedToolBarIDs = [] |
|
64 # remember custom toolbars to be deleted |
61 |
65 |
62 self.__widgetActionToToolBarItemID = {} |
66 self.__widgetActionToToolBarItemID = {} |
63 # maps widget action IDs to toolbar item IDs |
67 # maps widget action IDs to toolbar item IDs |
64 self.__toolBarItemToWidgetActionID = {} |
68 self.__toolBarItemToWidgetActionID = {} |
65 # maps toolbar item IDs to widget action IDs |
69 # maps toolbar item IDs to widget action IDs |
106 else: |
110 else: |
107 aID = id(action) |
111 aID = id(action) |
108 actionIDs.append(aID) |
112 actionIDs.append(aID) |
109 if aID in self.__widgetActionToToolBarItemID: |
113 if aID in self.__widgetActionToToolBarItemID: |
110 self.__widgetActionToToolBarItemID[aID] = id(tbItem) |
114 self.__widgetActionToToolBarItemID[aID] = id(tbItem) |
111 self.__toolBarItemToWidgetActionID[id(tbItem)].append(aID) |
115 self.__toolBarItemToWidgetActionID[id(tbItem)]\ |
|
116 .append(aID) |
112 tbItem.actionIDs = actionIDs |
117 tbItem.actionIDs = actionIDs |
113 self.toolbarComboBox.addItem(tb.windowTitle(), int(id(tbItem))) |
118 self.toolbarComboBox.addItem(tb.windowTitle(), int(id(tbItem))) |
114 if default: |
119 if default: |
115 self.toolbarComboBox.setItemData(self.toolbarComboBox.count() - 1, |
120 self.toolbarComboBox.setItemData( |
|
121 self.toolbarComboBox.count() - 1, |
116 QColor(Qt.darkGreen), Qt.ForegroundRole) |
122 QColor(Qt.darkGreen), Qt.ForegroundRole) |
117 self.toolbarComboBox.model().sort(0) |
123 self.toolbarComboBox.model().sort(0) |
118 |
124 |
119 self.toolbarComboBox.currentIndexChanged[int].connect( |
125 self.toolbarComboBox.currentIndexChanged[int].connect( |
120 self.__toolbarComboBox_currentIndexChanged) |
126 self.__toolbarComboBox_currentIndexChanged) |
133 if ok and name: |
139 if ok and name: |
134 if self.toolbarComboBox.findText(name) != -1: |
140 if self.toolbarComboBox.findText(name) != -1: |
135 # toolbar with this name already exists |
141 # toolbar with this name already exists |
136 E5MessageBox.critical(self, |
142 E5MessageBox.critical(self, |
137 self.trUtf8("New Toolbar"), |
143 self.trUtf8("New Toolbar"), |
138 self.trUtf8("""A toolbar with the name <b>{0}</b> already exists.""")\ |
144 self.trUtf8( |
|
145 """A toolbar with the name <b>{0}</b> already exists.""") |
139 .format(name)) |
146 .format(name)) |
140 return |
147 return |
141 |
148 |
142 tbItem = E5ToolBarItem(None, [], False) |
149 tbItem = E5ToolBarItem(None, [], False) |
143 tbItem.title = name |
150 tbItem.title = name |
144 tbItem.isChanged = True |
151 tbItem.isChanged = True |
145 self.__toolbarItems[id(tbItem)] = tbItem |
152 self.__toolbarItems[id(tbItem)] = tbItem |
146 self.__toolBarItemToWidgetActionID[id(tbItem)] = [] |
153 self.__toolBarItemToWidgetActionID[id(tbItem)] = [] |
147 self.toolbarComboBox.addItem(name, int(id(tbItem))) |
154 self.toolbarComboBox.addItem(name, int(id(tbItem))) |
148 self.toolbarComboBox.model().sort(0) |
155 self.toolbarComboBox.model().sort(0) |
149 self.toolbarComboBox.setCurrentIndex(self.toolbarComboBox.findText(name)) |
156 self.toolbarComboBox.setCurrentIndex( |
|
157 self.toolbarComboBox.findText(name)) |
150 |
158 |
151 @pyqtSlot() |
159 @pyqtSlot() |
152 def on_removeButton_clicked(self): |
160 def on_removeButton_clicked(self): |
153 """ |
161 """ |
154 Private slot to remove a custom toolbar. |
162 Private slot to remove a custom toolbar. |
155 """ |
163 """ |
156 name = self.toolbarComboBox.currentText() |
164 name = self.toolbarComboBox.currentText() |
157 res = E5MessageBox.yesNo(self, |
165 res = E5MessageBox.yesNo(self, |
158 self.trUtf8("Remove Toolbar"), |
166 self.trUtf8("Remove Toolbar"), |
159 self.trUtf8("""Should the toolbar <b>{0}</b> really be removed?""")\ |
167 self.trUtf8( |
|
168 """Should the toolbar <b>{0}</b> really be removed?""") |
160 .format(name)) |
169 .format(name)) |
161 if res: |
170 if res: |
162 index = self.toolbarComboBox.currentIndex() |
171 index = self.toolbarComboBox.currentIndex() |
163 tbItemID = self.toolbarComboBox.itemData(index) |
172 tbItemID = self.toolbarComboBox.itemData(index) |
164 tbItem = self.__toolbarItems[tbItemID] |
173 tbItem = self.__toolbarItems[tbItemID] |
188 return |
197 return |
189 if self.toolbarComboBox.findText(newName) != -1: |
198 if self.toolbarComboBox.findText(newName) != -1: |
190 # toolbar with this name already exists |
199 # toolbar with this name already exists |
191 E5MessageBox.critical(self, |
200 E5MessageBox.critical(self, |
192 self.trUtf8("Rename Toolbar"), |
201 self.trUtf8("Rename Toolbar"), |
193 self.trUtf8("""A toolbar with the name <b>{0}</b> already exists.""")\ |
202 self.trUtf8( |
|
203 """A toolbar with the name <b>{0}</b> already exists.""") |
194 .format(newName)) |
204 .format(newName)) |
195 return |
205 return |
196 index = self.toolbarComboBox.currentIndex() |
206 index = self.toolbarComboBox.currentIndex() |
197 self.toolbarComboBox.setItemText(index, newName) |
207 self.toolbarComboBox.setItemText(index, newName) |
198 tbItem = \ |
208 tbItem = \ |
206 """ |
216 """ |
207 index = self.toolbarComboBox.currentIndex() |
217 index = self.toolbarComboBox.currentIndex() |
208 if index > -1: |
218 if index > -1: |
209 itemID = self.toolbarComboBox.itemData(index) |
219 itemID = self.toolbarComboBox.itemData(index) |
210 self.__currentToolBarItem = self.__toolbarItems[itemID] |
220 self.__currentToolBarItem = self.__toolbarItems[itemID] |
211 self.renameButton.setEnabled(not self.__currentToolBarItem.isDefault) |
221 self.renameButton.setEnabled( |
212 self.removeButton.setEnabled(not self.__currentToolBarItem.isDefault) |
222 not self.__currentToolBarItem.isDefault) |
213 self.__restoreDefaultsButton.setEnabled(self.__currentToolBarItem.isDefault) |
223 self.removeButton.setEnabled( |
214 self.__resetButton.setEnabled(self.__currentToolBarItem.toolBarId is not None) |
224 not self.__currentToolBarItem.isDefault) |
|
225 self.__restoreDefaultsButton.setEnabled( |
|
226 self.__currentToolBarItem.isDefault) |
|
227 self.__resetButton.setEnabled( |
|
228 self.__currentToolBarItem.toolBarId is not None) |
215 |
229 |
216 row = self.toolbarActionsList.currentRow() |
230 row = self.toolbarActionsList.currentRow() |
217 self.upButton.setEnabled(row > 0) |
231 self.upButton.setEnabled(row > 0) |
218 self.downButton.setEnabled(row < self.toolbarActionsList.count() - 1) |
232 self.downButton.setEnabled(row < self.toolbarActionsList.count() - 1) |
219 self.leftButton.setEnabled(self.toolbarActionsList.count() > 0) |
233 self.leftButton.setEnabled(self.toolbarActionsList.count() > 0) |
349 item.setData(Qt.TextColorRole, QColor(Qt.blue)) |
363 item.setData(Qt.TextColorRole, QColor(Qt.blue)) |
350 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
364 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
351 if oldTbItemID is not None: |
365 if oldTbItemID is not None: |
352 self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) |
366 self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) |
353 self.__toolbarItems[oldTbItemID].isChanged = True |
367 self.__toolbarItems[oldTbItemID].isChanged = True |
354 self.__toolBarItemToWidgetActionID[oldTbItemID].remove(actionID) |
368 self.__toolBarItemToWidgetActionID[oldTbItemID]\ |
|
369 .remove(actionID) |
355 self.__widgetActionToToolBarItemID[actionID] = \ |
370 self.__widgetActionToToolBarItemID[actionID] = \ |
356 id(self.__currentToolBarItem) |
371 id(self.__currentToolBarItem) |
357 self.__toolBarItemToWidgetActionID[id(self.__currentToolBarItem)]\ |
372 self.__toolBarItemToWidgetActionID[ |
358 .append(actionID) |
373 id(self.__currentToolBarItem)].append(actionID) |
359 self.toolbarActionsList.insertItem(row, item) |
374 self.toolbarActionsList.insertItem(row, item) |
360 self.__currentToolBarItem.actionIDs.insert(row, actionID) |
375 self.__currentToolBarItem.actionIDs.insert(row, actionID) |
361 self.__currentToolBarItem.isChanged = True |
376 self.__currentToolBarItem.isChanged = True |
362 self.toolbarActionsList.setCurrentRow(row) |
377 self.toolbarActionsList.setCurrentRow(row) |
363 self.__setupButtons() |
378 self.__setupButtons() |
415 if actionID is None: |
430 if actionID is None: |
416 actions.append(None) |
431 actions.append(None) |
417 else: |
432 else: |
418 action = self.__manager.actionById(actionID) |
433 action = self.__manager.actionById(actionID) |
419 if action is None: |
434 if action is None: |
420 raise RuntimeError("No such action, id: 0x{0:x}".format(actionID)) |
435 raise RuntimeError( |
|
436 "No such action, id: 0x{0:x}".format(actionID)) |
421 actions.append(action) |
437 actions.append(action) |
422 self.__manager.setToolBar(tb, actions) |
438 self.__manager.setToolBar(tb, actions) |
423 tbItem.isChanged = False |
439 tbItem.isChanged = False |
424 |
440 |
425 def __restoreCurrentToolbar(self, actions): |
441 def __restoreCurrentToolbar(self, actions): |
426 """ |
442 """ |
427 Private methdo to restore the current toolbar to the given list of actions. |
443 Private methdo to restore the current toolbar to the given list of |
428 |
444 actions. |
429 @param actions list of actions to set for the current toolbar (list of QAction) |
445 |
|
446 @param actions list of actions to set for the current toolbar |
|
447 (list of QAction) |
430 """ |
448 """ |
431 tbItemID = id(self.__currentToolBarItem) |
449 tbItemID = id(self.__currentToolBarItem) |
432 for widgetActionID in self.__toolBarItemToWidgetActionID[tbItemID]: |
450 for widgetActionID in self.__toolBarItemToWidgetActionID[tbItemID]: |
433 self.__widgetActionToToolBarItemID[widgetActionID] = None |
451 self.__widgetActionToToolBarItemID[widgetActionID] = None |
434 self.__toolBarItemToWidgetActionID[tbItemID] = [] |
452 self.__toolBarItemToWidgetActionID[tbItemID] = [] |
441 actionID = id(action) |
459 actionID = id(action) |
442 self.__currentToolBarItem.actionIDs.append(actionID) |
460 self.__currentToolBarItem.actionIDs.append(actionID) |
443 if actionID in self.__widgetActionToToolBarItemID: |
461 if actionID in self.__widgetActionToToolBarItemID: |
444 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
462 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
445 if oldTbItemID is not None: |
463 if oldTbItemID is not None: |
446 self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) |
464 self.__toolbarItems[oldTbItemID].actionIDs.remove( |
|
465 actionID) |
447 self.__toolbarItems[oldTbItemID].isChanged = True |
466 self.__toolbarItems[oldTbItemID].isChanged = True |
448 self.__toolBarItemToWidgetActionID[oldTbItemID].remove(actionID) |
467 self.__toolBarItemToWidgetActionID[oldTbItemID].remove( |
|
468 actionID) |
449 self.__widgetActionToToolBarItemID[actionID] = tbItemID |
469 self.__widgetActionToToolBarItemID[actionID] = tbItemID |
450 self.__toolBarItemToWidgetActionID[tbItemID].append(actionID) |
470 self.__toolBarItemToWidgetActionID[tbItemID].append( |
451 self.__toolbarComboBox_currentIndexChanged(self.toolbarComboBox.currentIndex()) |
471 actionID) |
|
472 self.__toolbarComboBox_currentIndexChanged( |
|
473 self.toolbarComboBox.currentIndex()) |
452 |
474 |
453 def __resetCurrentToolbar(self): |
475 def __resetCurrentToolbar(self): |
454 """ |
476 """ |
455 Private method to revert all changes made to the current toolbar. |
477 Private method to revert all changes made to the current toolbar. |
456 """ |
478 """ |