def __init__(self, actions, parent=None): super(ActionEditorDialog, self).__init__(parent) self.actions = actions help = QLabel(translate("Shortcut Settings", '<b>Double click a cell in the Shortcut Column' \ ' to <br />modify the key sequence.</b>')) self.actionTable = QTableWidget(self) self.actionTable.setSelectionBehavior(QTableWidget.SelectRows) self.actionTable.setEditTriggers(QTableWidget.DoubleClicked) self.actionTable.setColumnCount(2) self.actionTable.setHorizontalHeaderLabels( [translate("Shortcut Settings", "Description"), translate("Shortcut Settings", "Shortcut")] ) self.actionTable.horizontalHeader().setStretchLastSection(True) self.actionTable.verticalHeader().hide() self.actionTable.setItemDelegate(ActionEditorDelegate(self)) self.connect(self.actionTable, SIGNAL("cellChanged(int, int)"), self.validateAction) row = 0 for action in self.actions: if action.text().isEmpty(): continue self.actionTable.insertRow(self.actionTable.rowCount()) item = QTableWidgetItem() item.setText(action.text()) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) self.actionTable.setItem(row, 0, item) item = QTableWidgetItem() item.setText(action.shortcut().toString()) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsSelectable) item.oldShortcutText = item.text() self.actionTable.setItem(row, 1, item) row += 1 self.actionTable.resizeColumnsToContents() mainLayout = QVBoxLayout() mainLayout.addWidget(help) mainLayout.setMargin(8) mainLayout.setSpacing(8) mainLayout.addWidget(self.actionTable) self.setLayout(mainLayout) self._model = self.actionTable.model() self._model.edited = False self.actionTable.model().edited = False self.setWindowTitle(translate("Shortcut Settings", "Edit Shortcuts"))
def initActions(self, actions, delegate): table = self.actionTable table.horizontalHeader().setStretchLastSection(True) table.verticalHeader().hide() table.setItemDelegate(delegate) for row, action in enumerate(actions): table.insertRow(table.rowCount()) text = unicode(action.text()).replace('&', '') item = QTableWidgetItem(action.icon(), text) item.setFlags(Qt.ItemIsEnabled) table.setItem(row, 0, item) item = QTableWidgetItem() item.setText(action.shortcut().toString()) item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsEditable) item.oldShortcutText = item.text() table.setItem(row, 1, item) table.resizeColumnsToContents() self.connect(table, Signals.cellChanged, self.validateAction)