--- a/E5Gui/E5ToolBarDialog.py Tue Oct 15 22:03:54 2013 +0200 +++ b/E5Gui/E5ToolBarDialog.py Fri Oct 18 23:00:41 2013 +0200 @@ -29,7 +29,8 @@ Constructor @param toolBarId id of the toolbar object (integer) - @param actionIDs list of action IDs belonging to the toolbar (list of integer) + @param actionIDs list of action IDs belonging to the toolbar + (list of integer) @param default flag indicating a default toolbar (boolean) """ self.toolBarId = toolBarId @@ -50,16 +51,19 @@ """ Constructor - @param toolBarManager reference to a toolbar manager object (E5ToolBarManager) + @param toolBarManager reference to a toolbar manager object + (E5ToolBarManager) @param parent reference to the parent widget (QWidget) """ super(E5ToolBarDialog, self).__init__(parent) self.setupUi(self) self.__manager = toolBarManager - self.__toolbarItems = {} # maps toolbar item IDs to toolbar items + self.__toolbarItems = {} + # maps toolbar item IDs to toolbar items self.__currentToolBarItem = None - self.__removedToolBarIDs = [] # remember custom toolbars to be deleted + self.__removedToolBarIDs = [] + # remember custom toolbars to be deleted self.__widgetActionToToolBarItemID = {} # maps widget action IDs to toolbar item IDs @@ -110,11 +114,13 @@ actionIDs.append(aID) if aID in self.__widgetActionToToolBarItemID: self.__widgetActionToToolBarItemID[aID] = id(tbItem) - self.__toolBarItemToWidgetActionID[id(tbItem)].append(aID) + self.__toolBarItemToWidgetActionID[id(tbItem)]\ + .append(aID) tbItem.actionIDs = actionIDs self.toolbarComboBox.addItem(tb.windowTitle(), int(id(tbItem))) if default: - self.toolbarComboBox.setItemData(self.toolbarComboBox.count() - 1, + self.toolbarComboBox.setItemData( + self.toolbarComboBox.count() - 1, QColor(Qt.darkGreen), Qt.ForegroundRole) self.toolbarComboBox.model().sort(0) @@ -137,7 +143,8 @@ # toolbar with this name already exists E5MessageBox.critical(self, self.trUtf8("New Toolbar"), - self.trUtf8("""A toolbar with the name <b>{0}</b> already exists.""")\ + self.trUtf8( + """A toolbar with the name <b>{0}</b> already exists.""") .format(name)) return @@ -148,17 +155,19 @@ self.__toolBarItemToWidgetActionID[id(tbItem)] = [] self.toolbarComboBox.addItem(name, int(id(tbItem))) self.toolbarComboBox.model().sort(0) - self.toolbarComboBox.setCurrentIndex(self.toolbarComboBox.findText(name)) + self.toolbarComboBox.setCurrentIndex( + self.toolbarComboBox.findText(name)) @pyqtSlot() def on_removeButton_clicked(self): """ - Private slot to remove a custom toolbar + Private slot to remove a custom toolbar. """ name = self.toolbarComboBox.currentText() res = E5MessageBox.yesNo(self, self.trUtf8("Remove Toolbar"), - self.trUtf8("""Should the toolbar <b>{0}</b> really be removed?""")\ + self.trUtf8( + """Should the toolbar <b>{0}</b> really be removed?""") .format(name)) if res: index = self.toolbarComboBox.currentIndex() @@ -192,7 +201,8 @@ # toolbar with this name already exists E5MessageBox.critical(self, self.trUtf8("Rename Toolbar"), - self.trUtf8("""A toolbar with the name <b>{0}</b> already exists.""")\ + self.trUtf8( + """A toolbar with the name <b>{0}</b> already exists.""") .format(newName)) return index = self.toolbarComboBox.currentIndex() @@ -210,10 +220,14 @@ if index > -1: itemID = self.toolbarComboBox.itemData(index) self.__currentToolBarItem = self.__toolbarItems[itemID] - self.renameButton.setEnabled(not self.__currentToolBarItem.isDefault) - self.removeButton.setEnabled(not self.__currentToolBarItem.isDefault) - self.__restoreDefaultsButton.setEnabled(self.__currentToolBarItem.isDefault) - self.__resetButton.setEnabled(self.__currentToolBarItem.toolBarId is not None) + self.renameButton.setEnabled( + not self.__currentToolBarItem.isDefault) + self.removeButton.setEnabled( + not self.__currentToolBarItem.isDefault) + self.__restoreDefaultsButton.setEnabled( + self.__currentToolBarItem.isDefault) + self.__resetButton.setEnabled( + self.__currentToolBarItem.toolBarId is not None) row = self.toolbarActionsList.currentRow() self.upButton.setEnabled(row > 0) @@ -255,13 +269,21 @@ def on_actionsTree_currentItemChanged(self, current, previous): """ Private slot called, when the currently selected action changes. + + @param current reference to the current item (QTreeWidgetItem) + @param previous reference to the previous current item + (QTreeWidgetItem) """ self.__setupButtons() @pyqtSlot(QListWidgetItem, QListWidgetItem) def on_toolbarActionsList_currentItemChanged(self, current, previous): """ - Slot documentation goes here. + Private slot to handle a change of the current item. + + @param current reference to the current item (QListWidgetItem) + @param previous reference to the previous current item + (QListWidgetItem) """ self.__setupButtons() @@ -345,11 +367,12 @@ if oldTbItemID is not None: self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) self.__toolbarItems[oldTbItemID].isChanged = True - self.__toolBarItemToWidgetActionID[oldTbItemID].remove(actionID) + self.__toolBarItemToWidgetActionID[oldTbItemID]\ + .remove(actionID) self.__widgetActionToToolBarItemID[actionID] = \ id(self.__currentToolBarItem) - self.__toolBarItemToWidgetActionID[id(self.__currentToolBarItem)]\ - .append(actionID) + self.__toolBarItemToWidgetActionID[ + id(self.__currentToolBarItem)].append(actionID) self.toolbarActionsList.insertItem(row, item) self.__currentToolBarItem.actionIDs.insert(row, actionID) self.__currentToolBarItem.isChanged = True @@ -360,6 +383,8 @@ def on_buttonBox_clicked(self, button): """ Private slot called, when a button of the button box was clicked. + + @param button reference to the button clicked (QAbstractButton) """ if button == self.buttonBox.button(QDialogButtonBox.Cancel): self.reject() @@ -379,6 +404,8 @@ def __saveToolBars(self): """ Private method to save the configured toolbars. + + @exception RuntimeError raised to indicate an invalid action """ # step 1: remove toolbars marked for deletion for tbID in self.__removedToolBarIDs: @@ -407,16 +434,19 @@ else: action = self.__manager.actionById(actionID) if action is None: - raise RuntimeError("No such action, id: 0x{0:x}".format(actionID)) + raise RuntimeError( + "No such action, id: 0x{0:x}".format(actionID)) actions.append(action) self.__manager.setToolBar(tb, actions) tbItem.isChanged = False def __restoreCurrentToolbar(self, actions): """ - Private methdo to restore the current toolbar to the given list of actions. + Private methdo to restore the current toolbar to the given list of + actions. - @param actions list of actions to set for the current toolbar (list of QAction) + @param actions list of actions to set for the current toolbar + (list of QAction) """ tbItemID = id(self.__currentToolBarItem) for widgetActionID in self.__toolBarItemToWidgetActionID[tbItemID]: @@ -433,12 +463,16 @@ if actionID in self.__widgetActionToToolBarItemID: oldTbItemID = self.__widgetActionToToolBarItemID[actionID] if oldTbItemID is not None: - self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) + self.__toolbarItems[oldTbItemID].actionIDs.remove( + actionID) self.__toolbarItems[oldTbItemID].isChanged = True - self.__toolBarItemToWidgetActionID[oldTbItemID].remove(actionID) + self.__toolBarItemToWidgetActionID[oldTbItemID].remove( + actionID) self.__widgetActionToToolBarItemID[actionID] = tbItemID - self.__toolBarItemToWidgetActionID[tbItemID].append(actionID) - self.__toolbarComboBox_currentIndexChanged(self.toolbarComboBox.currentIndex()) + self.__toolBarItemToWidgetActionID[tbItemID].append( + actionID) + self.__toolbarComboBox_currentIndexChanged( + self.toolbarComboBox.currentIndex()) def __resetCurrentToolbar(self): """