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 requirements file. |
|
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 import E5FileDialog |
|
19 |
|
20 from .Ui_PipRequirementsSelectionDialog import \ |
|
21 Ui_PipRequirementsSelectionDialog |
|
22 |
|
23 import Utilities |
|
24 import UI.PixmapCache |
|
25 |
|
26 |
|
27 class PipRequirementsSelectionDialog(QDialog, |
|
28 Ui_PipRequirementsSelectionDialog): |
|
29 """ |
|
30 Class implementing a dialog to enter a requirements file. |
|
31 """ |
|
32 def __init__(self, plugin, parent=None): |
|
33 """ |
|
34 Constructor |
|
35 |
|
36 @param plugin reference to the plugin object (ToolPipPlugin) |
|
37 @param parent reference to the parent widget (QWidget) |
|
38 """ |
|
39 super(PipRequirementsSelectionDialog, self).__init__(parent) |
|
40 self.setupUi(self) |
|
41 |
|
42 self.fileButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
|
43 |
|
44 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
45 |
|
46 self.__default = self.tr("<Default>") |
|
47 pipExecutables = sorted(plugin.getPreferences("PipExecutables")) |
|
48 self.pipComboBox.addItem(self.__default) |
|
49 self.pipComboBox.addItems(pipExecutables) |
|
50 |
|
51 msh = self.minimumSizeHint() |
|
52 self.resize(max(self.width(), msh.width()), msh.height()) |
|
53 |
|
54 @pyqtSlot() |
|
55 def on_fileButton_clicked(self): |
|
56 """ |
|
57 Private slot to enter the requirements file via a file selection |
|
58 dialog. |
|
59 """ |
|
60 fileName = E5FileDialog.getOpenFileName( |
|
61 self, |
|
62 self.tr("Select the requirements file"), |
|
63 self.requirementsEdit.text() or os.path.expanduser("~"), |
|
64 self.tr("Text Files (*.txt);;All Files (*)") |
|
65 ) |
|
66 if fileName: |
|
67 self.requirementsEdit.setText( |
|
68 Utilities.toNativeSeparators(fileName)) |
|
69 |
|
70 @pyqtSlot(str) |
|
71 def on_requirementsEdit_textChanged(self, txt): |
|
72 """ |
|
73 Private slot handling entering the name of a requirements file. |
|
74 |
|
75 @param txt name of the requirements file (string) |
|
76 """ |
|
77 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
78 bool(txt) and |
|
79 os.path.exists(Utilities.toNativeSeparators(txt)) |
|
80 ) |
|
81 |
|
82 def getData(self): |
|
83 """ |
|
84 Public method to get the entered data. |
|
85 |
|
86 @return tuple with the pip command (string) and the name of the |
|
87 requirements file (string) |
|
88 """ |
|
89 command = self.pipComboBox.currentText() |
|
90 if command == self.__default: |
|
91 command = "" |
|
92 |
|
93 return command, self.requirementsEdit.text() |
|