VirtualEnv/VirtualenvNameDialog.py

branch
maintenance
changeset 6826
c6dda2cbe081
parent 6678
5f1de9e59227
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 the logical name for a new virtual
8 environment.
9 """
10
11 from __future__ import unicode_literals
12
13 from PyQt5.QtCore import pyqtSlot, Qt
14 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
15
16 from .Ui_VirtualenvNameDialog import Ui_VirtualenvNameDialog
17
18
19 class VirtualenvNameDialog(QDialog, Ui_VirtualenvNameDialog):
20 """
21 Class implementing a dialog to enter the logical name for a new virtual
22 environment.
23 """
24 def __init__(self, environments, currentName, parent=None):
25 """
26 Constructor
27
28 @param environments list of environment names to be shown
29 @type list of str
30 @param currentName name to be shown in the name edit
31 @type str
32 @param parent reference to the parent widget
33 @type QWidget
34 """
35 super(VirtualenvNameDialog, self).__init__(parent)
36 self.setupUi(self)
37
38 self.envsList.addItems(environments)
39 self.nameEdit.setText(currentName)
40
41 self.nameEdit.setFocus(Qt.OtherFocusReason)
42 self.nameEdit.selectAll()
43
44 @pyqtSlot(str)
45 def on_nameEdit_textChanged(self, txt):
46 """
47 Private slot to handle a change of the environment name.
48
49 @param txt contens of the name edit
50 @type str
51 """
52 items = self.envsList.findItems(txt, Qt.MatchExactly)
53 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
54 bool(txt) and len(items) == 0)
55
56 def getName(self):
57 """
58 Public method to get the entered name.
59
60 @return name for the environment
61 @rtype str
62 """
63 return self.nameEdit.text()

eric ide

mercurial