ProjectDjango/DjangoRunTestServerDataDialog.py

Mon, 28 Oct 2024 16:24:54 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 28 Oct 2024 16:24:54 +0100
branch
eric7
changeset 195
b027b4f90994
parent 191
7b03dfe583e3
child 197
2667e16a3379
permissions
-rw-r--r--

- changed to the new style header
- ensured proper parent relationship of modal dialogs
- included compiled form files

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

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

"""
Module implementing a dialog to enter the data for the 'loaddata' command.
"""

import contextlib

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

try:
    from eric7.EricGui import EricPixmapCache
except ImportError:
    from UI import PixmapCache as EricPixmapCache
from eric7.EricWidgets.EricPathPicker import EricPathPickerModes

from .Ui_DjangoRunTestServerDataDialog import Ui_DjangoRunTestServerDataDialog


class DjangoRunTestServerDataDialog(QDialog, Ui_DjangoRunTestServerDataDialog):
    """
    Class implementing a dialog to enter the data for the 'loaddata' command.
    """

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

        @param project reference to the Django project object
        @type Project
        @param parent reference to the parent widget
        @type QWidget
        """
        super().__init__(parent)
        self.setupUi(self)

        fileFilters = self.tr("JSON Files (*.json);;XML Files (*.xml);;")
        with contextlib.suppress(ImportError):
            import yaml  # __IGNORE_WARNING__

            fileFilters += self.tr("YAML Files (*.yaml);;")
        fileFilters += self.tr("All Files (*)")

        self.fixturePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
        self.fixturePicker.setFilters(fileFilters)

        self.fixtureFileButton.setIcon(EricPixmapCache.getIcon("open"))

        self.__project = project

        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)

        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())

    @pyqtSlot(str)
    def on_fixturesPicker_textChanged(self, txt):
        """
        Private slot to handle a change of the fixtures text.

        @param txt text of the line edit
        @type str
        """
        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(bool(txt))

    def getData(self):
        """
        Public method to get the data entered into the dialog.

        @return list of fixtures
        @rtype list of str
        """
        fixturesStr = self.fixturePicker.text()
        fixtures = fixturesStr.split()

        return fixtures

eric ide

mercurial