eric7/PipInterface/PipPackagesWidget.py

branch
eric7
changeset 8356
68ec9c3d4de5
parent 8318
962bce857696
child 8358
144a6b854f70
equal deleted inserted replaced
8355:8a7677a63c8d 8356:68ec9c3d4de5
17 from PyQt6.QtWidgets import ( 17 from PyQt6.QtWidgets import (
18 QWidget, QToolButton, QApplication, QHeaderView, QTreeWidgetItem, 18 QWidget, QToolButton, QApplication, QHeaderView, QTreeWidgetItem,
19 QMenu, QDialog 19 QMenu, QDialog
20 ) 20 )
21 21
22 from E5Gui.E5Application import e5App 22 from E5Gui.EricApplication import ericApp
23 from E5Gui import E5MessageBox 23 from E5Gui import EricMessageBox
24 from E5Gui.E5OverrideCursor import E5OverrideCursor 24 from E5Gui.EricOverrideCursor import EricOverrideCursor
25 25
26 from .Ui_PipPackagesWidget import Ui_PipPackagesWidget 26 from .Ui_PipPackagesWidget import Ui_PipPackagesWidget
27 27
28 import UI.PixmapCache 28 import UI.PixmapCache
29 import Globals 29 import Globals
205 "entry-points": self.tr("Entry Points:"), 205 "entry-points": self.tr("Entry Points:"),
206 "files": self.tr("Files:"), 206 "files": self.tr("Files:"),
207 } 207 }
208 self.infoWidget.setHeaderLabels(["Key", "Value"]) 208 self.infoWidget.setHeaderLabels(["Key", "Value"])
209 209
210 venvManager = e5App().getObject("VirtualEnvManager") 210 venvManager = ericApp().getObject("VirtualEnvManager")
211 venvManager.virtualEnvironmentAdded.connect( 211 venvManager.virtualEnvironmentAdded.connect(
212 self.on_refreshButton_clicked) 212 self.on_refreshButton_clicked)
213 venvManager.virtualEnvironmentRemoved.connect( 213 venvManager.virtualEnvironmentRemoved.connect(
214 self.on_refreshButton_clicked) 214 self.on_refreshButton_clicked)
215 215
216 project = e5App().getObject("Project") 216 project = ericApp().getObject("Project")
217 project.projectOpened.connect( 217 project.projectOpened.connect(
218 self.on_refreshButton_clicked) 218 self.on_refreshButton_clicked)
219 project.projectClosed.connect( 219 project.projectClosed.connect(
220 self.on_refreshButton_clicked) 220 self.on_refreshButton_clicked)
221 221
359 if interpreter: 359 if interpreter:
360 self.statusLabel.show() 360 self.statusLabel.show()
361 self.statusLabel.setText( 361 self.statusLabel.setText(
362 self.tr("Getting installed packages...")) 362 self.tr("Getting installed packages..."))
363 363
364 with E5OverrideCursor(): 364 with EricOverrideCursor():
365 # 1. populate with installed packages 365 # 1. populate with installed packages
366 self.packagesList.setUpdatesEnabled(False) 366 self.packagesList.setUpdatesEnabled(False)
367 installedPackages = self.__pip.getInstalledPackages( 367 installedPackages = self.__pip.getInstalledPackages(
368 venvName, 368 venvName,
369 localPackages=self.localCheckBox.isChecked(), 369 localPackages=self.localCheckBox.isChecked(),
465 args.append("--verbose") 465 args.append("--verbose")
466 if self.installedFilesCheckBox.isChecked(): 466 if self.installedFilesCheckBox.isChecked():
467 args.append("--files") 467 args.append("--files")
468 args.append(itm.text(0)) 468 args.append(itm.text(0))
469 469
470 with E5OverrideCursor(): 470 with EricOverrideCursor():
471 success, output = self.__pip.runProcess(args, interpreter) 471 success, output = self.__pip.runProcess(args, interpreter)
472 472
473 if success and output: 473 if success and output:
474 mode = self.ShowProcessGeneralMode 474 mode = self.ShowProcessGeneralMode
475 for line in output.splitlines(): 475 for line in output.splitlines():
566 """ 566 """
567 currentEnvironment = self.environmentsComboBox.currentText() 567 currentEnvironment = self.environmentsComboBox.currentText()
568 self.environmentsComboBox.clear() 568 self.environmentsComboBox.clear()
569 self.packagesList.clear() 569 self.packagesList.clear()
570 570
571 with E5OverrideCursor(): 571 with EricOverrideCursor():
572 self.__populateEnvironments() 572 self.__populateEnvironments()
573 573
574 index = self.environmentsComboBox.findText( 574 index = self.environmentsComboBox.findText(
575 currentEnvironment, 575 currentEnvironment,
576 Qt.MatchFlag.MatchExactly | Qt.MatchFlag.MatchCaseSensitive 576 Qt.MatchFlag.MatchExactly | Qt.MatchFlag.MatchCaseSensitive
770 770
771 urlQuery = QUrlQuery(reply.url()) 771 urlQuery = QUrlQuery(reply.url())
772 searchTerm = urlQuery.queryItemValue("q") 772 searchTerm = urlQuery.queryItemValue("q")
773 773
774 if reply.error() != QNetworkReply.NetworkError.NoError: 774 if reply.error() != QNetworkReply.NetworkError.NoError:
775 E5MessageBox.warning( 775 EricMessageBox.warning(
776 None, 776 None,
777 self.tr("Search PyPI"), 777 self.tr("Search PyPI"),
778 self.tr( 778 self.tr(
779 "<p>Received an error while searching for <b>{0}</b>.</p>" 779 "<p>Received an error while searching for <b>{0}</b>.</p>"
780 "<p>Error: {1}</p>" 780 "<p>Error: {1}</p>"
792 msg = self.tr("%n package(s) found.", "", len(results)) 792 msg = self.tr("%n package(s) found.", "", len(results))
793 else: 793 else:
794 msg = self.tr("Showing first 20 packages found.") 794 msg = self.tr("Showing first 20 packages found.")
795 self.searchInfoLabel.setText(msg) 795 self.searchInfoLabel.setText(msg)
796 else: 796 else:
797 E5MessageBox.warning( 797 EricMessageBox.warning(
798 self, 798 self,
799 self.tr("Search PyPI"), 799 self.tr("Search PyPI"),
800 self.tr("""<p>There were no results for <b>{0}</b>.</p>""")) 800 self.tr("""<p>There were no results for <b>{0}</b>.</p>"""))
801 self.searchInfoLabel.setText( 801 self.searchInfoLabel.setText(
802 self.tr("""<p>There were no results for <b>{0}</b>.</p>""")) 802 self.tr("""<p>There were no results for <b>{0}</b>.</p>"""))
927 @type bool (optional) 927 @type bool (optional)
928 @param installable flag indicating that the package may be installed 928 @param installable flag indicating that the package may be installed
929 (defaults to False) 929 (defaults to False)
930 @type bool (optional) 930 @type bool (optional)
931 """ 931 """
932 with E5OverrideCursor(): 932 with EricOverrideCursor():
933 packageData = self.__pip.getPackageDetails( 933 packageData = self.__pip.getPackageDetails(
934 packageName, packageVersion) 934 packageName, packageVersion)
935 935
936 if packageData: 936 if packageData:
937 from .PipPackageDetailsDialog import PipPackageDetailsDialog 937 from .PipPackageDetailsDialog import PipPackageDetailsDialog
955 PipPackageDetailsDialog(packageData, buttonsMode=buttonsMode, 955 PipPackageDetailsDialog(packageData, buttonsMode=buttonsMode,
956 parent=self) 956 parent=self)
957 ) 957 )
958 self.__packageDetailsDialog.show() 958 self.__packageDetailsDialog.show()
959 else: 959 else:
960 E5MessageBox.warning( 960 EricMessageBox.warning(
961 self, 961 self,
962 self.tr("Search PyPI"), 962 self.tr("Search PyPI"),
963 self.tr("""<p>No package details info for <b>{0}</b>""" 963 self.tr("""<p>No package details info for <b>{0}</b>"""
964 """ available.</p>""").format(packageName)) 964 """ available.</p>""").format(packageName))
965 965
1193 return 1193 return
1194 else: 1194 else:
1195 cfgFile = self.__pip.getUserConfig() 1195 cfgFile = self.__pip.getUserConfig()
1196 cfgDir = os.path.dirname(cfgFile) 1196 cfgDir = os.path.dirname(cfgFile)
1197 if not cfgDir: 1197 if not cfgDir:
1198 E5MessageBox.critical( 1198 EricMessageBox.critical(
1199 None, 1199 None,
1200 self.tr("Edit Configuration"), 1200 self.tr("Edit Configuration"),
1201 self.tr("""No valid configuration path determined.""" 1201 self.tr("""No valid configuration path determined."""
1202 """ Aborting""")) 1202 """ Aborting"""))
1203 return 1203 return
1204 1204
1205 try: 1205 try:
1206 if not os.path.isdir(cfgDir): 1206 if not os.path.isdir(cfgDir):
1207 os.makedirs(cfgDir) 1207 os.makedirs(cfgDir)
1208 except OSError: 1208 except OSError:
1209 E5MessageBox.critical( 1209 EricMessageBox.critical(
1210 None, 1210 None,
1211 self.tr("Edit Configuration"), 1211 self.tr("Edit Configuration"),
1212 self.tr("""No valid configuration path determined.""" 1212 self.tr("""No valid configuration path determined."""
1213 """ Aborting""")) 1213 """ Aborting"""))
1214 return 1214 return
1217 with contextlib.suppress(OSError), open(cfgFile, "w") as f: 1217 with contextlib.suppress(OSError), open(cfgFile, "w") as f:
1218 f.write("[global]\n") 1218 f.write("[global]\n")
1219 1219
1220 # check, if the destination is writeable 1220 # check, if the destination is writeable
1221 if not os.access(cfgFile, os.W_OK): 1221 if not os.access(cfgFile, os.W_OK):
1222 E5MessageBox.critical( 1222 EricMessageBox.critical(
1223 None, 1223 None,
1224 self.tr("Edit Configuration"), 1224 self.tr("Edit Configuration"),
1225 self.tr("""No valid configuration path determined.""" 1225 self.tr("""No valid configuration path determined."""
1226 """ Aborting""")) 1226 """ Aborting"""))
1227 return 1227 return
1231 1231
1232 def __pipConfigure(self): 1232 def __pipConfigure(self):
1233 """ 1233 """
1234 Private slot to open the configuration page. 1234 Private slot to open the configuration page.
1235 """ 1235 """
1236 e5App().getObject("UserInterface").showPreferences("pipPage") 1236 ericApp().getObject("UserInterface").showPreferences("pipPage")
1237 1237
1238 @pyqtSlot() 1238 @pyqtSlot()
1239 def __showCacheInfo(self): 1239 def __showCacheInfo(self):
1240 """ 1240 """
1241 Private slot to show information about the cache. 1241 Private slot to show information about the cache.

eric ide

mercurial