19 QVBoxLayout, |
20 QVBoxLayout, |
20 QWidget, |
21 QWidget, |
21 ) |
22 ) |
22 |
23 |
23 from eric7.EricGui import EricPixmapCache |
24 from eric7.EricGui import EricPixmapCache |
|
25 from eric7.EricWidgets import EricMessageBox |
24 from eric7.EricWidgets.EricMainWindow import EricMainWindow |
26 from eric7.EricWidgets.EricMainWindow import EricMainWindow |
25 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
27 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes |
|
28 from eric7.EricWidgets.EricListSelectionDialog import EricListSelectionDialog |
26 from eric7.SystemUtilities import OSUtilities |
29 from eric7.SystemUtilities import OSUtilities |
27 |
30 |
28 from .Ui_VirtualenvManagerWidget import Ui_VirtualenvManagerWidget |
31 from .Ui_VirtualenvManagerWidget import Ui_VirtualenvManagerWidget |
|
32 from .VirtualenvMeta import VirtualenvMetaData |
29 |
33 |
30 |
34 |
31 class VirtualenvManagerWidget(QWidget, Ui_VirtualenvManagerWidget): |
35 class VirtualenvManagerWidget(QWidget, Ui_VirtualenvManagerWidget): |
32 """ |
36 """ |
33 Class implementing a widget to manage the list of defined virtual |
37 Class implementing a widget to manage the list of defined virtual |
53 self.__manager = manager |
57 self.__manager = manager |
54 |
58 |
55 self.refreshButton.setIcon(EricPixmapCache.getIcon("reload")) |
59 self.refreshButton.setIcon(EricPixmapCache.getIcon("reload")) |
56 self.addButton.setIcon(EricPixmapCache.getIcon("plus")) |
60 self.addButton.setIcon(EricPixmapCache.getIcon("plus")) |
57 self.newButton.setIcon(EricPixmapCache.getIcon("new")) |
61 self.newButton.setIcon(EricPixmapCache.getIcon("new")) |
|
62 self.searchNewButton.setIcon(EricPixmapCache.getIcon("question")) |
58 self.editButton.setIcon(EricPixmapCache.getIcon("edit")) |
63 self.editButton.setIcon(EricPixmapCache.getIcon("edit")) |
59 self.upgradeButton.setIcon(EricPixmapCache.getIcon("upgrade")) |
64 self.upgradeButton.setIcon(EricPixmapCache.getIcon("upgrade")) |
60 self.removeButton.setIcon(EricPixmapCache.getIcon("minus")) |
65 self.removeButton.setIcon(EricPixmapCache.getIcon("minus")) |
61 self.removeAllButton.setIcon(EricPixmapCache.getIcon("minus_3")) |
66 self.removeAllButton.setIcon(EricPixmapCache.getIcon("minus_3")) |
62 self.deleteButton.setIcon(EricPixmapCache.getIcon("fileDelete")) |
67 self.deleteButton.setIcon(EricPixmapCache.getIcon("fileDelete")) |
157 def on_newButton_clicked(self): |
162 def on_newButton_clicked(self): |
158 """ |
163 """ |
159 Private slot to create a new virtual environment. |
164 Private slot to create a new virtual environment. |
160 """ |
165 """ |
161 self.__manager.createVirtualEnv(baseDir=self.envBaseDirectoryPicker.text()) |
166 self.__manager.createVirtualEnv(baseDir=self.envBaseDirectoryPicker.text()) |
|
167 |
|
168 @pyqtSlot() |
|
169 def on_searchNewButton_clicked(self): |
|
170 """ |
|
171 Public slot to search for new (not yet registered) Python interpreters. |
|
172 """ |
|
173 potentialInterpreters = self.__manager.searchUnregisteredInterpreters() |
|
174 |
|
175 if not bool(potentialInterpreters): |
|
176 EricMessageBox.information( |
|
177 self, |
|
178 self.tr("Search Virtual Environments"), |
|
179 self.tr("""No unregistered virtual environments were found."""), |
|
180 ) |
|
181 return |
|
182 |
|
183 baseDir = self.__manager.getVirtualEnvironmentsBaseDir() |
|
184 if not baseDir: |
|
185 baseDir = OSUtilities.getHomeDir() |
|
186 |
|
187 selectionList = [] |
|
188 for interpreter in potentialInterpreters: |
|
189 if not interpreter.startswith(baseDir): |
|
190 realpath = os.path.realpath(interpreter) |
|
191 if realpath != interpreter: |
|
192 # interpreter is a link |
|
193 selectionList.append( |
|
194 ( |
|
195 self.tr("{0}\n(=> {1})").format(interpreter, realpath), |
|
196 interpreter, |
|
197 ) |
|
198 ) |
|
199 continue |
|
200 |
|
201 selectionList.append((interpreter, interpreter)) |
|
202 |
|
203 dlg = EricListSelectionDialog( |
|
204 sorted(selectionList), |
|
205 title=self.tr("Search Virtual Environments"), |
|
206 message=self.tr( |
|
207 "Select the interpreters to create environment entries for:" |
|
208 ), |
|
209 checkBoxSelection=True, |
|
210 emptySelectionOk=True, |
|
211 showSelectAll=True, |
|
212 ) |
|
213 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
214 selectedInterpreters = [env[1] for env in dlg.getSelection()] |
|
215 |
|
216 nameTemplate = ( |
|
217 "Environment #{0} added " |
|
218 + datetime.datetime.now().strftime("%Y-%m-%d %H:%M") |
|
219 ) |
|
220 for interpreter in selectedInterpreters: |
|
221 metadata = VirtualenvMetaData( |
|
222 name=nameTemplate.format( |
|
223 selectedInterpreters.index(interpreter) + 1 |
|
224 ), |
|
225 path=( |
|
226 os.path.abspath(os.path.join(interpreter, "..", "..")) |
|
227 if interpreter.startswith(baseDir) |
|
228 else "" |
|
229 ), |
|
230 interpreter=interpreter, |
|
231 is_global=not interpreter.startswith(baseDir), |
|
232 ) |
|
233 self.__manager.addVirtualEnv(metadata) |
162 |
234 |
163 @pyqtSlot() |
235 @pyqtSlot() |
164 def on_editButton_clicked(self): |
236 def on_editButton_clicked(self): |
165 """ |
237 """ |
166 Private slot to edit the selected entry. |
238 Private slot to edit the selected entry. |