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.venvComboBox.addItem(pip.getDefaultEnvironmentString()) |
|
74 projectVenv = pip.getProjectEnvironmentString() |
|
75 if projectVenv: |
|
76 self.venvComboBox.addItem(projectVenv) |
|
77 self.venvComboBox.addItems(pip.getVirtualenvNames()) |
|
78 |
|
79 self.userCheckBox.setVisible(install) |
|
80 |
|
81 msh = self.minimumSizeHint() |
|
82 self.resize(max(self.width(), msh.width()), msh.height()) |
|
83 |
|
84 @pyqtSlot(str) |
|
85 def on_filePicker_textChanged(self, txt): |
|
86 """ |
|
87 Private slot to handle entering the name of a file. |
|
88 |
|
89 @param txt name of the file |
|
90 @type str |
|
91 """ |
|
92 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
93 bool(txt) and |
|
94 os.path.exists(Utilities.toNativeSeparators(txt)) |
|
95 ) |
|
96 |
|
97 def getData(self): |
|
98 """ |
|
99 Public method to get the entered data. |
|
100 |
|
101 @return tuple with the environment name, the name of the |
|
102 selected file and a flag indicating to install to the |
|
103 user install directory |
|
104 @rtype tuple of (str, str, bool) |
|
105 """ |
|
106 return ( |
|
107 self.venvComboBox.currentText(), |
|
108 self.filePicker.text(), |
|
109 self.userCheckBox.isChecked() |
|
110 ) |
|