--- a/RefactoringRope/ChangeSignatureDialog.py Sat Jun 25 18:06:56 2022 +0200 +++ b/RefactoringRope/ChangeSignatureDialog.py Wed Sep 21 15:30:34 2022 +0200 @@ -10,9 +10,7 @@ import copy from PyQt6.QtCore import pyqtSlot, Qt -from PyQt6.QtWidgets import ( - QDialog, QDialogButtonBox, QListWidgetItem, QAbstractButton -) +from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem, QAbstractButton from .Ui_ChangeSignatureDialog import Ui_ChangeSignatureDialog from .RefactoringDialogBase import RefactoringDialogBase @@ -22,15 +20,16 @@ """ Class implementing the Change Signature dialog. """ + NameRole = Qt.ItemDataRole.UserRole IsAddedRole = Qt.ItemDataRole.UserRole + 1 DefaultRole = Qt.ItemDataRole.UserRole + 2 ValueRole = Qt.ItemDataRole.UserRole + 3 - + def __init__(self, refactoring, title, filename, offset, parent=None): """ Constructor - + @param refactoring reference to the main refactoring object @type RefactoringServer @param title title of the dialog @@ -44,61 +43,63 @@ """ RefactoringDialogBase.__init__(self, refactoring, title, parent) self.setupUi(self) - + self._changeGroupName = "ChangeSignature" - + self.__filename = filename self.__offset = offset - + self.__definition_info = [] self.__to_be_removed = [] - - self.__okButton = self.buttonBox.button( - QDialogButtonBox.StandardButton.Ok) + + self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok) self.__previewButton = self.buttonBox.addButton( - self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole) + self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole + ) self.__previewButton.setDefault(True) - - self._refactoring.sendJson("RequestSignature", { - "ChangeGroup": self._changeGroupName, - "Title": self._title, - "FileName": self.__filename, - "Offset": self.__offset, - }) - + + self._refactoring.sendJson( + "RequestSignature", + { + "ChangeGroup": self._changeGroupName, + "Title": self._title, + "FileName": self.__filename, + "Offset": self.__offset, + }, + ) + def __processSignature(self, data): """ Private method to process the inline type data sent by the refactoring client in order to polish the dialog. - + @param data dictionary containing the inline type data @type dict """ self.__definition_info = data["DefinitionInfo"] - + # populate the parameters list for arg, default in self.__definition_info: itm = ( QListWidgetItem(arg, self.parameterList) - if default is None else - QListWidgetItem("{0}={1}".format(arg, default), - self.parameterList) + if default is None + else QListWidgetItem("{0}={1}".format(arg, default), self.parameterList) ) itm.setData(ChangeSignatureDialog.NameRole, arg) itm.setData(ChangeSignatureDialog.IsAddedRole, False) itm.setData(ChangeSignatureDialog.DefaultRole, None) itm.setData(ChangeSignatureDialog.ValueRole, None) - + if self.parameterList.count(): self.parameterList.setCurrentRow(0) else: self.on_parameterList_currentRowChanged(-1) - + @pyqtSlot(int) def on_parameterList_currentRowChanged(self, currentRow): """ Private slot called, when the current row is changed. - + @param currentRow index of the current row @type int """ @@ -110,7 +111,7 @@ maxIndex = self.parameterList.count() - 1 self.upButton.setEnabled(currentRow != 0) self.downButton.setEnabled(currentRow != maxIndex) - + @pyqtSlot() def on_upButton_clicked(self): """ @@ -120,7 +121,7 @@ if row == 0: # we're already at the top return - + itm = self.parameterList.takeItem(row) self.parameterList.insertItem(row - 1, itm) self.parameterList.setCurrentItem(itm) @@ -129,7 +130,7 @@ else: self.upButton.setEnabled(True) self.downButton.setEnabled(True) - + @pyqtSlot() def on_downButton_clicked(self): """ @@ -140,7 +141,7 @@ if row == rows - 1: # we're already at the end return - + itm = self.parameterList.takeItem(row) self.parameterList.insertItem(row + 1, itm) self.parameterList.setCurrentItem(itm) @@ -149,7 +150,7 @@ self.downButton.setEnabled(False) else: self.downButton.setEnabled(True) - + @pyqtSlot() def on_removeButton_clicked(self): """ @@ -157,13 +158,14 @@ """ itm = self.parameterList.takeItem(self.parameterList.currentRow()) self.__to_be_removed.append(itm) - + @pyqtSlot() def on_addButton_clicked(self): """ Private slot to add a new parameter. """ from .AddParameterDialog import AddParameterDialog + dlg = AddParameterDialog(self) if dlg.exec() == QDialog.DialogCode.Accepted: name, default, value = dlg.getData() @@ -183,17 +185,16 @@ else: itm.setData(ChangeSignatureDialog.ValueRole, None) if self.parameterList.count(): - self.parameterList.insertItem( - self.parameterList.currentRow() + 1, itm) + self.parameterList.insertItem(self.parameterList.currentRow() + 1, itm) else: self.parameterList.addItem(itm) self.parameterList.setCurrentItem(itm) - + @pyqtSlot(QAbstractButton) def on_buttonBox_clicked(self, button): """ Private slot to act on the button pressed. - + @param button reference to the button pressed @type QAbstractButton """ @@ -201,11 +202,11 @@ self.requestPreview() elif button == self.__okButton: self.applyChanges() - + def __getParameterIndex(self, definition_info, name): """ Private method to calculate the index of the given paramter. - + @param definition_info list of lists containing the method signature definition @type list of lists of two str @@ -217,7 +218,7 @@ for index, pair in enumerate(definition_info): if pair[0] == name: return index - + return -1 def _calculateChanges(self): @@ -230,12 +231,12 @@ if itm.data(ChangeSignatureDialog.IsAddedRole): continue index = self.__getParameterIndex( - definition_info, - itm.data(ChangeSignatureDialog.NameRole)) + definition_info, itm.data(ChangeSignatureDialog.NameRole) + ) if index >= 0: removals.append(index) del definition_info[index] - + additions = [] for index in range(self.parameterList.count()): itm = self.parameterList.item(index) @@ -248,7 +249,7 @@ definition_info.insert(index, [name, default]) except Exception as err: self._refactoring.handleRopeError(err, self._title) - + newOrdering = [] for row in range(self.parameterList.count()): itm = self.parameterList.item(row) @@ -259,24 +260,27 @@ autodef = self.autodefEdit.text() if not autodef: autodef = None - - self._refactoring.sendJson("CalculateSignatureChanges", { - "ChangeGroup": self._changeGroupName, - "Title": self._title, - "FileName": self.__filename, - "Offset": self.__offset, - "Removals": removals, - "Additions": additions, - "Ordering": newOrdering, - "AutoDef": autodef, - "Hierarchy": self.hierarchyCheckBox.isChecked(), - }) - + + self._refactoring.sendJson( + "CalculateSignatureChanges", + { + "ChangeGroup": self._changeGroupName, + "Title": self._title, + "FileName": self.__filename, + "Offset": self.__offset, + "Removals": removals, + "Additions": additions, + "Ordering": newOrdering, + "AutoDef": autodef, + "Hierarchy": self.hierarchyCheckBox.isChecked(), + }, + ) + def processChangeData(self, data): """ Public method to process the change data sent by the refactoring client. - + @param data dictionary containing the change data @type dict """