RefactoringRope/MoveDialog.py

branch
eric7
changeset 389
4f53795beff0
parent 374
958f34e97952
child 396
933b8fcd854f
--- a/RefactoringRope/MoveDialog.py	Sat Jun 25 18:06:56 2022 +0200
+++ b/RefactoringRope/MoveDialog.py	Wed Sep 21 15:30:34 2022 +0200
@@ -26,10 +26,11 @@
     """
     Class implementing the Move Method or Module dialog.
     """
+
     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
@@ -43,49 +44,52 @@
         """
         RefactoringDialogBase.__init__(self, refactoring, title, parent)
         self.setupUi(self)
-        
+
         self._changeGroupName = "Move"
-        
+
         self.__destinationCompleter = EricFileCompleter(self.destinationEdit)
-        
+
         self.__filename = filename
         self.__offset = offset
-        
+
         self.__project = ericApp().getObject("Project")
-        
-        self.__okButton = self.buttonBox.button(
-            QDialogButtonBox.StandardButton.Ok)
+
+        self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
         self.__okButton.setEnabled(False)
         self.__previewButton = self.buttonBox.addButton(
-            self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole)
+            self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole
+        )
         self.__previewButton.setDefault(True)
-        
+
         self.moveStackWidget.setCurrentIndex(0)
-        
+
         self.__moveType = ""
-        
+
         if offset is None:
             # it is a 'move module' refactoring, no need to determine
             # the move type via the client
             self.__processMoveType({"Kind": "move_module"})
         else:
-            self._refactoring.sendJson("RequestMoveType", {
-                "ChangeGroup": self._changeGroupName,
-                "Title": self._title,
-                "FileName": self.__filename,
-                "Offset": self.__offset,
-            })
-    
+            self._refactoring.sendJson(
+                "RequestMoveType",
+                {
+                    "ChangeGroup": self._changeGroupName,
+                    "Title": self._title,
+                    "FileName": self.__filename,
+                    "Offset": self.__offset,
+                },
+            )
+
     def __processMoveType(self, data):
         """
         Private method to process the move type data sent by the refactoring
         client in order to polish the dialog.
-        
+
         @param data dictionary containing the move type data
         @type dict
         """
         self.__moveType = data["Kind"]
-        
+
         if self.__moveType == "move_method":
             self.setWindowTitle(self.tr("Move Method"))
             self.moveStackWidget.setCurrentIndex(1)
@@ -95,75 +99,77 @@
             self.setWindowTitle(self.tr("Move Global Method"))
             self.moveStackWidget.setCurrentIndex(2)
             self.destinationLabel.setText(self.tr("Destination Module:"))
-            self.destinationEdit.setToolTip(self.tr(
-                "Enter the destination module for the method"))
-            self.selectButton.setToolTip(self.tr(
-                "Select the destination module via a file selection dialog"))
+            self.destinationEdit.setToolTip(
+                self.tr("Enter the destination module for the method")
+            )
+            self.selectButton.setToolTip(
+                self.tr("Select the destination module via a file selection dialog")
+            )
         elif self.__moveType == "move_module":
             self.setWindowTitle(self.tr("Move Module"))
             self.moveStackWidget.setCurrentIndex(2)
             self.destinationLabel.setText(self.tr("Destination Package:"))
-            self.destinationEdit.setToolTip(self.tr(
-                "Enter the destination package for the module"))
-            self.selectButton.setToolTip(self.tr(
-                "Select the destination package via a directory selection"
-                " dialog"))
+            self.destinationEdit.setToolTip(
+                self.tr("Enter the destination package for the module")
+            )
+            self.selectButton.setToolTip(
+                self.tr(
+                    "Select the destination package via a directory selection" " dialog"
+                )
+            )
         else:
             self.setWindowTitle(self.tr("Move"))
             self.moveStackWidget.setCurrentIndex(0)
-        
+
         self.__updateUI()
-        
+
         msh = self.minimumSizeHint()
         self.resize(max(self.width(), msh.width()), msh.height())
-    
+
     @pyqtSlot(str)
     def on_attributeEdit_textChanged(self, text):
         """
         Private slot to react to changes of the attribute.
-        
+
         @param text text entered into the edit
         @type str
         """
         self.__updateUI()
-    
+
     @pyqtSlot(str)
     def on_methodEdit_textChanged(self, text):
         """
         Private slot to react to changes of the method.
-        
+
         @param text text entered into the edit
         @type str
         """
         self.__updateUI()
-    
+
     @pyqtSlot(str)
     def on_destinationEdit_textChanged(self, text):
         """
         Private slot to react to changes of the destination module.
-        
+
         @param text text entered into the edit
         @type str
         """
         self.__updateUI()
-    
+
     def __updateUI(self):
         """
         Private method to perform various UI updates.
         """
         if self.__moveType == "move_method":
-            enable = (
-                self.attributeEdit.text() != "" and
-                self.methodEdit.text() != ""
-            )
+            enable = self.attributeEdit.text() != "" and self.methodEdit.text() != ""
         elif self.__moveType in ["move_global_method", "move_module"]:
             enable = self.destinationEdit.text() != ""
         else:
             enable = False
-        
+
         self.__okButton.setEnabled(enable)
         self.__previewButton.setEnabled(enable)
-    
+
     @pyqtSlot()
     def on_selectButton_clicked(self):
         """
@@ -180,70 +186,74 @@
                 self,
                 self.windowTitle(),
                 dest,
-                self.tr("Python Files (*.py *.py3);;All Files (*)"))
-            if self.__moveType == "move_global_method" else
+                self.tr("Python Files (*.py *.py3);;All Files (*)"),
+            )
+            if self.__moveType == "move_global_method"
+            else
             # move_module
-            EricFileDialog.getExistingDirectory(
-                self,
-                self.windowTitle(),
-                dest)
+            EricFileDialog.getExistingDirectory(self, self.windowTitle(), dest)
         )
-        
+
         if destination:
             destination = Utilities.toNativeSeparators(destination)
             if not self.__project.startswithProjectPath(destination):
                 if self.__moveType == "move_global_method":
-                    errorMessage = self.tr("""The selected module must be """
-                                           """inside the project.""")
+                    errorMessage = self.tr(
+                        """The selected module must be """ """inside the project."""
+                    )
                 else:
                     # move_module
-                    errorMessage = self.tr("""The selected directory must"""
-                                           """ be inside the project.""")
-                EricMessageBox.critical(
-                    self,
-                    self.windowTitle(),
-                    errorMessage)
+                    errorMessage = self.tr(
+                        """The selected directory must""" """ be inside the project."""
+                    )
+                EricMessageBox.critical(self, self.windowTitle(), errorMessage)
                 return
-            
+
             if self.__moveType == "move_global_method":
                 if not os.path.exists(destination):
                     EricMessageBox.critical(
                         self,
                         self.windowTitle(),
-                        self.tr("""The selected module <b>{0}</b> does"""
-                                """ not exist.""").format(destination))
+                        self.tr(
+                            """The selected module <b>{0}</b> does""" """ not exist."""
+                        ).format(destination),
+                    )
                     return
             else:
                 # move_module
-                if not os.path.exists(
-                        os.path.join(destination, "__init__.py")):
+                if not os.path.exists(os.path.join(destination, "__init__.py")):
                     EricMessageBox.critical(
                         self,
                         self.windowTitle(),
-                        self.tr("""The selected directory <b>{0}</b> is"""
-                                """ not a package.""").format(destination))
+                        self.tr(
+                            """The selected directory <b>{0}</b> is"""
+                            """ not a package."""
+                        ).format(destination),
+                    )
                     return
-            
+
             destination = self.__project.getRelativePath(destination)
             self.destinationEdit.setText(destination)
-    
+
     def __checkDestination(self):
         """
         Private method to check the destination entered.
-        
+
         @return flag indicating a valid entry
         @rtype bool
         """
         destination = os.path.join(
-            self.__project.getProjectPath(),
-            self.destinationEdit.text())
+            self.__project.getProjectPath(), self.destinationEdit.text()
+        )
         if self.__moveType == "move_global_method":
             if not os.path.exists(destination):
                 EricMessageBox.critical(
                     self,
                     self.windowTitle(),
-                    self.tr("""The selected module <b>{0}</b> does"""
-                            """ not exist.""").format(destination))
+                    self.tr(
+                        """The selected module <b>{0}</b> does""" """ not exist."""
+                    ).format(destination),
+                )
                 return False
         else:
             # move_module
@@ -251,28 +261,31 @@
                 EricMessageBox.critical(
                     self,
                     self.windowTitle(),
-                    self.tr("""The selected directory <b>{0}</b> is"""
-                            """ not a package.""").format(destination))
+                    self.tr(
+                        """The selected directory <b>{0}</b> is""" """ not a package."""
+                    ).format(destination),
+                )
                 return False
-        
+
         return True
-    
+
     @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
         """
         if self.__moveType == "move_method" or (
-            self.__moveType in ["move_global_method", "move_module"] and
-                self.__checkDestination()):
+            self.__moveType in ["move_global_method", "move_module"]
+            and self.__checkDestination()
+        ):
             if button == self.__previewButton:
                 self.requestPreview()
             elif button == self.__okButton:
                 self.applyChanges()
-    
+
     def _calculateChanges(self):
         """
         Protected method to initiate the calculation of the changes.
@@ -280,23 +293,26 @@
         newName = self.methodEdit.text()
         if not newName:
             newName = None
-        
-        self._refactoring.sendJson("CalculateMoveChanges", {
-            "ChangeGroup": self._changeGroupName,
-            "Title": self.windowTitle(),
-            "FileName": self.__filename,
-            "Offset": self.__offset,
-            "Kind": self.__moveType,
-            "NewName": newName,
-            "Attribute": self.attributeEdit.text(),
-            "DestinationModule": self.destinationEdit.text(),
-        })
-    
+
+        self._refactoring.sendJson(
+            "CalculateMoveChanges",
+            {
+                "ChangeGroup": self._changeGroupName,
+                "Title": self.windowTitle(),
+                "FileName": self.__filename,
+                "Offset": self.__offset,
+                "Kind": self.__moveType,
+                "NewName": newName,
+                "Attribute": self.attributeEdit.text(),
+                "DestinationModule": self.destinationEdit.text(),
+            },
+        )
+
     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
         """

eric ide

mercurial