32 """ |
32 """ |
33 Class implementing a widget to manage the list of defined virtual |
33 Class implementing a widget to manage the list of defined virtual |
34 environments. |
34 environments. |
35 """ |
35 """ |
36 |
36 |
37 IsGlobalRole = Qt.ItemDataRole.UserRole + 1 |
37 MetadataRole = Qt.ItemDataRole.UserRole + 1 |
38 IsCondaRole = Qt.ItemDataRole.UserRole + 2 |
|
39 IsRemoteRole = Qt.ItemDataRole.UserRole + 3 |
|
40 ExecPathRole = Qt.ItemDataRole.UserRole + 4 |
|
41 DescriptionRole = Qt.ItemDataRole.UserRole + 5 |
|
42 |
38 |
43 def __init__(self, manager, parent=None): |
39 def __init__(self, manager, parent=None): |
44 """ |
40 """ |
45 Constructor |
41 Constructor |
46 |
42 |
92 deletableSelectedItemCount = 0 |
88 deletableSelectedItemCount = 0 |
93 for itm in self.venvList.selectedItems(): |
89 for itm in self.venvList.selectedItems(): |
94 if ( |
90 if ( |
95 itm.text(0) != "<default>" |
91 itm.text(0) != "<default>" |
96 and bool(itm.text(1)) |
92 and bool(itm.text(1)) |
97 and not itm.data(0, VirtualenvManagerWidget.IsGlobalRole) |
93 and not itm.data(0, VirtualenvManagerWidget.MetadataRole).is_global |
98 and not itm.data(0, VirtualenvManagerWidget.IsRemoteRole) |
94 and not itm.data(0, VirtualenvManagerWidget.MetadataRole).is_remote |
99 ): |
95 ): |
100 deletableSelectedItemCount += 1 |
96 deletableSelectedItemCount += 1 |
101 |
97 |
102 deletableItemCount = 0 |
98 deletableItemCount = 0 |
103 for index in range(topLevelItemCount): |
99 for index in range(topLevelItemCount): |
104 itm = self.venvList.topLevelItem(index) |
100 itm = self.venvList.topLevelItem(index) |
105 if ( |
101 if ( |
106 itm.text(0) != "<default>" |
102 itm.text(0) != "<default>" |
107 and bool(itm.text(1)) |
103 and bool(itm.text(1)) |
108 and not itm.data(0, VirtualenvManagerWidget.IsRemoteRole) |
104 and not itm.data(0, VirtualenvManagerWidget.MetadataRole).is_remote |
109 ): |
105 ): |
110 deletableItemCount += 1 |
106 deletableItemCount += 1 |
111 |
107 |
112 canBeRemoved = ( |
108 canBeRemoved = ( |
113 selectedItemsCount == 1 |
109 selectedItemsCount == 1 |
149 Private slot to add a new entry. |
145 Private slot to add a new entry. |
150 """ |
146 """ |
151 from .VirtualenvAddEditDialog import VirtualenvAddEditDialog |
147 from .VirtualenvAddEditDialog import VirtualenvAddEditDialog |
152 |
148 |
153 dlg = VirtualenvAddEditDialog( |
149 dlg = VirtualenvAddEditDialog( |
154 self.__manager, baseDir=self.envBaseDirectoryPicker.text() |
150 self.__manager, baseDir=self.envBaseDirectoryPicker.text(), parent=self |
155 ) |
151 ) |
156 if dlg.exec() == QDialog.DialogCode.Accepted: |
152 if dlg.exec() == QDialog.DialogCode.Accepted: |
157 ( |
153 metadata = dlg.getMetaData() |
158 venvName, |
154 self.__manager.addVirtualEnv(metadata) |
159 venvDirectory, |
|
160 venvInterpreter, |
|
161 isGlobal, |
|
162 isConda, |
|
163 isRemote, |
|
164 execPath, |
|
165 description, |
|
166 ) = dlg.getData() |
|
167 |
|
168 self.__manager.addVirtualEnv( |
|
169 venvName, |
|
170 venvDirectory, |
|
171 venvInterpreter, |
|
172 isGlobal, |
|
173 isConda, |
|
174 isRemote, |
|
175 execPath, |
|
176 description, |
|
177 ) |
|
178 |
155 |
179 @pyqtSlot() |
156 @pyqtSlot() |
180 def on_newButton_clicked(self): |
157 def on_newButton_clicked(self): |
181 """ |
158 """ |
182 Private slot to create a new virtual environment. |
159 Private slot to create a new virtual environment. |
193 selectedItem = self.venvList.selectedItems()[0] |
170 selectedItem = self.venvList.selectedItems()[0] |
194 oldVenvName = selectedItem.text(0) |
171 oldVenvName = selectedItem.text(0) |
195 |
172 |
196 dlg = VirtualenvAddEditDialog( |
173 dlg = VirtualenvAddEditDialog( |
197 self.__manager, |
174 self.__manager, |
198 selectedItem.text(0), |
175 selectedItem.data(0, VirtualenvManagerWidget.MetadataRole), |
199 selectedItem.text(1), |
|
200 selectedItem.text(2), |
|
201 selectedItem.data(0, VirtualenvManagerWidget.IsGlobalRole), |
|
202 selectedItem.data(0, VirtualenvManagerWidget.IsCondaRole), |
|
203 selectedItem.data(0, VirtualenvManagerWidget.IsRemoteRole), |
|
204 selectedItem.data(0, VirtualenvManagerWidget.ExecPathRole), |
|
205 selectedItem.data(0, VirtualenvManagerWidget.DescriptionRole), |
|
206 baseDir=self.envBaseDirectoryPicker.text(), |
176 baseDir=self.envBaseDirectoryPicker.text(), |
|
177 parent=self, |
207 ) |
178 ) |
208 if dlg.exec() == QDialog.DialogCode.Accepted: |
179 if dlg.exec() == QDialog.DialogCode.Accepted: |
209 ( |
180 metadata = dlg.getMetaData() |
210 venvName, |
181 if metadata.name != oldVenvName: |
211 venvDirectory, |
182 self.__manager.renameVirtualEnv(oldVenvName, metadata) |
212 venvInterpreter, |
|
213 isGlobal, |
|
214 isConda, |
|
215 isRemote, |
|
216 execPath, |
|
217 description, |
|
218 ) = dlg.getData() |
|
219 if venvName != oldVenvName: |
|
220 self.__manager.renameVirtualEnv( |
|
221 oldVenvName, |
|
222 venvName, |
|
223 venvDirectory, |
|
224 venvInterpreter, |
|
225 isGlobal, |
|
226 isConda, |
|
227 isRemote, |
|
228 execPath, |
|
229 description, |
|
230 ) |
|
231 else: |
183 else: |
232 self.__manager.setVirtualEnv( |
184 self.__manager.setVirtualEnv(metadata) |
233 venvName, |
|
234 venvDirectory, |
|
235 venvInterpreter, |
|
236 isGlobal, |
|
237 isConda, |
|
238 isRemote, |
|
239 execPath, |
|
240 description, |
|
241 ) |
|
242 |
185 |
243 @pyqtSlot() |
186 @pyqtSlot() |
244 def on_upgradeButton_clicked(self): |
187 def on_upgradeButton_clicked(self): |
245 """ |
188 """ |
246 Private slot to upgrade a virtual environment. |
189 Private slot to upgrade a virtual environment. |
307 self.__updateButtons() |
250 self.__updateButtons() |
308 |
251 |
309 selectedItems = self.venvList.selectedItems() |
252 selectedItems = self.venvList.selectedItems() |
310 if len(selectedItems) == 1: |
253 if len(selectedItems) == 1: |
311 self.descriptionEdit.setPlainText( |
254 self.descriptionEdit.setPlainText( |
312 selectedItems[0].data(0, VirtualenvManagerWidget.DescriptionRole) |
255 selectedItems[0] |
|
256 .data(0, VirtualenvManagerWidget.MetadataRole) |
|
257 .description |
313 ) |
258 ) |
314 else: |
259 else: |
315 self.descriptionEdit.clear() |
260 self.descriptionEdit.clear() |
316 |
261 |
317 @pyqtSlot() |
262 @pyqtSlot() |
338 |
283 |
339 def __populateVenvList(self): |
284 def __populateVenvList(self): |
340 """ |
285 """ |
341 Private method to populate the list of virtual environments. |
286 Private method to populate the list of virtual environments. |
342 """ |
287 """ |
343 environments = self.__manager.getEnvironmentEntries() |
288 for environment in self.__manager.getEnvironmentEntries(): |
344 for venvName in environments: |
|
345 itm = QTreeWidgetItem( |
289 itm = QTreeWidgetItem( |
346 self.venvList, |
290 self.venvList, |
347 [ |
291 [ |
348 venvName, |
292 environment.name, |
349 environments[venvName]["path"], |
293 environment.path, |
350 environments[venvName]["interpreter"], |
294 environment.interpreter, |
351 ], |
295 ], |
352 ) |
296 ) |
353 itm.setData( |
297 itm.setData(0, VirtualenvManagerWidget.MetadataRole, environment) |
354 0, |
|
355 VirtualenvManagerWidget.IsGlobalRole, |
|
356 environments[venvName]["is_global"], |
|
357 ) |
|
358 itm.setData( |
|
359 0, |
|
360 VirtualenvManagerWidget.IsCondaRole, |
|
361 environments[venvName]["is_conda"], |
|
362 ) |
|
363 itm.setData( |
|
364 0, |
|
365 VirtualenvManagerWidget.IsRemoteRole, |
|
366 environments[venvName]["is_remote"], |
|
367 ) |
|
368 itm.setData( |
|
369 0, |
|
370 VirtualenvManagerWidget.ExecPathRole, |
|
371 environments[venvName]["exec_path"], |
|
372 ) |
|
373 itm.setData( |
|
374 0, |
|
375 VirtualenvManagerWidget.DescriptionRole, |
|
376 environments[venvName]["description"], |
|
377 ) |
|
378 |
298 |
379 # show remote environments with underlined font |
299 # show remote environments with underlined font |
380 if environments[venvName]["is_remote"]: |
300 if environment.is_remote: |
381 font = itm.font(0) |
301 font = itm.font(0) |
382 font.setUnderline(True) |
302 font.setUnderline(True) |
383 for column in range(itm.columnCount()): |
303 for column in range(itm.columnCount()): |
384 itm.setFont(column, font) |
304 itm.setFont(column, font) |
385 else: |
305 else: |
386 # local environments |
306 # local environments |
387 |
307 |
388 # show global environments with bold font |
308 # show global environments with bold font |
389 if environments[venvName]["is_global"]: |
309 if environment.is_global: |
390 font = itm.font(0) |
310 font = itm.font(0) |
391 font.setBold(True) |
311 font.setBold(True) |
392 for column in range(itm.columnCount()): |
312 for column in range(itm.columnCount()): |
393 itm.setFont(column, font) |
313 itm.setFont(column, font) |
394 |
314 |
395 # show Anaconda environments with italic font |
315 # show Anaconda environments with italic font |
396 if environments[venvName]["is_conda"]: |
316 if environment.is_conda: |
397 font = itm.font(0) |
317 font = itm.font(0) |
398 font.setItalic(True) |
318 font.setItalic(True) |
399 for column in range(itm.columnCount()): |
319 for column in range(itm.columnCount()): |
400 itm.setFont(column, font) |
320 itm.setFont(column, font) |
401 |
321 |