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 |
11 |
12 import os |
|
13 |
|
14 from PyQt5.QtCore import pyqtSlot, Qt |
12 from PyQt5.QtCore import pyqtSlot, Qt |
15 from PyQt5.QtWidgets import QWidget, QToolButton, QMenu |
13 from PyQt5.QtGui import QCursor |
|
14 from PyQt5.QtWidgets import QWidget, QToolButton, QMenu, QTreeWidgetItem, \ |
|
15 QApplication |
16 |
16 |
17 from .Ui_CondaPackagesWidget import Ui_CondaPackagesWidget |
17 from .Ui_CondaPackagesWidget import Ui_CondaPackagesWidget |
18 |
18 |
19 import UI.PixmapCache |
19 import UI.PixmapCache |
20 |
20 |
21 |
21 |
22 class CondaPackagesWidget(QWidget, Ui_CondaPackagesWidget): |
22 class CondaPackagesWidget(QWidget, Ui_CondaPackagesWidget): |
23 """ |
23 """ |
24 Class implementing the conda packages management widget. |
24 Class implementing the conda packages management widget. |
25 """ |
25 """ |
26 def __init__(self, parent=None): |
26 def __init__(self, conda, parent=None): |
27 """ |
27 """ |
28 Constructor |
28 Constructor |
29 |
29 |
|
30 @param conda reference to the conda interface |
|
31 @type Conda |
30 @param parent reference to the parent widget |
32 @param parent reference to the parent widget |
31 @type QWidget |
33 @type QWidget |
32 """ |
34 """ |
33 super(CondaPackagesWidget, self).__init__(parent) |
35 super(CondaPackagesWidget, self).__init__(parent) |
34 self.setupUi(self) |
36 self.setupUi(self) |
|
37 |
|
38 self.__conda = conda |
35 |
39 |
36 self.condaMenuButton.setObjectName( |
40 self.condaMenuButton.setObjectName( |
37 "navigation_supermenu_button") |
41 "navigation_supermenu_button") |
38 self.condaMenuButton.setIcon(UI.PixmapCache.getIcon("superMenu.png")) |
42 self.condaMenuButton.setIcon(UI.PixmapCache.getIcon("superMenu.png")) |
39 self.condaMenuButton.setToolTip(self.tr("Conda Menu")) |
43 self.condaMenuButton.setToolTip(self.tr("Conda Menu")) |
43 self.condaMenuButton.setAutoRaise(True) |
47 self.condaMenuButton.setAutoRaise(True) |
44 self.condaMenuButton.setShowMenuInside(True) |
48 self.condaMenuButton.setShowMenuInside(True) |
45 |
49 |
46 self.__initCondaMenu() |
50 self.__initCondaMenu() |
47 self.__populateEnvironments() |
51 self.__populateEnvironments() |
|
52 self.__updateActionButtons() |
48 |
53 |
49 def __populateEnvironments(self): |
54 def __populateEnvironments(self): |
50 """ |
55 """ |
51 Private method to get a list of environments and populate the selector. |
56 Private method to get a list of environments and populate the selector. |
52 """ |
57 """ |
53 # TODO: replace this by the real stuff |
58 # TODO: populate with name and prefix |
54 envs = [ |
59 environmentNames = [""] + self.__conda.getCondaEnvironmentsList() |
55 "path/to/envs/sqlite", |
|
56 "path/to/envs/pyqt4", |
|
57 "path/to/envs/pyqt5", |
|
58 ] |
|
59 |
|
60 environmentNames = [os.path.basename(e) for e in envs] |
|
61 self.environmentsComboBox.addItems(sorted(environmentNames)) |
60 self.environmentsComboBox.addItems(sorted(environmentNames)) |
62 |
61 |
63 def __initCondaMenu(self): |
62 def __initCondaMenu(self): |
64 """ |
63 """ |
65 Private method to create the super menu and attach it to the super |
64 Private method to create the super menu and attach it to the super |
69 # TODO: implement Conda menu |
68 # TODO: implement Conda menu |
70 self.__condaMenu.addAction(self.tr("Test Entry"), self.on_refreshButton_clicked) |
69 self.__condaMenu.addAction(self.tr("Test Entry"), self.on_refreshButton_clicked) |
71 |
70 |
72 self.condaMenuButton.setMenu(self.__condaMenu) |
71 self.condaMenuButton.setMenu(self.__condaMenu) |
73 |
72 |
|
73 def __selectedUpdateableItems(self): |
|
74 """ |
|
75 Private method to get a list of selected items that can be updated. |
|
76 |
|
77 @return list of selected items that can be updated |
|
78 @rtype list of QTreeWidgetItem |
|
79 """ |
|
80 return [ |
|
81 itm for itm in self.packagesList.selectedItems() |
|
82 if bool(itm.text(2)) |
|
83 ] |
|
84 |
|
85 def __allUpdateableItems(self): |
|
86 """ |
|
87 Private method to get a list of all items that can be updated. |
|
88 |
|
89 @return list of all items that can be updated |
|
90 @rtype list of QTreeWidgetItem |
|
91 """ |
|
92 updateableItems = [] |
|
93 for index in range(self.packagesList.topLevelItemCount()): |
|
94 itm = self.packagesList.topLevelItem(index) |
|
95 if itm.text(2): |
|
96 updateableItems.append(itm) |
|
97 |
|
98 return updateableItems |
|
99 |
|
100 def __updateActionButtons(self): |
|
101 """ |
|
102 Private method to set the state of the action buttons. |
|
103 """ |
|
104 self.upgradeButton.setEnabled( |
|
105 bool(self.__selectedUpdateableItems())) |
|
106 self.uninstallButton.setEnabled( |
|
107 bool(self.packagesList.selectedItems())) |
|
108 self.upgradeAllButton.setEnabled( |
|
109 bool(self.__allUpdateableItems())) |
|
110 |
|
111 # TODO: change to int = index |
74 @pyqtSlot(str) |
112 @pyqtSlot(str) |
75 def on_environmentsComboBox_activated(self, p0): |
113 def on_environmentsComboBox_currentIndexChanged(self, name): |
76 """ |
114 """ |
77 Slot documentation goes here. |
115 Private slot handling the selection of a conda environment. |
78 |
116 |
79 @param p0 DESCRIPTION |
117 @param name name of the selected conda environment name |
80 @type str |
118 @type str |
81 """ |
119 """ |
82 # TODO: not implemented yet |
120 self.packagesList.clear() |
83 raise NotImplementedError |
121 if name: |
|
122 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
|
123 QApplication.processEvents() |
|
124 |
|
125 # 1. populate with installed packages |
|
126 # TODO: use prefix |
|
127 installedPackages = self.__conda.getInstalledPackages(name=name) |
|
128 for package, version, build_ in installedPackages: |
|
129 QTreeWidgetItem(self.packagesList, [package, version]) |
|
130 |
|
131 # 2. update with update information |
|
132 updateablePackages = self.__conda.getUpdateablePackages(name=name) |
|
133 for package, version, build_ in updateablePackages: |
|
134 items = self.packagesList.findItems( |
|
135 package, Qt.MatchExactly | Qt.MatchCaseSensitive) |
|
136 if items: |
|
137 items[0].setText(2, version) |
|
138 |
|
139 QApplication.restoreOverrideCursor() |
|
140 |
|
141 self.__updateActionButtons() |
84 |
142 |
85 @pyqtSlot() |
143 @pyqtSlot() |
86 def on_packagesList_itemSelectionChanged(self): |
144 def on_packagesList_itemSelectionChanged(self): |
87 """ |
145 """ |
88 Slot documentation goes here. |
146 Private slot to handle the selection of some items.. |
89 """ |
147 """ |
90 # TODO: not implemented yet |
148 self.__updateActionButtons() |
91 raise NotImplementedError |
|
92 |
149 |
93 @pyqtSlot() |
150 @pyqtSlot() |
94 def on_refreshButton_clicked(self): |
151 def on_refreshButton_clicked(self): |
95 """ |
152 """ |
96 Slot documentation goes here. |
153 Private slot to refresh the display. |
97 """ |
154 """ |
98 # TODO: not implemented yet |
155 currentEnvironment = self.environmentsComboBox.currentText() |
99 raise NotImplementedError |
156 self.environmentsComboBox.clear() |
|
157 self.packagesList.clear() |
|
158 |
|
159 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
|
160 QApplication.processEvents() |
|
161 |
|
162 self.__populateEnvironments() |
|
163 |
|
164 index = self.environmentsComboBox.findText( |
|
165 currentEnvironment, Qt.MatchExactly | Qt.MatchCaseSensitive) |
|
166 if index != -1: |
|
167 self.environmentsComboBox.setCurrentIndex(index) |
|
168 |
|
169 QApplication.restoreOverrideCursor() |
|
170 self.__updateActionButtons() |
100 |
171 |
101 @pyqtSlot() |
172 @pyqtSlot() |
102 def on_upgradeButton_clicked(self): |
173 def on_upgradeButton_clicked(self): |
103 """ |
174 """ |
104 Slot documentation goes here. |
175 Slot documentation goes here. |