eric6/PipInterface/PipFileSelectionDialog.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

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
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2015 - 2021 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
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt5.QtCore import pyqtSlot
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from E5Gui.E5PathPicker import E5PathPickerModes
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 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
19
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 import Utilities
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
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 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
24 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 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
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
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 super(PipFileSelectionDialog, self).__init__(parent)
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)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
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:"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.filePicker.setMode(E5PathPickerModes.OpenFileMode)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.filePicker.setToolTip(self.tr(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 "Press to select the requirements file through a file"
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 " selection dialog."))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.filePicker.setFilters(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.tr("Text Files (*.txt);;All Files (*)"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 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
52 self.fileLabel.setText(self.tr("Enter package file:"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.filePicker.setMode(E5PathPickerModes.OpenFileMode)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.filePicker.setToolTip(self.tr(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 "Press to select the package file through a file"
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 " selection dialog."))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.filePicker.setFilters(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.tr("Python Wheel (*.whl);;"
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 "Archive Files (*.tar.gz *.zip);;"
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 "All Files (*)"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 else:
6295
79bfd24e2fee Updated translations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6294
diff changeset
62 self.fileLabel.setText(self.tr("Enter file name:"))
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.filePicker.setMode(E5PathPickerModes.OpenFileMode)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.filePicker.setToolTip(self.tr(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 "Press to select a file through a file selection dialog."))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 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
67 self.filePicker.setDefaultDirectory(os.path.expanduser("~"))
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
6327
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
71 self.userCheckBox.setVisible(install)
a1716d9210f4 pip Interface: started to add support for the '--user' option.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6301
diff changeset
72
6294
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 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
74 self.resize(max(self.width(), msh.width()), msh.height())
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 @pyqtSlot(str)
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 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
78 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 Private slot to handle entering the name of a file.
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 @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
82 @type str
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 bool(txt) and
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 os.path.exists(Utilities.toNativeSeparators(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
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 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
90 """
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 Public method to get the entered data.
58f82c179d2b pip Interface: added an action to install a locally available package/wheel
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
6795
6e2ed2aac325 PipInterface: continued with the pip interface widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6782
diff changeset
93 @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
94 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
95 @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
96 """
6342
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
97 return (
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
98 self.filePicker.text(),
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
99 self.userCheckBox.isChecked()
c79ecba9cde7 pip Interface: changed to use the new VirtualEnv Manager
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6327
diff changeset
100 )

eric ide

mercurial