PluginRefactoringRope.py

Sun, 08 Mar 2015 18:12:42 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 08 Mar 2015 18:12:42 +0100
changeset 112
ddeaa445f81f
parent 107
3ee7bd0bba9a
child 114
b176e34cd6bd
permissions
-rw-r--r--

Prepared new release.

1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
1 # -*- coding: utf-8 -*-
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
2
94
03d6a17c66ac Updated copyright for 2015.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 87
diff changeset
3 # Copyright (c) 2010 - 2015 Detlev Offenbach <detlev@die-offenbachs.de>
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
4 #
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
5
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
6 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
7 Module implementing the Rope refactoring plugin.
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
8 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
9
76
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
10 from __future__ import unicode_literals
50
a29c3d2e6dc0 rope for Python2 projects enabled, if running on Python2
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 48
diff changeset
11
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
12 import os
50
a29c3d2e6dc0 rope for Python2 projects enabled, if running on Python2
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 48
diff changeset
13 import sys
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
14
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
15 from PyQt5.QtCore import QObject, QTranslator, QCoreApplication, QTimer
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
16
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
17 from E5Gui.E5Application import e5App
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
18
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
19 import Preferences
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
20 import Utilities
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
21
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
22 from Preferences.Shortcuts import readShortcuts
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
23
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
24 # Start-Of-Header
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
25 name = "Refactoring Rope Plugin"
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
26 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
27 autoactivate = True
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
28 deactivateable = True
112
ddeaa445f81f Prepared new release.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 107
diff changeset
29 version = "4.0.3"
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
30 className = "RefactoringRopePlugin"
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
31 packageName = "RefactoringRope"
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
32 internalPackages = "rope"
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
33 shortDescription = "Refactoring using the Rope library."
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
34 longDescription = """This plug-in implements refactoring functionality""" \
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
35 """ using the Rope refactoring library. Additonally it implements an """ \
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
36 """ alternative auto-completion and calltips provider. Only""" \
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
37 """ refactoring, completions and calltips in the same Python variant""" \
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
38 """ as Eric is running is allowed."""
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
39 pyqtApi = 2
52
abd297a94a55 Added the 'doNotCompile' plug-in module header entry to avoid attempting to compile the sources, which will raise errors due to the rope variants for both Python versions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 51
diff changeset
40 doNotCompile = True
76
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
41 python2Compatible = True
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
42 # End-Of-Header
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
43
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
44 error = ""
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
45
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
46 refactoringRopePluginObject = None
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
47
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
48
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
49 def createAutoCompletionPage(configDlg):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
50 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
51 Module function to create the autocompletion configuration page.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
52
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
53 @param configDlg reference to the configuration dialog
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
54 @return reference to the configuration page
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
55 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
56 global refactoringRopePluginObject
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
57 from RefactoringRope.ConfigurationPage.AutoCompletionRopePage \
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
58 import AutoCompletionRopePage
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
59 page = AutoCompletionRopePage(refactoringRopePluginObject)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
60 return page
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
61
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
62
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
63 def createCallTipsPage(configDlg):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
64 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
65 Module function to create the calltips configuration page.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
66
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
67 @param configDlg reference to the configuration dialog
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
68 @return reference to the configuration page
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
69 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
70 global refactoringRopePluginObject
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
71 from RefactoringRope.ConfigurationPage.CallTipsRopePage \
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
72 import CallTipsRopePage
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
73 page = CallTipsRopePage(refactoringRopePluginObject)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
74 return page
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
75
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
76
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
77 def getConfigData():
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
78 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
79 Module function returning data as required by the configuration dialog.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
80
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
81 @return dictionary containing the relevant data
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
82 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
83 return {
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
84 "ropeAutoCompletionPage" : [
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
85 QCoreApplication.translate("RefactoringRopePlugin", "Rope"),
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
86 os.path.join("RefactoringRope", "ConfigurationPage",
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
87 "preferences-refactoring.png"),
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
88 createAutoCompletionPage, "editorAutocompletionPage", None],
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
89 "ropeCallTipsPage" : \
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
90 [QCoreApplication.translate("RefactoringRopePlugin", "Rope"),
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
91 os.path.join("RefactoringRope", "ConfigurationPage",
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
92 "preferences-refactoring.png"),
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
93 createCallTipsPage, "editorCalltipsPage", None],
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
94 }
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
95
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
96
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
97 def prepareUninstall():
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
98 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
99 Module function to prepare for an uninstallation.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
100 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
101 Preferences.Prefs.settings.remove(RefactoringRopePlugin.PreferencesKey)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
102
20
83b71483e198 Made the code PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
103
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
104 class RefactoringRopePlugin(QObject):
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
105 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
106 Class implementing the Rope refactoring plugin.
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
107 """
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
108 PreferencesKey = "RefactoringRope"
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
109
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
110 def __init__(self, ui):
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
111 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
112 Constructor
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
113
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
114 @param ui reference to the user interface object (UI.UserInterface)
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
115 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
116 QObject.__init__(self, ui)
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
117 self.__ui = ui
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
118 self.__initialize()
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
119
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
120 self.__defaults = {
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
121 "CodeAssistEnabled" : False,
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
122 "MaxFixes" : 10,
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
123 "CodeAssistTimeout" : 100,
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
124 "ShowQScintillaCompletions": True,
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
125
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
126 "CodeAssistCalltipsEnabled" : False,
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
127 "CalltipsMaxFixes" : 10,
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
128 }
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
129
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
130 self.__translator = None
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
131 self.__loadTranslator()
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
132
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
133 self.__acTimer = QTimer(self)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
134 self.__acTimer.setSingleShot(True)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
135 self.__acTimer.setInterval(self.getPreferences("CodeAssistTimeout"))
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
136 self.__acTimer.timeout.connect(self.__codeAssist)
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
137
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
138 def __initialize(self):
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
139 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
140 Private slot to (re)initialize the plugin.
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
141 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
142 self.__object = None
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
143 self.__caObject = None
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
144
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
145 self.__mainAct = None
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
146 self.__mainMenu = None
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
147 self.__projectIsOpen = False
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
148
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
149 self.__editors = []
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
150
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
151 self.__currentEditor = None
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
152 self.__savedEditorName = None
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
153 self.__oldEditorText = ""
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
154
31
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
155 def __checkUiVersion(self):
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
156 """
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
157 Private method to check, if the IDE has a suitable version.
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
158
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
159 @return flag indicating a suitable version (boolean)
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
160 """
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
161 global error
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
162
87
1fbf5fdbe721 Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 83
diff changeset
163 suitable = self.__ui.versionIsNewer("5.99.99", "20140701")
31
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
164 if not suitable:
87
1fbf5fdbe721 Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 83
diff changeset
165 error = self.tr("Your version of eric6 is not supported.")
31
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
166 return suitable
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
167
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
168 def activate(self):
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
169 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
170 Public method to activate this plugin.
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
171
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
172 @return tuple of None and activation status (boolean)
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
173 """
31
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
174 global error
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
175 error = "" # clear previous error
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
176
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
177 if not self.__checkUiVersion():
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
178 return None, False
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
179
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
180 global refactoringRopePluginObject
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
181 refactoringRopePluginObject = self
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
182
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
183 from RefactoringRope.Refactoring import Refactoring
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
184 from RefactoringRope.CodeAssist import CodeAssist
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
185
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
186 self.__caObject = CodeAssist(self, self)
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
187
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
188 self.__object = Refactoring(self, self.__ui)
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
189 self.__object.initActions()
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
190 e5App().registerPluginObject("RefactoringRope", self.__object)
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
191 try:
20
83b71483e198 Made the code PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
192 readShortcuts(pluginName="RefactoringRope")
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
193 except TypeError:
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
194 # backwards comaytibility, ignore
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
195 pass
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
196
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
197 self.__mainMenu = self.__object.initMenu()
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
198 extrasAct = self.__ui.getMenuBarAction("extras")
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
199 self.__mainAct = self.__ui.menuBar().insertMenu(
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
200 extrasAct, self.__mainMenu)
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
201
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
202 if e5App().getObject("Project").isOpen():
76
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
203 self.__projectOpened()
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
204
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
205 if self.__projectIsOpen:
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
206 self.__object.projectOpened()
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
207
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
208 e5App().getObject("ViewManager").editorOpenedEd.connect(
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
209 self.__editorOpened)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
210 e5App().getObject("ViewManager").editorClosedEd.connect(
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
211 self.__editorClosed)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
212
31
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
213 e5App().getObject("Project").projectOpened.connect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
214 self.__object.projectOpened)
76
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
215 e5App().getObject("Project").projectPropertiesChanged.connect(
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
216 self.__object.projectOpened)
31
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
217 e5App().getObject("Project").projectClosed.connect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
218 self.__object.projectClosed)
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
219 e5App().getObject("Project").newProject.connect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
220 self.__object.projectOpened)
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
221
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
222 e5App().getObject("Project").projectOpened.connect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
223 self.__projectOpened)
76
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
224 e5App().getObject("Project").projectPropertiesChanged.connect(
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
225 self.__projectOpened)
31
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
226 e5App().getObject("Project").projectClosed.connect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
227 self.__projectClosed)
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
228 e5App().getObject("Project").newProject.connect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
229 self.__projectOpened)
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
230
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
231 if e5App().getObject("Project").isOpen():
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
232 for editor in e5App().getObject("ViewManager").getOpenEditors():
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
233 self.__editorOpened(editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
234
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
235 return None, True
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
236
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
237 def deactivate(self):
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
238 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
239 Public method to deactivate this plugin.
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
240 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
241 e5App().unregisterPluginObject("RefactoringRope")
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
242
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
243 e5App().getObject("ViewManager").editorOpenedEd.disconnect(
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
244 self.__editorOpened)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
245 e5App().getObject("ViewManager").editorClosedEd.disconnect(
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
246 self.__editorClosed)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
247
31
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
248 e5App().getObject("Project").projectOpened.disconnect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
249 self.__object.projectOpened)
76
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
250 e5App().getObject("Project").projectPropertiesChanged.disconnect(
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
251 self.__object.projectOpened)
31
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
252 e5App().getObject("Project").projectClosed.disconnect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
253 self.__object.projectClosed)
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
254 e5App().getObject("Project").newProject.disconnect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
255 self.__object.projectOpened)
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
256
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
257 e5App().getObject("Project").projectOpened.disconnect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
258 self.__projectOpened)
76
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
259 e5App().getObject("Project").projectPropertiesChanged.disconnect(
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
260 self.__projectOpened)
31
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
261 e5App().getObject("Project").projectClosed.disconnect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
262 self.__projectClosed)
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
263 e5App().getObject("Project").newProject.disconnect(
0389d4a924cc Dropped support for eric 5.0.x.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 20
diff changeset
264 self.__projectOpened)
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
265
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
266 self.__ui.menuBar().removeAction(self.__mainAct)
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
267
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
268 for editor in self.__editors[:]:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
269 self.__editorClosed(editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
270
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
271 self.__initialize()
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
272
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
273 def __loadTranslator(self):
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
274 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
275 Private method to load the translation file.
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
276 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
277 if self.__ui is not None:
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
278 loc = self.__ui.getLocale()
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
279 if loc and loc != "C":
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
280 locale_dir = \
20
83b71483e198 Made the code PEP-8 compliant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1
diff changeset
281 os.path.join(os.path.dirname(__file__),
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
282 "RefactoringRope", "i18n")
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
283 translation = "rope_%s" % loc
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
284 translator = QTranslator(None)
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
285 loaded = translator.load(translation, locale_dir)
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
286 if loaded:
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
287 self.__translator = translator
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
288 e5App().installTranslator(self.__translator)
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
289 else:
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
290 print("Warning: translation file '{0}' could not"
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
291 " be loaded.".format(translation))
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
292 print("Using default.")
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
293
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
294 def getPreferences(self, key):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
295 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
296 Public method to retrieve the various refactoring settings.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
297
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
298 @param key the key of the value to get
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
299 @param prefClass preferences class used as the storage area
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
300 @return the requested refactoring setting
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
301 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
302 if key in ["CodeAssistEnabled", "CodeAssistCalltipsEnabled",
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
303 "ShowQScintillaCompletions"]:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
304 return Preferences.toBool(Preferences.Prefs.settings.value(
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
305 self.PreferencesKey + "/" + key, self.__defaults[key]))
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
306 else:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
307 return int(Preferences.Prefs.settings.value(
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
308 self.PreferencesKey + "/" + key, self.__defaults[key]))
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
309
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
310 def setPreferences(self, key, value):
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
311 """
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
312 Public method to store the various refactoring settings.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
313
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
314 @param key the key of the setting to be set (string)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
315 @param value the value to be set
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
316 @param prefClass preferences class used as the storage area
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
317 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
318 Preferences.Prefs.settings.setValue(
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
319 self.PreferencesKey + "/" + key, value)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
320
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
321 if key in ["CodeAssistEnabled", "CodeAssistCalltipsEnabled"]:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
322 if value:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
323 if e5App().getObject("Project").isOpen():
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
324 for editor in e5App().getObject("ViewManager")\
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
325 .getOpenEditors():
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
326 if editor not in self.__editors:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
327 self.__editorOpened(editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
328 else:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
329 for editor in self.__editors[:]:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
330 self.__editorClosed(editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
331 elif key == "CodeAssistTimeout":
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
332 self.__acTimer.setInterval(value)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
333
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
334 def __determineLanguage(self):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
335 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
336 Private method to determine the valid language strings.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
337
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
338 @return list of valid language strings (list of string)
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
339 """
50
a29c3d2e6dc0 rope for Python2 projects enabled, if running on Python2
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 48
diff changeset
340 if sys.version_info[0] == 3:
a29c3d2e6dc0 rope for Python2 projects enabled, if running on Python2
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 48
diff changeset
341 lang = ["Python3"]
a29c3d2e6dc0 rope for Python2 projects enabled, if running on Python2
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 48
diff changeset
342 elif sys.version_info[0] == 2:
a29c3d2e6dc0 rope for Python2 projects enabled, if running on Python2
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 48
diff changeset
343 lang = ["Python", "Python2"]
a29c3d2e6dc0 rope for Python2 projects enabled, if running on Python2
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 48
diff changeset
344 else:
a29c3d2e6dc0 rope for Python2 projects enabled, if running on Python2
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 48
diff changeset
345 lang = []
76
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
346
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
347 return lang
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
348
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
349 def __projectOpened(self):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
350 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
351 Private slot to handle the projectOpened signal.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
352 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
353 lang = self.__determineLanguage()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
354
76
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
355 enabled = e5App().getObject("Project").getProjectLanguage() in lang
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
356 self.__mainAct.setEnabled(enabled)
936b2a98fe4e Merge with Py2 comp.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 74 63
diff changeset
357 self.__projectIsOpen = enabled
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
358
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
359 def __projectClosed(self):
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
360 """
87
1fbf5fdbe721 Ported to PyQt5 and eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 83
diff changeset
361 Private slot to handle the projectClosed signal.
1
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
362 """
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
363 self.__mainAct.setEnabled(False)
9f687137a929 Started implementing the basic functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
364 self.__projectIsOpen = False
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
365
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
366 def __editorOpened(self, editor):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
367 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
368 Private slot called, when a new editor was opened.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
369
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
370 @param editor reference to the new editor (QScintilla.Editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
371 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
372 lang = self.__determineLanguage()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
373
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
374 if editor.getLanguage() in lang:
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
375 self.__connectEditor(editor)
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
376
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
377 editor.languageChanged.connect(self.__editorLanguageChanged)
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
378 self.__editors.append(editor)
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
379
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
380 def __editorClosed(self, editor):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
381 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
382 Private slot called, when an editor was closed.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
383
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
384 @param editor reference to the editor (QScintilla.Editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
385 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
386 if editor in self.__editors:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
387 editor.languageChanged.disconnect(self.__editorLanguageChanged)
101
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
388 self.__disconnectEditor(editor)
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
389 self.__editors.remove(editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
390
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
391 def __editorLanguageChanged(self, language):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
392 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
393 Private slot to handle the language change of an editor.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
394
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
395 @param language programming language of the editor (string)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
396 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
397 editor = self.sender()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
398 lang = self.__determineLanguage()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
399
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
400 if language in lang:
101
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
401 self.__connectEditor(editor)
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
402 else:
101
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
403 self.__disconnectEditor(editor)
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
404
101
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
405 def __connectEditor(self, editor):
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
406 """
101
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
407 Private method to connect an editor.
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
408
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
409 @param editor reference to the editor (QScintilla.Editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
410 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
411 editor.editorAboutToBeSaved.connect(self.__editorAboutToBeSaved)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
412 editor.editorSaved.connect(self.__editorSaved)
101
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
413
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
414 if self.getPreferences("CodeAssistEnabled"):
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
415 self.__setAutoCompletionHook(editor)
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
416 if self.getPreferences("CodeAssistCalltipsEnabled"):
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
417 self.__setCalltipsHook(editor)
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
418
101
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
419 def __disconnectEditor(self, editor):
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
420 """
101
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
421 Private method to disconnect an editor.
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
422
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
423 @param editor reference to the editor (QScintilla.Editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
424 """
101
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
425 try:
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
426 editor.editorAboutToBeSaved.disconnect(self.__editorAboutToBeSaved)
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
427 editor.editorSaved.disconnect(self.__editorSaved)
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
428 except TypeError:
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
429 # just ignore it
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
430 pass
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
431
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
432 if editor.autoCompletionHook() == self.codeAssist:
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
433 self.__unsetAutoCompletionHook(editor)
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
434 if editor.callTipHook() == self.codeAssistCallTip:
5098ad8960ed Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 100
diff changeset
435 self.__unsetCalltipsHook(editor)
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
436
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
437 def __completionListSelected(self, id, txt):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
438 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
439 Private slot to handle the selection from the completion list.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
440
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
441 @param id the ID of the user list (should be 1) (integer)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
442 @param txt the selected text (QString)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
443 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
444 from QScintilla.Editor import EditorAutoCompletionListID
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
445
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
446 editor = self.sender()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
447 if id == EditorAutoCompletionListID:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
448 lst = txt.split()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
449 if len(lst) > 1:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
450 txt = lst[0]
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
451
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
452 if Preferences.getEditor("AutoCompletionReplaceWord"):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
453 editor.selectCurrentWord()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
454 editor.removeSelectedText()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
455 line, col = editor.getCursorPosition()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
456 else:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
457 line, col = editor.getCursorPosition()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
458 wLeft = editor.getWordLeft(line, col)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
459 if not txt.startswith(wLeft):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
460 editor.selectCurrentWord()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
461 editor.removeSelectedText()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
462 line, col = editor.getCursorPosition()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
463 elif wLeft:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
464 txt = txt[len(wLeft):]
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
465 editor.insert(txt)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
466 editor.setCursorPosition(line, col + len(txt))
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
467
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
468 def __setAutoCompletionHook(self, editor):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
469 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
470 Private method to set the autocompletion hook.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
471
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
472 @param editor reference to the editor (QScintilla.Editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
473 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
474 editor.userListActivated.connect(self.__completionListSelected)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
475 editor.setAutoCompletionHook(self.codeAssist)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
476
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
477 def __unsetAutoCompletionHook(self, editor):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
478 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
479 Private method to unset the autocompletion hook.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
480
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
481 @param editor reference to the editor (QScintilla.Editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
482 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
483 editor.unsetAutoCompletionHook()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
484 editor.userListActivated.disconnect(self.__completionListSelected)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
485
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
486 def codeAssist(self, editor, context = False):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
487 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
488 Public method to determine the autocompletion proposals.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
489
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
490 @param editor reference to the editor object, that called this method
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
491 QScintilla.Editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
492 @param context flag indicating to autocomplete a context (boolean)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
493 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
494 self.__currentEditor = editor
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
495 if self.getPreferences("CodeAssistTimeout"):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
496 self.__acTimer.stop()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
497 self.__acTimer.start()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
498 else:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
499 self.__codeAssist()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
500
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
501 def __codeAssist(self):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
502 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
503 Private slot to show a list with completion proposals.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
504 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
505 from QScintilla.Editor import EditorAutoCompletionListID
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
506
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
507 if self.__currentEditor is not None:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
508 if self.__currentEditor.isListActive():
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
509 self.__currentEditor.cancelList()
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
510 completions = self.__caObject.getCompletions(self.__currentEditor)
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
511 if len(completions) == 0 and \
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
512 self.getPreferences("ShowQScintillaCompletions"):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
513 # try QScintilla autocompletion
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
514 self.__currentEditor.autoCompleteQScintilla()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
515 else:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
516 completions.sort()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
517 self.__currentEditor.showUserList(EditorAutoCompletionListID,
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
518 completions)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
519
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
520 def __editorAboutToBeSaved(self, filename):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
521 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
522 Private slot to get the old contents of the named file.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
523
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
524 @param filename name of the file about to be saved (string)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
525 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
526 if filename and os.path.exists(filename):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
527 try:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
528 self.__oldEditorText = Utilities.readEncodedFile(filename)[0]
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
529 except IOError:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
530 self.__oldEditorText = ""
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
531 self.__savedEditorName = filename
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
532 else:
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
533 self.__savedEditorName = ""
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
534 self.__oldEditorText = ""
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
535
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
536 def __editorSaved(self, filename):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
537 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
538 Private slot to activate SOA.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
539
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
540 @param filename name of the file that was saved (string)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
541 """
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
542 if filename == self.__savedEditorName and self.__oldEditorText:
106
b2b2107b8047 Little improvement to update the SOA database for refactoring upon saving a file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 104
diff changeset
543 self.__object.reportChanged(self.__savedEditorName,
b2b2107b8047 Little improvement to update the SOA database for refactoring upon saving a file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 104
diff changeset
544 self.__oldEditorText)
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
545 self.__caObject.reportChanged(self.__savedEditorName,
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
546 self.__oldEditorText)
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
547 else:
106
b2b2107b8047 Little improvement to update the SOA database for refactoring upon saving a file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 104
diff changeset
548 self.__object.reportChanged(filename, "")
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
549 self.__caObject.reportChanged(filename, "")
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
550
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
551 def __setCalltipsHook(self, editor):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
552 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
553 Private method to set the calltip hook.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
554
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
555 @param editor reference to the editor (QScintilla.Editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
556 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
557 editor.setCallTipHook(self.codeAssistCallTip)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
558
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
559 def __unsetCalltipsHook(self, editor):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
560 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
561 Private method to unset the calltip hook.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
562
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
563 @param editor reference to the editor (QScintilla.Editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
564 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
565 editor.unsetCallTipHook()
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
566
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
567 def codeAssistCallTip(self, editor, pos, commas):
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
568 """
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
569 Public method to return a list of calltips.
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
570
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
571 @param editor reference to the editor (QScintilla.Editor)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
572 @param pos position in the text for the calltip (integer)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
573 @param commas minimum number of commas contained in the calltip
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
574 (integer)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
575 @return list of possible calltips (list of strings)
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
576 """
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 101
diff changeset
577 cts = self.__caObject.getCallTips(pos, editor)
100
2bfe9e3fad8d Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 99
diff changeset
578 return cts

eric ide

mercurial