src/eric7/VirtualEnv/VirtualenvNameDialog.py

Sat, 31 Dec 2022 16:23:21 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 31 Dec 2022 16:23:21 +0100
branch
eric7
changeset 9653
e67609152c5e
parent 9473
3f23dbf37dbe
child 10439
21c28b0f9e41
permissions
-rw-r--r--

Updated copyright for 2023.

# -*- coding: utf-8 -*-

# Copyright (c) 2019 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to enter the logical name for a new virtual
environment.
"""

from PyQt6.QtCore import Qt, pyqtSlot
from PyQt6.QtWidgets import QDialog, QDialogButtonBox

from .Ui_VirtualenvNameDialog import Ui_VirtualenvNameDialog


class VirtualenvNameDialog(QDialog, Ui_VirtualenvNameDialog):
    """
    Class implementing a dialog to enter the logical name for a new virtual
    environment.
    """

    def __init__(self, environments, currentName, parent=None):
        """
        Constructor

        @param environments list of environment names to be shown
        @type list of str
        @param currentName name to be shown in the name edit
        @type str
        @param parent reference to the parent widget
        @type QWidget
        """
        super().__init__(parent)
        self.setupUi(self)

        self.envsList.addItems(environments)
        self.nameEdit.setText(currentName)

        self.nameEdit.setFocus(Qt.FocusReason.OtherFocusReason)
        self.nameEdit.selectAll()

    @pyqtSlot(str)
    def on_nameEdit_textChanged(self, txt):
        """
        Private slot to handle a change of the environment name.

        @param txt contens of the name edit
        @type str
        """
        items = self.envsList.findItems(txt, Qt.MatchFlag.MatchExactly)
        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(
            bool(txt) and len(items) == 0
        )

    def getName(self):
        """
        Public method to get the entered name.

        @return name for the environment
        @rtype str
        """
        return self.nameEdit.text()

eric ide

mercurial