PluginRefactoringRope.py

branch
eric7
changeset 365
f740b50380df
parent 362
792c2651fbd7
child 368
c206d08c28e7
--- a/PluginRefactoringRope.py	Wed May 26 17:53:08 2021 +0200
+++ b/PluginRefactoringRope.py	Wed May 26 19:07:42 2021 +0200
@@ -10,9 +10,9 @@
 import os
 import contextlib
 
-from PyQt5.QtCore import Qt, QObject, QTranslator, QCoreApplication
+from PyQt6.QtCore import Qt, QObject, QTranslator, QCoreApplication
 
-from E5Gui.E5Application import e5App
+from EricWidgets.EricApplication import ericApp
 
 import Preferences
 import Utilities
@@ -22,7 +22,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "8.0.1"
+version = "1.0.0"
 className = "RefactoringRopePlugin"
 packageName = "RefactoringRope"
 internalPackages = "rope"
@@ -30,8 +30,8 @@
 longDescription = (
     """This plug-in implements refactoring functionality"""
     """ using the Rope refactoring library. Additionally it implements an"""
-    """ alternative auto-completion and call-tips provider. It is a"""
-    """ provider for code documentation as well."""
+    """ auto-completion, call-tips and code documentation provider as well"""
+    """ as a mouse click handler."""
 )
 pyqtApi = 2
 doNotCompile = True
@@ -47,7 +47,9 @@
     Module function to create the autocompletion configuration page.
     
     @param configDlg reference to the configuration dialog
+    @type ConfigurationWidget
     @return reference to the configuration page
+    @rtype AutoCompletionRopePage
     """
     global refactoringRopePluginObject
     from RefactoringRope.ConfigurationPage.AutoCompletionRopePage import (
@@ -62,7 +64,9 @@
     Module function to create the calltips configuration page.
     
     @param configDlg reference to the configuration dialog
+    @type ConfigurationWidget
     @return reference to the configuration page
+    @rtype CallTipsRopePage
     """
     global refactoringRopePluginObject
     from RefactoringRope.ConfigurationPage.CallTipsRopePage import (
@@ -77,7 +81,9 @@
     Module function to create the mouse click handler configuration page.
     
     @param configDlg reference to the configuration dialog
+    @type ConfigurationWidget
     @return reference to the configuration page
+    @rtype MouseClickHandlerRopePage
     """
     global refactoringRopePluginObject
     from RefactoringRope.ConfigurationPage.MouseClickHandlerRopePage import (
@@ -96,10 +102,10 @@
     @rtype dict
     """
     try:
-        usesDarkPalette = e5App().usesDarkPalette()
+        usesDarkPalette = ericApp().usesDarkPalette()
     except AttributeError:
-        from PyQt5.QtGui import QPalette
-        palette = e5App().palette()
+        from PyQt6.QtGui import QPalette
+        palette = ericApp().palette()
         lightness = palette.color(QPalette.Window).lightness()
         usesDarkPalette = lightness <= 128
     iconSuffix = "dark" if usesDarkPalette else "light"
@@ -143,7 +149,7 @@
         Constructor
         
         @param ui reference to the user interface object
-        @type UI.UserInterface
+        @type UserInterface
         """
         QObject.__init__(self, ui)
         self.__ui = ui
@@ -157,8 +163,11 @@
             "CalltipsMaxFixes": 10,
             
             "MouseClickEnabled": True,
-            "MouseClickGotoModifiers": int(Qt.ControlModifier),
-            "MouseClickGotoButton": int(Qt.LeftButton),
+            "MouseClickGotoModifiers": (
+                Qt.KeyboardModifier.ControlModifier |
+                Qt.KeyboardModifier.AltModifier
+            ),
+            "MouseClickGotoButton": Qt.MouseButton.LeftButton,
         }
         
         self.__translator = None
@@ -187,7 +196,7 @@
         global refactoringRopePluginObject
         refactoringRopePluginObject = self
         
-        e5App().getObject("PluginManager").shutdown.connect(
+        ericApp().getObject("PluginManager").shutdown.connect(
             self.__shutdown)
         
         from RefactoringRope.CodeAssistServer import CodeAssistServer
@@ -198,14 +207,14 @@
         self.__refactoringServer = RefactoringServer(self, self.__ui)
         self.__refactoringServer.activate()
         
-        e5App().getObject("PluginManager").shutdown.connect(
+        ericApp().getObject("PluginManager").shutdown.connect(
             self.__shutdown)
-        e5App().getObject("ViewManager").editorOpenedEd.connect(
+        ericApp().getObject("ViewManager").editorOpenedEd.connect(
             self.__editorOpened)
-        e5App().getObject("ViewManager").editorClosedEd.connect(
+        ericApp().getObject("ViewManager").editorClosedEd.connect(
             self.__editorClosed)
         
-        for editor in e5App().getObject("ViewManager").getOpenEditors():
+        for editor in ericApp().getObject("ViewManager").getOpenEditors():
             self.__editorOpened(editor)
         
         return None, True
@@ -220,11 +229,11 @@
         if self.__codeAssistServer:
             self.__codeAssistServer.deactivate()
         
-        e5App().getObject("PluginManager").shutdown.disconnect(
+        ericApp().getObject("PluginManager").shutdown.disconnect(
             self.__shutdown)
-        e5App().getObject("ViewManager").editorOpenedEd.disconnect(
+        ericApp().getObject("ViewManager").editorOpenedEd.disconnect(
             self.__editorOpened)
-        e5App().getObject("ViewManager").editorClosedEd.disconnect(
+        ericApp().getObject("ViewManager").editorClosedEd.disconnect(
             self.__editorClosed)
         
         for editor in self.__editors[:]:
@@ -253,7 +262,7 @@
                 loaded = translator.load(translation, locale_dir)
                 if loaded:
                     self.__translator = translator
-                    e5App().installTranslator(self.__translator)
+                    ericApp().installTranslator(self.__translator)
                 else:
                     print("Warning: translation file '{0}' could not"
                           " be loaded.".format(translation))
@@ -266,14 +275,18 @@
         @param key the key of the value to get
         @type str
         @return the requested refactoring setting
+        @rtype Any
         """
         if key in ["CodeAssistEnabled", "CodeAssistCalltipsEnabled",
                    "MouseClickEnabled"]:
             return Preferences.toBool(Preferences.Prefs.settings.value(
                 self.PreferencesKey + "/" + key, self.__defaults[key]))
-        else:
+        elif key in ["CalltipsMaxFixes", "MaxFixes"]:
             return int(Preferences.Prefs.settings.value(
                 self.PreferencesKey + "/" + key, self.__defaults[key]))
+        else:
+            return Preferences.Prefs.settings.value(
+                self.PreferencesKey + "/" + key, self.__defaults[key])
     
     def setPreferences(self, key, value):
         """
@@ -282,6 +295,7 @@
         @param key the key of the setting to be set
         @type str
         @param value the value to be set
+        @type Any
         """
         Preferences.Prefs.settings.setValue(
             self.PreferencesKey + "/" + key, value)
@@ -299,14 +313,15 @@
         @rtype list of str
         """
         return ["Python3", "MicroPython",
-                "Pygments|Python", "Pygments|Python 2.x"]
+                "Pygments|Python", "Pygments|Python 2.x",
+                "Cython"]
     
     def __editorOpened(self, editor):
         """
         Private slot called, when a new editor was opened.
         
         @param editor reference to the new editor
-        @type QScintilla.Editor.Editor
+        @type Editor
         """
         languages = self.__determineLanguage()
         
@@ -321,7 +336,7 @@
         Private slot called, when an editor was closed.
         
         @param editor reference to the editor
-        @type QScintilla.Editor.Editor
+        @type Editor
         """
         if editor in self.__editors:
             editor.languageChanged.disconnect(self.__editorLanguageChanged)
@@ -347,7 +362,7 @@
         Private method to connect an editor.
         
         @param editor reference to the editor
-        @type QScintilla.Editor.Editor
+        @type Editor
         """
         editor.editorAboutToBeSaved.connect(self.__editorAboutToBeSaved)
         editor.editorSaved.connect(self.__editorSaved)
@@ -362,7 +377,7 @@
         Private method to disconnect an editor.
         
         @param editor reference to the editor
-        @type QScintilla.Editor.Editor
+        @type Editor
         """
         with contextlib.suppress(TypeError):
             editor.editorAboutToBeSaved.disconnect(self.__editorAboutToBeSaved)
@@ -378,7 +393,7 @@
         Private method to connect the mouse click handler to an editor.
         
         @param editor reference to the editor
-        @type QScintilla.Editor
+        @type Editor
         """
         if self.getPreferences("MouseClickGotoButton"):
             editor.setMouseClickHandler(
@@ -393,7 +408,7 @@
         Private method to disconnect the mouse click handler from an editor.
         
         @param editor reference to the editor
-        @type QScintilla.Editor
+        @type Editor
         """
         editor.removeMouseClickHandlers("rope")
     
@@ -402,24 +417,17 @@
         Private method to set the autocompletion hook.
         
         @param editor reference to the editor
-        @type QScintilla.Editor
+        @type Editor
         """
-        try:
-            editor.addCompletionListHook(
-                "rope", self.__codeAssistServer.requestCompletions, True)
-            self.__codeAssistServer.setAsyncCompletions(True)
-        except TypeError:
-            # interface before 17.11
-            editor.addCompletionListHook(
-                "rope", self.__codeAssistServer.getCompletions)
-            self.__codeAssistServer.setAsyncCompletions(False)
+        editor.addCompletionListHook(
+            "rope", self.__codeAssistServer.requestCompletions, True)
     
     def __unsetAutoCompletionHook(self, editor):
         """
         Private method to unset the autocompletion hook.
         
         @param editor reference to the editor
-        @type QScintilla.Editor
+        @type Editor
         """
         editor.removeCompletionListHook("rope")
     
@@ -428,7 +436,7 @@
         Private method to set the calltip hook.
         
         @param editor reference to the editor
-        @type QScintilla.Editor
+        @type Editor
         """
         editor.addCallTipHook("rope", self.__codeAssistServer.getCallTips)
     
@@ -437,7 +445,7 @@
         Private method to unset the calltip hook.
         
         @param editor reference to the editor
-        @type QScintilla.Editor
+        @type Editor
         """
         editor.removeCallTipHook("rope")
     

eric ide

mercurial