|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2015 - 2018 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, plugin, mode, parent=None): |
|
30 """ |
|
31 Constructor |
|
32 |
|
33 @param plugin reference to the plugin object |
|
34 @type PipInterfacePlugin |
|
35 @param mode mode of the dialog |
|
36 @type str |
|
37 @param parent reference to the parent widget |
|
38 @type QWidget |
|
39 """ |
|
40 super(PipFileSelectionDialog, self).__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:")) |
|
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(QDialogButtonBox.Ok).setEnabled(False) |
|
70 |
|
71 self.__default = self.tr("<Default>") |
|
72 pipExecutables = sorted(plugin.getPreferences("PipExecutables")) |
|
73 self.pipComboBox.addItem(self.__default) |
|
74 self.pipComboBox.addItems(pipExecutables) |
|
75 |
|
76 msh = self.minimumSizeHint() |
|
77 self.resize(max(self.width(), msh.width()), msh.height()) |
|
78 |
|
79 @pyqtSlot(str) |
|
80 def on_filePicker_textChanged(self, txt): |
|
81 """ |
|
82 Private slot to handle entering the name of a file. |
|
83 |
|
84 @param txt name of the file |
|
85 @type str |
|
86 """ |
|
87 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
88 bool(txt) and |
|
89 os.path.exists(Utilities.toNativeSeparators(txt)) |
|
90 ) |
|
91 |
|
92 def getData(self): |
|
93 """ |
|
94 Public method to get the entered data. |
|
95 |
|
96 @return tuple with the pip command and the name of the |
|
97 selected file |
|
98 @rtype tuple of (str, str) |
|
99 """ |
|
100 command = self.pipComboBox.currentText() |
|
101 if command == self.__default: |
|
102 command = "" |
|
103 |
|
104 return command, self.filePicker.text() |