eric7/PipInterface/PipFileSelectionDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2015 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6
7 """
8 Module implementing a dialog to enter a file to be processed.
9 """
10
11 import os
12
13 from PyQt5.QtCore import pyqtSlot
14 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
15
16 from E5Gui.E5PathPicker import E5PathPickerModes
17
18 from .Ui_PipFileSelectionDialog import Ui_PipFileSelectionDialog
19
20 import Utilities
21
22
23 class PipFileSelectionDialog(QDialog, Ui_PipFileSelectionDialog):
24 """
25 Class implementing a dialog to enter a file to be processed.
26 """
27 def __init__(self, pip, mode, install=True, parent=None):
28 """
29 Constructor
30
31 @param pip reference to the pip object
32 @type Pip
33 @param mode mode of the dialog
34 @type str
35 @param install flag indicating an install action
36 @type bool
37 @param parent reference to the parent widget
38 @type QWidget
39 """
40 super().__init__(parent)
41 self.setupUi(self)
42
43 if mode == "requirements":
44 self.fileLabel.setText(self.tr("Enter requirements file:"))
45 self.filePicker.setMode(E5PathPickerModes.OpenFileMode)
46 self.filePicker.setToolTip(self.tr(
47 "Press to select the requirements file through a file"
48 " selection dialog."))
49 self.filePicker.setFilters(
50 self.tr("Text Files (*.txt);;All Files (*)"))
51 elif mode == "package":
52 self.fileLabel.setText(self.tr("Enter package file:"))
53 self.filePicker.setMode(E5PathPickerModes.OpenFileMode)
54 self.filePicker.setToolTip(self.tr(
55 "Press to select the package file through a file"
56 " selection dialog."))
57 self.filePicker.setFilters(
58 self.tr("Python Wheel (*.whl);;"
59 "Archive Files (*.tar.gz *.zip);;"
60 "All Files (*)"))
61 else:
62 self.fileLabel.setText(self.tr("Enter file name:"))
63 self.filePicker.setMode(E5PathPickerModes.OpenFileMode)
64 self.filePicker.setToolTip(self.tr(
65 "Press to select a file through a file selection dialog."))
66 self.filePicker.setFilters(self.tr("All Files (*)"))
67 self.filePicker.setDefaultDirectory(os.path.expanduser("~"))
68
69 self.buttonBox.button(
70 QDialogButtonBox.StandardButton.Ok).setEnabled(False)
71
72 self.userCheckBox.setVisible(install)
73
74 msh = self.minimumSizeHint()
75 self.resize(max(self.width(), msh.width()), msh.height())
76
77 @pyqtSlot(str)
78 def on_filePicker_textChanged(self, txt):
79 """
80 Private slot to handle entering the name of a file.
81
82 @param txt name of the file
83 @type str
84 """
85 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
86 bool(txt) and
87 os.path.exists(Utilities.toNativeSeparators(txt))
88 )
89
90 def getData(self):
91 """
92 Public method to get the entered data.
93
94 @return tuple with the name of the selected file and a flag indicating
95 to install to the user install directory
96 @rtype tuple of (str, bool)
97 """
98 return (
99 self.filePicker.text(),
100 self.userCheckBox.isChecked()
101 )

eric ide

mercurial