7 Module implementing a dialog to enter the data for the 'loaddata' command. |
7 Module implementing a dialog to enter the data for the 'loaddata' command. |
8 """ |
8 """ |
9 |
9 |
10 import contextlib |
10 import contextlib |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot |
12 from PyQt6.QtCore import pyqtSlot |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
14 |
14 |
15 from E5Gui import E5FileDialog |
15 from EricWidgets.EricPathPicker import EricPathPickerModes |
16 |
16 |
17 from .Ui_DjangoRunTestServerDataDialog import Ui_DjangoRunTestServerDataDialog |
17 from .Ui_DjangoRunTestServerDataDialog import Ui_DjangoRunTestServerDataDialog |
18 |
18 |
19 import Utilities |
|
20 import UI.PixmapCache |
19 import UI.PixmapCache |
21 |
20 |
22 |
21 |
23 class DjangoRunTestServerDataDialog(QDialog, Ui_DjangoRunTestServerDataDialog): |
22 class DjangoRunTestServerDataDialog(QDialog, Ui_DjangoRunTestServerDataDialog): |
24 """ |
23 """ |
27 def __init__(self, project, parent=None): |
26 def __init__(self, project, parent=None): |
28 """ |
27 """ |
29 Constructor |
28 Constructor |
30 |
29 |
31 @param project reference to the Django project object |
30 @param project reference to the Django project object |
32 @param parent reference to the parent widget (QWidget) |
31 @type Project |
|
32 @param parent reference to the parent widget |
|
33 @type QWidget |
33 """ |
34 """ |
34 super().__init__(parent) |
35 super().__init__(parent) |
35 self.setupUi(self) |
36 self.setupUi(self) |
36 |
37 |
37 self.fixtureFileButton.setIcon(UI.PixmapCache.getIcon("open")) |
|
38 |
|
39 self.__project = project |
|
40 |
|
41 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
42 |
|
43 msh = self.minimumSizeHint() |
|
44 self.resize(max(self.width(), msh.width()), msh.height()) |
|
45 |
|
46 @pyqtSlot(str) |
|
47 def on_fixturesEdit_textChanged(self, txt): |
|
48 """ |
|
49 Private slot to handle a change of the fixtures text. |
|
50 |
|
51 @param txt text of the line edit (string) |
|
52 """ |
|
53 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(bool(txt)) |
|
54 |
|
55 @pyqtSlot() |
|
56 def on_fixtureFileButton_clicked(self): |
|
57 """ |
|
58 Private slot to select a fixture file via a file selection dialog. |
|
59 """ |
|
60 fileFilters = self.tr("JSON Files (*.json);;XML Files (*.xml);;") |
38 fileFilters = self.tr("JSON Files (*.json);;XML Files (*.xml);;") |
61 with contextlib.suppress(ImportError): |
39 with contextlib.suppress(ImportError): |
62 import yaml # __IGNORE_WARNING__ |
40 import yaml # __IGNORE_WARNING__ |
63 fileFilters += self.tr("YAML Files (*.yaml);;") |
41 fileFilters += self.tr("YAML Files (*.yaml);;") |
64 fileFilters += self.tr("All Files (*)") |
42 fileFilters += self.tr("All Files (*)") |
65 |
43 |
66 fixtureFiles = E5FileDialog.getOpenFileNames( |
44 self.fixturePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
67 self, |
45 self.fixturePicker.setFilters(fileFilters) |
68 self.tr("Select fixture file"), |
|
69 self.__project.getProjectPath(), |
|
70 fileFilters) |
|
71 |
46 |
72 if fixtureFiles: |
47 self.fixtureFileButton.setIcon(UI.PixmapCache.getIcon("open")) |
73 self.fixturesEdit.setText(" ".join( |
48 |
74 [Utilities.toNativeSeparators(f) for f in fixtureFiles])) |
49 self.__project = project |
|
50 |
|
51 self.buttonBox.button( |
|
52 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
|
53 |
|
54 msh = self.minimumSizeHint() |
|
55 self.resize(max(self.width(), msh.width()), msh.height()) |
|
56 |
|
57 @pyqtSlot(str) |
|
58 def on_fixturesPicker_textChanged(self, txt): |
|
59 """ |
|
60 Private slot to handle a change of the fixtures text. |
|
61 |
|
62 @param txt text of the line edit |
|
63 @type str |
|
64 """ |
|
65 self.buttonBox.button( |
|
66 QDialogButtonBox.StandardButton.Ok).setEnabled(bool(txt)) |
75 |
67 |
76 def getData(self): |
68 def getData(self): |
77 """ |
69 """ |
78 Public method to get the data entered into the dialog. |
70 Public method to get the data entered into the dialog. |
79 |
71 |
80 @return list of fixtures (list of strings) |
72 @return list of fixtures |
|
73 @rtype list of str |
81 """ |
74 """ |
82 fixturesStr = self.fixturesEdit.text() |
75 fixturesStr = self.fixturePicker.text() |
83 fixtures = fixturesStr.split() |
76 fixtures = fixturesStr.split() |
84 |
77 |
85 return fixtures |
78 return fixtures |