eric6/PipInterface/PipFileSelectionDialog.py

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

eric ide

mercurial