RefactoringRope/Refactoring.py

branch
server_client_variant
changeset 167
3c8e875d0326
parent 166
6fc202183b3b
child 168
53d76b4fc1ac
diff -r 6fc202183b3b -r 3c8e875d0326 RefactoringRope/Refactoring.py
--- a/RefactoringRope/Refactoring.py	Sat Sep 16 16:40:50 2017 +0200
+++ b/RefactoringRope/Refactoring.py	Sat Sep 16 18:51:19 2017 +0200
@@ -20,7 +20,6 @@
     str = unicode   # __IGNORE_WARNING__
 sys.path.insert(0, path)
 
-import rope
 import rope.base.libutils
 import rope.base.exceptions
 
@@ -66,6 +65,19 @@
         
         from FileSystemCommands import E5FileSystemCommands
         self.__fsCommands = E5FileSystemCommands(self.__e5project)
+        
+        self.__methodMapping = {
+            "Config": self.__setConfig,
+            "Progress": self.__processProgress,
+            "QueryReferencesResult": self.__queryReferencesResult,
+            "QueryDefinitionResult": self.__queryDefinitionResult,
+            "QueryImplementationsResult": self.__queryImplementationsResult,
+            "SoaFinished": self.__soaFinished,
+            
+            "FileSystemCommand": self.__fsCommands.processFileSystemCommand,
+            
+            "ClientException": self.__processClientException,
+        }
     
     def initActions(self):
         """
@@ -661,7 +673,7 @@
         self.actions.append(self.refactoringEditConfigAct)
         
         self.refactoringHelpAct = E5Action(
-            self.tr('Rope help'),
+            self.tr('Rope Help'),
             self.tr('Rope &Help'),
             0, 0,
             self, 'refactoring_help')
@@ -796,6 +808,7 @@
         menu.addAction(self.refactoringHelpAct)
         
         self.__mainMenu = menu
+        
         return menu
 
     ##################################################################
@@ -806,11 +819,14 @@
         """
         Private slot to show some info about rope.
         """
-        E5MessageBox.about(
-            self.__ui,
-            self.tr("About rope"),
-            self.tr("{0}\nVersion {1}\n\n{2}".format(
-                rope.INFO, rope.VERSION, rope.COPYRIGHT)))
+        if self.__ropeConfig:
+            E5MessageBox.about(
+                self.__ui,
+                self.tr("About rope"),
+                self.tr("{0}\nVersion {1}\n\n{2}".format(
+                    self.__ropeConfig["RopeInfo"],
+                    self.__ropeConfig["RopeVersion"],
+                    self.__ropeConfig["RopeCopyright"])))
     
     def __canUndo(self):
         """
@@ -2179,6 +2195,43 @@
     ## methods below are private utility methods
     ##################################################################
     
+    def __processProgress(self, params):
+        """
+        Private method to handle Progress commands.
+        
+        @param params dictionary containing the progress data
+        @type dict
+        """
+        subcommand = params["Subcommand"]
+        if subcommand == "Init":
+            if self.__progressDialog is not None:
+                self.__progressDialog.reset()
+            
+            progressDialog = RopeProgressDialog(
+                self, params["Title"], params["Interruptable"], self.__ui)
+            progressDialog.show()
+            self.__progressDialog = progressDialog
+            QApplication.processEvents()
+        
+        elif subcommand == "Progress":
+            if self.__progressDialog is not None:
+                self.__progressDialog.updateProgress(params)
+            
+        elif subcommand == "Reset":
+            if self.__progressDialog is not None:
+                self.__progressDialog.reset()
+    
+    def __setConfig(self, params):
+        """
+        Private method to set the rope client configuration data.
+        
+        @param params dictionary containing the configuration data
+        @type dict
+        """
+        self.__ropeConfig = params
+        # keys: RopeFolderName, DefaultConfig, RopeHelpFile,
+        # RopeInfo, RopeVersion, RopeCopyright
+    
     def __ropeConfigFile(self):
         """
         Private method to get the name of the rope configuration file.
@@ -2235,13 +2288,19 @@
         self.__projectpath = self.__e5project.getProjectPath()
         self.__projectLanguage = self.__e5project.getProjectLanguage()
         
+        ok = False
+        
         if self.__projectLanguage.startswith("Python"):
-            if self.__projectLanguage == "Python2":
-                interpreter = Preferences.getDebugger("PythonInterpreter")
-            elif self.__projectLanguage == "Python3":
-                interpreter = Preferences.getDebugger("Python3Interpreter")
-            else:
-                interpreter = ""
+            # get interpreter from project first
+            interpreter = self.__e5project.getDebugProperty("INTERPRETER")
+            if not interpreter or not Utilities.isinpath(interpreter):
+                # get it from debugger settings second
+                if self.__projectLanguage == "Python2":
+                    interpreter = Preferences.getDebugger("PythonInterpreter")
+                elif self.__projectLanguage == "Python3":
+                    interpreter = Preferences.getDebugger("Python3Interpreter")
+                else:
+                    interpreter = ""
             if interpreter:
                 ok = self.__startRefactoringClient(interpreter)
                 if not ok:
@@ -2259,6 +2318,12 @@
                     " suitable interpreter is configured. Refactoring is"
                     " disabled."
                 ).format(self.__projectLanguage))
+        else:
+            self.__ui.appendToStderr(self.tr(
+                "Refactoring for project language '{0}' is not supported."
+            ).format(self.__projectLanguage))
+        
+        self.__mainMenu.menuAction().setEnabled(ok)
     
     def projectClosed(self):
         """
@@ -2266,6 +2331,7 @@
         """
         for act in self.actions:
             act.setEnabled(False)
+        self.__mainMenu.menuAction().setEnabled(False)
         
         self.stopClient()
         
@@ -2365,72 +2431,46 @@
         @param params dictionary with method specific parameters
         @type dict
         """
-        if method == "Config":
-            self.__ropeConfig = params
-            # keys: RopeFolderName, DefaultConfig
+        self.__methodMapping[method](params)
+    
+    def __processClientException(self, params):
+        """
+        Private method to handle exceptions of the refactoring client.
         
-        elif method == "ClientException":
-            if params["ExceptionType"] == "ProtocolError":
-                E5MessageBox.critical(
-                    None,
-                    self.tr("Refactoring Protocol Error"),
-                    self.tr("""<p>The data received from the refactoring"""
-                            """ server could not be decoded. Please report"""
-                            """ this issue with the received data to the"""
-                            """ eric bugs email address.</p>"""
-                            """<p>Error: {0}</p>"""
-                            """<p>Data:<br/>{0}</p>""").format(
-                        params["ExceptionValue"],
-                        Utilities.html_encode(params["ProtocolData"])),
-                    E5MessageBox.StandardButtons(
-                        E5MessageBox.Ok))
-            else:
-                E5MessageBox.critical(
-                    None,
-                    self.tr("Refactoring Client Error"),
-                    self.tr("<p>An exception happened in the refactoring"
-                            " client. Please report it to the eric bugs"
-                            " email address.</p>"
-                            "<p>Exception: {0}</p>"
-                            "<p>Value: {1}</p>"
-                            "Traceback: {2}</p>").format(
-                        Utilities.html_encode(params["ExceptionType"]),
-                        params["ExceptionValue"],
-                        params["Traceback"].replace("\r\n", "<br/>")
-                        .replace("\n", "<br/>").replace("\r", "<br/>"),
-                    ),
-                    E5MessageBox.StandardButtons(
-                        E5MessageBox.Ok))
-        
-        elif method == "FileSystemCommand":
-            self.__fsCommands.processFileSystemCommand(params)
-        
-        elif method == "ProgressInit":
-            progressDialog = RopeProgressDialog(
-                self, params["Title"], params["Interrutable"], self.__ui)
-            progressDialog.show()
-            self.__progressDialog = progressDialog
-            QApplication.processEvents()
-        
-        elif method == "Progress":
-            if self.__progressDialog is not None:
-                self.__progressDialog.updateProgress(params)
-        
-        elif method == "ProgressReset":
-            if self.__progressDialog is not None:
-                self.__progressDialog.reset()
-        
-        elif method == "QueryReferencesResult":
-            self.__queryReferencesResult(params)
-        
-        elif method == "QueryDefinitionResult":
-            self.__queryDefinitionResult(params)
-        
-        elif method == "QueryImplementationsResult":
-            self.__queryImplementationsResult(params)
-        
-        elif method == "SoaFinished":
-            self.__soaFinished(params)
+        @param params dictionary containing the exception data
+        @type dict
+        """
+        if params["ExceptionType"] == "ProtocolError":
+            E5MessageBox.critical(
+                None,
+                self.tr("Refactoring Protocol Error"),
+                self.tr("""<p>The data received from the refactoring"""
+                        """ server could not be decoded. Please report"""
+                        """ this issue with the received data to the"""
+                        """ eric bugs email address.</p>"""
+                        """<p>Error: {0}</p>"""
+                        """<p>Data:<br/>{0}</p>""").format(
+                    params["ExceptionValue"],
+                    Utilities.html_encode(params["ProtocolData"])),
+                E5MessageBox.StandardButtons(
+                    E5MessageBox.Ok))
+        else:
+            E5MessageBox.critical(
+                None,
+                self.tr("Refactoring Client Error"),
+                self.tr("<p>An exception happened in the refactoring"
+                        " client. Please report it to the eric bugs"
+                        " email address.</p>"
+                        "<p>Exception: {0}</p>"
+                        "<p>Value: {1}</p>"
+                        "Traceback: {2}</p>").format(
+                    Utilities.html_encode(params["ExceptionType"]),
+                    params["ExceptionValue"],
+                    params["Traceback"].replace("\r\n", "<br/>")
+                    .replace("\n", "<br/>").replace("\r", "<br/>"),
+                ),
+                E5MessageBox.StandardButtons(
+                    E5MessageBox.Ok))
     
     def __startRefactoringClient(self, interpreter):
         """

eric ide

mercurial