21 class VirtualenvManagerDialog(QDialog, Ui_VirtualenvManagerDialog): |
21 class VirtualenvManagerDialog(QDialog, Ui_VirtualenvManagerDialog): |
22 """ |
22 """ |
23 Class implementing a dialog to manage the list of defined virtual |
23 Class implementing a dialog to manage the list of defined virtual |
24 environments. |
24 environments. |
25 """ |
25 """ |
26 IsGlobalRole = Qt.UserRole + 1 |
26 IsGlobalRole = Qt.ItemDataRole.UserRole + 1 |
27 IsCondaRole = Qt.UserRole + 2 |
27 IsCondaRole = Qt.ItemDataRole.UserRole + 2 |
28 IsRemoteRole = Qt.UserRole + 3 |
28 IsRemoteRole = Qt.ItemDataRole.UserRole + 3 |
29 ExecPathRole = Qt.UserRole + 4 |
29 ExecPathRole = Qt.ItemDataRole.UserRole + 4 |
30 |
30 |
31 def __init__(self, manager, parent=None): |
31 def __init__(self, manager, parent=None): |
32 """ |
32 """ |
33 Constructor |
33 Constructor |
34 |
34 |
52 self.envBaseDirectoryPicker.setText(baseDir) |
52 self.envBaseDirectoryPicker.setText(baseDir) |
53 |
53 |
54 self.__populateVenvList() |
54 self.__populateVenvList() |
55 self.__updateButtons() |
55 self.__updateButtons() |
56 |
56 |
57 self.venvList.header().setSortIndicator(0, Qt.AscendingOrder) |
57 self.venvList.header().setSortIndicator(0, Qt.SortOrder.AscendingOrder) |
58 |
58 |
59 def __updateButtons(self): |
59 def __updateButtons(self): |
60 """ |
60 """ |
61 Private method to update the enabled state of the various buttons. |
61 Private method to update the enabled state of the various buttons. |
62 """ |
62 """ |
109 from .VirtualenvAddEditDialog import VirtualenvAddEditDialog |
109 from .VirtualenvAddEditDialog import VirtualenvAddEditDialog |
110 dlg = VirtualenvAddEditDialog( |
110 dlg = VirtualenvAddEditDialog( |
111 self.__manager, |
111 self.__manager, |
112 baseDir=self.envBaseDirectoryPicker.text() |
112 baseDir=self.envBaseDirectoryPicker.text() |
113 ) |
113 ) |
114 if dlg.exec() == QDialog.Accepted: |
114 if dlg.exec() == QDialog.DialogCode.Accepted: |
115 (venvName, venvDirectory, venvInterpreter, isGlobal, isConda, |
115 (venvName, venvDirectory, venvInterpreter, isGlobal, isConda, |
116 isRemote, execPath) = dlg.getData() |
116 isRemote, execPath) = dlg.getData() |
117 |
117 |
118 self.__manager.addVirtualEnv( |
118 self.__manager.addVirtualEnv( |
119 venvName, venvDirectory, venvInterpreter, isGlobal, isConda, |
119 venvName, venvDirectory, venvInterpreter, isGlobal, isConda, |
143 selectedItem.data(0, VirtualenvManagerDialog.IsCondaRole), |
143 selectedItem.data(0, VirtualenvManagerDialog.IsCondaRole), |
144 selectedItem.data(0, VirtualenvManagerDialog.IsRemoteRole), |
144 selectedItem.data(0, VirtualenvManagerDialog.IsRemoteRole), |
145 selectedItem.data(0, VirtualenvManagerDialog.ExecPathRole), |
145 selectedItem.data(0, VirtualenvManagerDialog.ExecPathRole), |
146 baseDir=self.envBaseDirectoryPicker.text() |
146 baseDir=self.envBaseDirectoryPicker.text() |
147 ) |
147 ) |
148 if dlg.exec() == QDialog.Accepted: |
148 if dlg.exec() == QDialog.DialogCode.Accepted: |
149 (venvName, venvDirectory, venvInterpreter, isGlobal, isConda, |
149 (venvName, venvDirectory, venvInterpreter, isGlobal, isConda, |
150 isRemote, execPath) = dlg.getData() |
150 isRemote, execPath) = dlg.getData() |
151 if venvName != oldVenvName: |
151 if venvName != oldVenvName: |
152 self.__manager.renameVirtualEnv( |
152 self.__manager.renameVirtualEnv( |
153 oldVenvName, venvName, venvDirectory, venvInterpreter, |
153 oldVenvName, venvName, venvDirectory, venvInterpreter, |
232 # 3. re-populate the list |
232 # 3. re-populate the list |
233 self.__populateVenvList() |
233 self.__populateVenvList() |
234 |
234 |
235 # 4. re-establish selection |
235 # 4. re-establish selection |
236 for venvName in selectedVenvs: |
236 for venvName in selectedVenvs: |
237 itms = self.venvList.findItems(venvName, Qt.MatchExactly, 0) |
237 itms = self.venvList.findItems( |
|
238 venvName, Qt.MatchFlag.MatchExactly, 0) |
238 if itms: |
239 if itms: |
239 itms[0].setSelected(True) |
240 itms[0].setSelected(True) |
240 |
241 |
241 def __populateVenvList(self): |
242 def __populateVenvList(self): |
242 """ |
243 """ |
287 """ |
288 """ |
288 Private method to resize the sections of the environment list to their |
289 Private method to resize the sections of the environment list to their |
289 contents. |
290 contents. |
290 """ |
291 """ |
291 self.venvList.header().resizeSections( |
292 self.venvList.header().resizeSections( |
292 QHeaderView.ResizeToContents) |
293 QHeaderView.ResizeMode.ResizeToContents) |
293 self.venvList.header().setStretchLastSection(True) |
294 self.venvList.header().setStretchLastSection(True) |
294 |
295 |
295 def closeEvent(self, evt): |
296 def closeEvent(self, evt): |
296 """ |
297 """ |
297 Protected method to handle the close event. |
298 Protected method to handle the close event. |