CondaInterface/CondaNewEnvironmentDataDialog.py

branch
maintenance
changeset 6826
c6dda2cbe081
parent 6731
c70eaa492741
equal deleted inserted replaced
6764:d14ddbfbbd36 6826:c6dda2cbe081
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter data for a new conda environment.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
14
15 from E5Gui.E5PathPicker import E5PathPickerModes
16
17 from .Ui_CondaNewEnvironmentDataDialog import Ui_CondaNewEnvironmentDataDialog
18
19
20 class CondaNewEnvironmentDataDialog(QDialog, Ui_CondaNewEnvironmentDataDialog):
21 """
22 Class implementing a dialog to enter data for a new conda environment.
23 """
24 def __init__(self, title, showRequirements, parent=None):
25 """
26 Constructor
27
28 @param title tirle of the dialog
29 @type str
30 @param showRequirements flag indicating to show the requirements
31 file input widget
32 @type bool
33 @param parent reference to the parent widget
34 @type QWidget
35 """
36 super(CondaNewEnvironmentDataDialog, self).__init__(parent)
37 self.setupUi(self)
38
39 self.setWindowTitle(title)
40
41 self.__requirementsMode = showRequirements
42
43 self.requirementsFilePicker.setMode(E5PathPickerModes.OpenFileMode)
44 self.requirementsFilePicker.setFilters(
45 self.tr("Text Files (*.txt);;All Files (*)"))
46
47 self.requirementsLabel.setVisible(showRequirements)
48 self.requirementsFilePicker.setVisible(showRequirements)
49
50 self.__updateOK()
51
52 msh = self.minimumSizeHint()
53 self.resize(max(self.width(), msh.width()), msh.height())
54
55 def __updateOK(self):
56 """
57 Private method to update the enabled state of the OK button.
58 """
59 enable = bool(self.nameEdit.text()) and bool(self.condaNameEdit.text())
60 if self.__requirementsMode:
61 enable &= bool(self.requirementsFilePicker.text())
62
63 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
64
65 @pyqtSlot(str)
66 def on_nameEdit_textChanged(self, txt):
67 """
68 Private slot to handle changes of the logical name.
69
70 @param txt current text of the logical name entry
71 @type str
72 """
73 self.__updateOK()
74
75 @pyqtSlot(str)
76 def on_condaNameEdit_textChanged(self, txt):
77 """
78 Private slot to handle changes of the conda name.
79
80 @param txt current text of the conda name entry
81 @type str
82 """
83 self.__updateOK()
84
85 @pyqtSlot(str)
86 def on_requirementsFilePicker_textChanged(self, txt):
87 """
88 Private slot to handle changes of the requirements file name.
89
90 @param txt current text of the requirements file name entry
91 @type str
92 """
93 self.__updateOK()
94
95 def getData(self):
96 """
97 Public method to get the entered data.
98
99 @return tuple with the logical name of the new environment, the conda
100 name and the requirements file name
101 @rtype tuple of (str, str, str)
102 """
103 if self.__requirementsMode:
104 requirementsFile = self.requirementsFilePicker.text()
105 else:
106 requirementsFile = ""
107
108 return (
109 self.nameEdit.text(),
110 self.condaNameEdit.text(),
111 requirementsFile
112 )

eric ide

mercurial