1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2015 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the pip interface plug-in. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 |
|
13 from PyQt5.QtCore import pyqtSignal, QObject, QCoreApplication |
|
14 |
|
15 from E5Gui.E5Application import e5App |
|
16 |
|
17 import Preferences |
|
18 import UI.Info |
|
19 |
|
20 # Start-Of-Header |
|
21 name = "pip Interface Plug-in" |
|
22 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
|
23 autoactivate = True |
|
24 deactivateable = True |
|
25 version = UI.Info.VersionOnly |
|
26 className = "PipInterfacePlugin" |
|
27 packageName = "__core__" |
|
28 shortDescription = "Plug-in implementing a simple GUI for the pip command." |
|
29 longDescription = ( |
|
30 """Plug-in implementing a simple GUI for the pip command.""" |
|
31 ) |
|
32 needsRestart = False |
|
33 pyqtApi = 2 |
|
34 python2Compatible = True |
|
35 # End-Of-Header |
|
36 |
|
37 error = "" |
|
38 |
|
39 pipPluginObject = None |
|
40 |
|
41 |
|
42 def exeDisplayDataList(): |
|
43 """ |
|
44 Module function to support the display of some executable info. |
|
45 |
|
46 @return list of dictionaries containing the data to query the presence of |
|
47 the executable |
|
48 """ |
|
49 global pipPluginObject |
|
50 |
|
51 dataList = [] |
|
52 data = { |
|
53 "programEntry": True, |
|
54 "header": QCoreApplication.translate( |
|
55 "PipInterfacePlugin", "Package Management - pip"), |
|
56 "exe": "dummyExe", |
|
57 "versionCommand": "--version", |
|
58 "versionStartsWith": "pip", |
|
59 "versionPosition": 1, |
|
60 "version": "", |
|
61 "versionCleanup": None, |
|
62 "exeModule": ["-m", "pip"], |
|
63 } |
|
64 virtualenvManager = e5App().getObject("VirtualEnvManager") |
|
65 for venvName in virtualenvManager.getVirtualenvNames(): |
|
66 interpreter = virtualenvManager.getVirtualenvInterpreter(venvName) |
|
67 data["exe"] = interpreter |
|
68 dataList.append(data.copy()) |
|
69 return dataList |
|
70 |
|
71 |
|
72 def createPipPage(configDlg): |
|
73 """ |
|
74 Module function to create the pip configuration page. |
|
75 |
|
76 @param configDlg reference to the configuration dialog |
|
77 @return reference to the configuration page |
|
78 """ |
|
79 global pipPluginObject |
|
80 from UiExtensionPlugins.PipInterface.ConfigurationPage.PipPage import \ |
|
81 PipPage |
|
82 page = PipPage(pipPluginObject) |
|
83 return page |
|
84 |
|
85 |
|
86 def getConfigData(): |
|
87 """ |
|
88 Module function returning data as required by the configuration dialog. |
|
89 |
|
90 @return dictionary containing the relevant data |
|
91 """ |
|
92 return { |
|
93 "pipPage": [ |
|
94 QCoreApplication.translate( |
|
95 "PipInterfacePlugin", "Python Package Management"), |
|
96 "preferences-python.png", |
|
97 createPipPage, None, None |
|
98 ], |
|
99 } |
|
100 |
|
101 |
|
102 def prepareUninstall(): |
|
103 """ |
|
104 Module function to prepare for an un-installation. |
|
105 """ |
|
106 Preferences.Prefs.settings.remove(PipInterfacePlugin.PreferencesKey) |
|
107 |
|
108 |
|
109 class PipInterfacePlugin(QObject): |
|
110 """ |
|
111 Class implementing the pip interface plug-in. |
|
112 |
|
113 @signal currentEnvironmentChanged(str) emitted to signal a change of the |
|
114 currently selected virtual environment |
|
115 """ |
|
116 PreferencesKey = "PipPlugin" |
|
117 |
|
118 currentEnvironmentChanged = pyqtSignal(str) |
|
119 |
|
120 def __init__(self, ui): |
|
121 """ |
|
122 Constructor |
|
123 |
|
124 @param ui reference to the user interface object (UI.UserInterface) |
|
125 """ |
|
126 super(PipInterfacePlugin, self).__init__(ui) |
|
127 self.__ui = ui |
|
128 self.__initialize() |
|
129 |
|
130 self.__defaults = { |
|
131 "CurrentEnvironment": "", |
|
132 "PipSearchIndex": "", # used by the search command |
|
133 } |
|
134 |
|
135 def __initialize(self): |
|
136 """ |
|
137 Private slot to (re)initialize the plugin. |
|
138 """ |
|
139 self.__object = None |
|
140 |
|
141 self.__mainAct = None |
|
142 self.__mainMenu = None |
|
143 |
|
144 def activate(self): |
|
145 """ |
|
146 Public method to activate this plugin. |
|
147 |
|
148 @return tuple of None and activation status |
|
149 @rtype tuple of (None, bool) |
|
150 """ |
|
151 global error |
|
152 error = "" # clear previous error |
|
153 |
|
154 global pipPluginObject |
|
155 pipPluginObject = self |
|
156 |
|
157 from UiExtensionPlugins.PipInterface.Pip import Pip |
|
158 self.__object = Pip(self, self.__ui) |
|
159 self.__object.initActions() |
|
160 e5App().registerPluginObject("PipGui", self.__object) |
|
161 |
|
162 menu = self.__ui.getMenu("extras") |
|
163 self.__mainMenu = self.__object.initMenu() |
|
164 self.__mainAct = menu.addMenu(self.__mainMenu) |
|
165 |
|
166 return None, True |
|
167 |
|
168 def deactivate(self): |
|
169 """ |
|
170 Public method to deactivate this plugin. |
|
171 """ |
|
172 e5App().unregisterPluginObject("PipGui") |
|
173 |
|
174 menu = self.__ui.getMenu("extras") |
|
175 menu.removeAction(self.__mainAct) |
|
176 self.__mainAct = None |
|
177 |
|
178 self.__initialize() |
|
179 |
|
180 def getPreferences(self, key): |
|
181 """ |
|
182 Public method to retrieve the various pip related settings. |
|
183 |
|
184 @param key the key of the value to get |
|
185 @type str |
|
186 @return the requested setting |
|
187 @rtype any |
|
188 """ |
|
189 return Preferences.Prefs.settings.value( |
|
190 self.PreferencesKey + "/" + key, self.__defaults[key]) |
|
191 |
|
192 def setPreferences(self, key, value): |
|
193 """ |
|
194 Public method to store the various pip related settings. |
|
195 |
|
196 @param key the key of the setting to be set |
|
197 @type str |
|
198 @param value the value to be set |
|
199 @type any |
|
200 """ |
|
201 Preferences.Prefs.settings.setValue( |
|
202 self.PreferencesKey + "/" + key, value) |
|
203 |
|
204 if key == "CurrentEnvironment": |
|
205 self.currentEnvironmentChanged.emit(value) |
|
206 |
|
207 def getMenu(self, name): |
|
208 """ |
|
209 Public method to get a reference to the requested menu. |
|
210 |
|
211 @param name name of the menu |
|
212 @type str |
|
213 @return reference to the menu or None, if no |
|
214 menu with the given name exists |
|
215 @rtype QMenu or None |
|
216 """ |
|
217 if self.__object is not None: |
|
218 return self.__object.getMenu(name) |
|
219 else: |
|
220 return None |
|
221 |
|
222 def getMenuNames(self): |
|
223 """ |
|
224 Public method to get the names of all menus. |
|
225 |
|
226 @return menu names |
|
227 @rtype list of str |
|
228 """ |
|
229 if self.__object is not None: |
|
230 return list(self.__menus.keys()) |
|
231 else: |
|
232 return [] |
|
233 |
|
234 # |
|
235 # eflag: noqa = M801 |
|