src/eric7/PipInterface/PipFileSelectionDialog.py

Sat, 31 Dec 2022 16:23:21 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 31 Dec 2022 16:23:21 +0100
branch
eric7
changeset 9653
e67609152c5e
parent 9624
b47dfa7a137d
child 10439
21c28b0f9e41
permissions
-rw-r--r--

Updated copyright for 2023.

6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
9653
e67609152c5e Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9624
diff changeset
3 # Copyright (c) 2015 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 Module implementing a dialog to enter a file to be processed.
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import os
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
13 from PyQt6.QtCore import pyqtSlot
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
14 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
16 from eric7.EricWidgets.EricPathPicker import EricPathPickerModes
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
17 from eric7.SystemUtilities import FileSystemUtilities
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from .Ui_PipFileSelectionDialog import Ui_PipFileSelectionDialog
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 class PipFileSelectionDialog(QDialog, Ui_PipFileSelectionDialog):
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Class implementing a dialog to enter a file to be processed.
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
26
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
27 def __init__(self, pip, mode, install=True, parent=None):
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
30
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
31 @param pip reference to the pip object
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
32 @type Pip
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param mode mode of the dialog
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @type str
6327
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
35 @param install flag indicating an install action
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
36 @type bool
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @param parent reference to the parent widget
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @type QWidget
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
40 super().__init__(parent)
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.setupUi(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
42
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 if mode == "requirements":
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.fileLabel.setText(self.tr("Enter requirements file:"))
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8327
diff changeset
45 self.filePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
46 self.filePicker.setToolTip(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
47 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
48 "Press to select the requirements file through a file"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49 " selection dialog."
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
50 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
51 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
52 self.filePicker.setFilters(self.tr("Text Files (*.txt);;All Files (*)"))
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 elif mode == "package":
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.fileLabel.setText(self.tr("Enter package file:"))
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8327
diff changeset
55 self.filePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
56 self.filePicker.setToolTip(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
57 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58 "Press to select the package file through a file"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
59 " selection dialog."
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
60 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
61 )
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.filePicker.setFilters(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
63 self.tr(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
64 "Python Wheel (*.whl);;"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
65 "Archive Files (*.tar.gz *.zip);;"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
66 "All Files (*)"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
67 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
68 )
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 else:
6295
79bfd24e2fee Updated translations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6294
diff changeset
70 self.fileLabel.setText(self.tr("Enter file name:"))
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8327
diff changeset
71 self.filePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
72 self.filePicker.setToolTip(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
73 self.tr("Press to select a file through a file selection dialog.")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
74 )
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.filePicker.setFilters(self.tr("All Files (*)"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.filePicker.setDefaultDirectory(os.path.expanduser("~"))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
77
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
78 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
79
6327
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
80 self.userCheckBox.setVisible(install)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
81
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 msh = self.minimumSizeHint()
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.resize(max(self.width(), msh.width()), msh.height())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
84
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 @pyqtSlot(str)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 def on_filePicker_textChanged(self, txt):
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 Private slot to handle entering the name of a file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
89
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 @param txt name of the file
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 @type str
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 """
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
93 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
94 bool(txt) and os.path.exists(FileSystemUtilities.toNativeSeparators(txt))
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
96
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 def getData(self):
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 Public method to get the entered data.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
100
6795
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
101 @return tuple with the name of the selected file and a flag indicating
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
102 to install to the user install directory
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
103 @rtype tuple of (str, bool)
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
105 return (self.filePicker.text(), self.userCheckBox.isChecked())

eric ide

mercurial