6 """ |
6 """ |
7 Module implementing the conda packages management widget. |
7 Module implementing the conda packages management widget. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
11 |
13 |
12 from PyQt5.QtCore import pyqtSlot, Qt |
14 from PyQt5.QtCore import pyqtSlot, Qt |
13 from PyQt5.QtGui import QCursor |
15 from PyQt5.QtGui import QCursor |
14 from PyQt5.QtWidgets import QWidget, QToolButton, QMenu, QTreeWidgetItem, \ |
16 from PyQt5.QtWidgets import QWidget, QToolButton, QMenu, QTreeWidgetItem, \ |
15 QApplication |
17 QApplication |
16 |
18 |
17 from E5Gui import E5MessageBox |
19 from E5Gui import E5MessageBox |
|
20 from E5Gui.E5Application import e5App |
18 |
21 |
19 from .Ui_CondaPackagesWidget import Ui_CondaPackagesWidget |
22 from .Ui_CondaPackagesWidget import Ui_CondaPackagesWidget |
20 |
23 |
21 import UI.PixmapCache |
24 import UI.PixmapCache |
22 |
25 |
91 """ |
94 """ |
92 Private method to create the super menu and attach it to the super |
95 Private method to create the super menu and attach it to the super |
93 menu button. |
96 menu button. |
94 """ |
97 """ |
95 self.__condaMenu = QMenu(self) |
98 self.__condaMenu = QMenu(self) |
96 # TODO: implement Conda menu |
99 self.__envActs = [] |
|
100 |
|
101 self.__cleanMenu = QMenu(self.tr("Clean"), self) |
|
102 self.__cleanMenu.addAction( |
|
103 self.tr("All"), lambda: self.__cleanMenuAction("all")) |
|
104 self.__cleanMenu.addAction( |
|
105 self.tr("Cache"), lambda: self.__cleanMenuAction("index-cache")) |
|
106 self.__cleanMenu.addAction( |
|
107 self.tr("Lock Files"), |
|
108 lambda: self.__cleanMenuAction("lock")) |
|
109 self.__cleanMenu.addAction( |
|
110 self.tr("Packages"), lambda: self.__cleanMenuAction("packages")) |
|
111 self.__cleanMenu.addAction( |
|
112 self.tr("Tarballs"), lambda: self.__cleanMenuAction("tarballs")) |
|
113 self.__cleanMenu.addAction( |
|
114 self.tr("Temporary Files"), |
|
115 lambda: self.__cleanMenuAction("temp_files")) |
|
116 |
|
117 self.__condaMenu.addAction( |
|
118 self.tr("About Conda..."), self.__aboutConda) |
|
119 self.__condaMenu.addSeparator() |
97 self.__condaMenu.addAction( |
120 self.__condaMenu.addAction( |
98 self.tr("Update Conda"), self.__conda.updateConda) |
121 self.tr("Update Conda"), self.__conda.updateConda) |
99 self.__condaMenu.addSeparator() |
122 self.__condaMenu.addSeparator() |
|
123 self.__envActs.append(self.__condaMenu.addAction( |
|
124 self.tr("Install Packages"), self.__installPackages)) |
|
125 self.__envActs.append(self.__condaMenu.addAction( |
|
126 self.tr("Install Local Packages"), self.__installLocalPackage)) |
|
127 self.__envActs.append(self.__condaMenu.addAction( |
|
128 self.tr("Install Requirements"), self.__installRequirements)) |
|
129 self.__condaMenu.addSeparator() |
|
130 self.__envActs.append(self.__condaMenu.addAction( |
|
131 self.tr("Generate Requirements"), self.__generateRequirements)) |
|
132 self.__condaMenu.addSeparator() |
|
133 self.__envActs.append(self.__condaMenu.addAction( |
|
134 self.tr("Clone Environment"), self.__cloneEnvironment)) |
|
135 self.__condaMenu.addSeparator() |
|
136 self.__envActs.append(self.__condaMenu.addMenu(self.__cleanMenu)) |
|
137 self.__condaMenu.addSeparator() |
|
138 self.__condaMenu.addAction( |
|
139 self.tr("Edit User Configuration..."), |
|
140 self.__editUserConfiguration) |
|
141 self.__condaMenu.addSeparator() |
|
142 self.__condaMenu.addAction( |
|
143 self.tr("Configure..."), self.__condaConfigure) |
100 |
144 |
101 self.condaMenuButton.setMenu(self.__condaMenu) |
145 self.condaMenuButton.setMenu(self.__condaMenu) |
102 |
146 |
103 self.__condaMenu.aboutToShow.connect(self.__aboutToShowCondaMenu) |
147 self.__condaMenu.aboutToShow.connect(self.__aboutToShowCondaMenu) |
104 |
148 |
152 prefix = self.environmentsComboBox.itemData(index) |
196 prefix = self.environmentsComboBox.itemData(index) |
153 if prefix: |
197 if prefix: |
154 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
198 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
155 QApplication.processEvents() |
199 QApplication.processEvents() |
156 |
200 |
|
201 # 1. populate with installed packages |
157 self.packagesList.setUpdatesEnabled(False) |
202 self.packagesList.setUpdatesEnabled(False) |
158 # 1. populate with installed packages |
|
159 installedPackages = \ |
203 installedPackages = \ |
160 self.__conda.getInstalledPackages(prefix=prefix) |
204 self.__conda.getInstalledPackages(prefix=prefix) |
161 for package, version, build in installedPackages: |
205 for package, version, build in installedPackages: |
162 itm = QTreeWidgetItem(self.packagesList, [package, version]) |
206 itm = QTreeWidgetItem(self.packagesList, [package, version]) |
163 itm.setData(1, self.PackageVersionRole, version) |
207 itm.setData(1, self.PackageVersionRole, version) |
164 itm.setData(1, self.PackageBuildRole, build) |
208 itm.setData(1, self.PackageBuildRole, build) |
|
209 self.packagesList.setUpdatesEnabled(True) |
|
210 QApplication.processEvents() |
165 |
211 |
166 # 2. update with update information |
212 # 2. update with update information |
|
213 self.packagesList.setUpdatesEnabled(False) |
167 updateablePackages = \ |
214 updateablePackages = \ |
168 self.__conda.getUpdateablePackages(prefix=prefix) |
215 self.__conda.getUpdateablePackages(prefix=prefix) |
169 for package, version, build in updateablePackages: |
216 for package, version, build in updateablePackages: |
170 items = self.packagesList.findItems( |
217 items = self.packagesList.findItems( |
171 package, Qt.MatchExactly | Qt.MatchCaseSensitive) |
218 package, Qt.MatchExactly | Qt.MatchCaseSensitive) |
184 itm.data(2, self.PackageVersionRole), |
231 itm.data(2, self.PackageVersionRole), |
185 itm.data(2, self.PackageBuildRole), |
232 itm.data(2, self.PackageBuildRole), |
186 )) |
233 )) |
187 |
234 |
188 self.packagesList.sortItems(0, Qt.AscendingOrder) |
235 self.packagesList.sortItems(0, Qt.AscendingOrder) |
189 self.packagesList.resizeColumnToContents(0) |
236 for col in range(self.packagesList.columnCount()): |
|
237 self.packagesList.resizeColumnToContents(col) |
190 self.packagesList.setUpdatesEnabled(True) |
238 self.packagesList.setUpdatesEnabled(True) |
191 QApplication.restoreOverrideCursor() |
239 QApplication.restoreOverrideCursor() |
192 |
240 |
193 self.__updateActionButtons() |
241 self.__updateActionButtons() |
194 self.__updateSearchActionButtons() |
242 self.__updateSearchActionButtons() |
446 self.searchEdit.setFocus(Qt.OtherFocusReason) |
494 self.searchEdit.setFocus(Qt.OtherFocusReason) |
447 self.searchEdit.selectAll() |
495 self.searchEdit.selectAll() |
448 |
496 |
449 self.__updateSearchActionButtons() |
497 self.__updateSearchActionButtons() |
450 |
498 |
|
499 ####################################################################### |
|
500 ## Menu related methods below |
|
501 ####################################################################### |
|
502 |
451 @pyqtSlot() |
503 @pyqtSlot() |
452 def __aboutToShowCondaMenu(self): |
504 def __aboutToShowCondaMenu(self): |
453 """ |
505 """ |
454 Private slot to handle the conda menu about to be shown. |
506 Private slot to handle the conda menu about to be shown. |
455 """ |
507 """ |
456 selectedEnvironment = self.environmentsComboBox.currentText() |
508 selectedEnvironment = self.environmentsComboBox.currentText() |
|
509 enable = selectedEnvironment not in [""] |
|
510 for act in self.__envActs: |
|
511 act.setEnabled(enable) |
|
512 |
|
513 @pyqtSlot() |
|
514 def __aboutConda(self): |
|
515 """ |
|
516 Private slot to |
|
517 """ |
|
518 # TODO: implement this menu function |
|
519 # conda info --all |
|
520 infoDict = self.__conda.getCondaInformation() |
|
521 |
|
522 from .CondaInfoDialog import CondaInfoDialog |
|
523 dlg = CondaInfoDialog(infoDict, self) |
|
524 dlg.exec_() |
|
525 |
|
526 @pyqtSlot() |
|
527 def __installPackages(self): |
|
528 """ |
|
529 Private slot to |
|
530 """ |
|
531 # TODO: implement this menu function |
|
532 # conda install ... |
|
533 |
|
534 @pyqtSlot() |
|
535 def __installLocalPackage(self): |
|
536 """ |
|
537 Private slot to |
|
538 """ |
|
539 # TODO: implement this menu function |
|
540 # conda install --use-local |
|
541 |
|
542 @pyqtSlot() |
|
543 def __installRequirements(self): |
|
544 """ |
|
545 Private slot to |
|
546 """ |
|
547 # TODO: implement this menu function |
|
548 # conda install --file FILE1 --file FILE2 ... |
|
549 |
|
550 @pyqtSlot() |
|
551 def __generateRequirements(self): |
|
552 """ |
|
553 Private slot to |
|
554 """ |
|
555 # TODO: implement this menu function |
|
556 # conda list --export |
|
557 |
|
558 @pyqtSlot() |
|
559 def __cloneEnvironment(self): |
|
560 """ |
|
561 Private slot to |
|
562 """ |
|
563 # TODO: implement this menu function |
|
564 # conda create --clone ENV |
|
565 |
|
566 def __cleanMenuAction(self, cleanAction): |
|
567 """ |
|
568 Private method to |
|
569 """ |
|
570 # TODO: implement this menu function |
|
571 # conda clean |
|
572 # --all (act = 'all') |
|
573 # --index-cache (act = 'index-cache') |
|
574 # --lock (act = 'lock') |
|
575 # --packages (act = 'packages') |
|
576 # --tarballs (act = 'tarballs') |
|
577 # -c prefix1 prefix2 ... (act = 'temp_files') |
|
578 |
|
579 @pyqtSlot() |
|
580 def __editUserConfiguration(self): |
|
581 """ |
|
582 Private slot to edit the user configuration. |
|
583 """ |
|
584 from QScintilla.MiniEditor import MiniEditor |
|
585 |
|
586 cfgFile = CondaInterface.userConfiguration() |
|
587 if not cfgFile: |
|
588 return |
|
589 |
|
590 if not os.path.exists(cfgFile): |
|
591 self.__conda.writeDefaultConfiguration() |
|
592 |
|
593 # check, if the destination is writeable |
|
594 if not os.access(cfgFile, os.W_OK): |
|
595 E5MessageBox.critical( |
|
596 None, |
|
597 self.tr("Edit Configuration"), |
|
598 self.tr("""The configuration file "{0}" does not exist""" |
|
599 """ or is not writable.""")) |
|
600 return |
|
601 |
|
602 self.__editor = MiniEditor(cfgFile, "YAML") |
|
603 self.__editor.show() |
|
604 |
|
605 @pyqtSlot() |
|
606 def __condaConfigure(self): |
|
607 """ |
|
608 Private slot to open the configuration page. |
|
609 """ |
|
610 e5App().getObject("UserInterface").showPreferences("condaPage") |