eric6/PipInterface/PipPackageDetailsDialog.py

changeset 8090
c53117374255
parent 8086
eff504bb6dec
child 8143
2c730d5fd177
equal deleted inserted replaced
8089:e43bf8d7baf9 8090:c53117374255
5 5
6 """ 6 """
7 Module implementing a dialog to show details about a package. 7 Module implementing a dialog to show details about a package.
8 """ 8 """
9 9
10 from PyQt5.QtCore import Qt, QLocale 10 from PyQt5.QtCore import pyqtSlot, Qt, QLocale
11 from PyQt5.QtWidgets import ( 11 from PyQt5.QtWidgets import (
12 QDialog, QDialogButtonBox, QTreeWidgetItem, QLabel, QHeaderView 12 QDialog, QDialogButtonBox, QTreeWidgetItem, QLabel, QHeaderView,
13 QAbstractButton
13 ) 14 )
14 15
15 from .Ui_PipPackageDetailsDialog import Ui_PipPackageDetailsDialog 16 from .Ui_PipPackageDetailsDialog import Ui_PipPackageDetailsDialog
16 17
17 18
18 # TODO: add some 'convenience' buttons (see issue369)
19 class PipPackageDetailsDialog(QDialog, Ui_PipPackageDetailsDialog): 19 class PipPackageDetailsDialog(QDialog, Ui_PipPackageDetailsDialog):
20 """ 20 """
21 Class implementing a dialog to show details about a package. 21 Class implementing a dialog to show details about a package.
22 """ 22 """
23 def __init__(self, detailsData, parent=None): 23 ButtonInstall = 1
24 ButtonRemove = 2
25 ButtonUpgrade = 4
26
27 def __init__(self, detailsData, buttonsMode=0, parent=None):
24 """ 28 """
25 Constructor 29 Constructor
26 30
27 @param detailsData package details 31 @param detailsData package details
28 @type dict 32 @type dict
29 @param parent reference to the parent widget 33 @param buttonsMode flags telling which convenience buttons to enable
30 @type QWidget 34 (defaults to 0)
35 @type int (optional)
36 @param parent reference to the parent widget (defaults to None)
37 @type QWidget (optional)
31 """ 38 """
32 super(PipPackageDetailsDialog, self).__init__(parent) 39 super(PipPackageDetailsDialog, self).__init__(parent)
33 self.setupUi(self) 40 self.setupUi(self)
34 self.setWindowFlags(Qt.Window) 41 self.setWindowFlags(Qt.Window)
42
43 self.__pipWidget = parent
44
45 self.__installButton = self.buttonBox.addButton(
46 self.tr("Install"), QDialogButtonBox.ActionRole)
47 self.__removeButton = self.buttonBox.addButton(
48 self.tr("Uninstall"), QDialogButtonBox.ActionRole)
49 self.__upgradeButton = self.buttonBox.addButton(
50 self.tr("Upgrade"), QDialogButtonBox.ActionRole)
35 51
36 self.__locale = QLocale() 52 self.__locale = QLocale()
37 self.__packageTypeMap = { 53 self.__packageTypeMap = {
38 "sdist": self.tr("Source"), 54 "sdist": self.tr("Source"),
39 "bdist_wheel": self.tr("Python Wheel"), 55 "bdist_wheel": self.tr("Python Wheel"),
42 "bdist_msi": self.tr("MS Windows Installer"), 58 "bdist_msi": self.tr("MS Windows Installer"),
43 "bdist_rpm": self.tr("Unix Installer"), 59 "bdist_rpm": self.tr("Unix Installer"),
44 "bdist_deb": self.tr("Unix Installer"), 60 "bdist_deb": self.tr("Unix Installer"),
45 "bdist_dumb": self.tr("Archive"), 61 "bdist_dumb": self.tr("Archive"),
46 } 62 }
63 self.__packageName = detailsData["info"]["name"]
47 64
48 self.__populateDetails(detailsData["info"]) 65 self.__populateDetails(detailsData["info"])
49 self.__populateDownloadUrls(detailsData["urls"]) 66 self.__populateDownloadUrls(detailsData["urls"])
50 self.__populateRequiresProvides(detailsData["info"]) 67 self.__populateRequiresProvides(detailsData["info"])
68
69 self.__installButton.setEnabled(buttonsMode & self.ButtonInstall)
70 self.__removeButton.setEnabled(buttonsMode & self.ButtonRemove)
71 self.__upgradeButton.setEnabled(buttonsMode & self.ButtonUpgrade)
51 72
52 def __populateDetails(self, detailsData): 73 def __populateDetails(self, detailsData):
53 """ 74 """
54 Private method to populate the details tab. 75 Private method to populate the details tab.
55 76
214 unit = self.tr("MB") 235 unit = self.tr("MB")
215 else: 236 else:
216 size /= 1024 * 1024 * 1024 237 size /= 1024 * 1024 * 1024
217 unit = self.tr("GB") 238 unit = self.tr("GB")
218 return self.tr("{0:.1f} {1}", "value, unit").format(size, unit) 239 return self.tr("{0:.1f} {1}", "value, unit").format(size, unit)
240
241 @pyqtSlot(QAbstractButton)
242 def on_buttonBox_clicked(self, button):
243 """
244 Private slot handling the user pressing an action button.
245
246 @param button button activated by the user
247 @type QAbstractButton
248 """
249 if button is self.__installButton:
250 self.__pipWidget.executeInstallPackages([self.__packageName])
251 self.__installButton.setEnabled(False)
252 self.__removeButton.setEnabled(True)
253 self.__upgradeButton.setEnabled(False)
254 self.raise_()
255 elif button is self.__removeButton:
256 self.__pipWidget.executeUninstallPackages([self.__packageName])
257 self.__installButton.setEnabled(True)
258 self.__removeButton.setEnabled(False)
259 self.__upgradeButton.setEnabled(False)
260 self.raise_()
261 elif button is self.__upgradeButton:
262 self.__pipWidget.executeUpgradePackages([self.__packageName])
263 self.__installButton.setEnabled(False)
264 self.__removeButton.setEnabled(True)
265 self.__upgradeButton.setEnabled(False)
266 self.raise_()

eric ide

mercurial