ProjectDjango/DjangoRunTestServerDataDialog.py

changeset 125
d280acf98fb5
parent 121
2346aa3fffcc
child 142
ecadd7fd0963
equal deleted inserted replaced
124:5c925935cbb9 125:d280acf98fb5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2013 - 2018 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter the data for the 'loaddata' command.
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 import E5FileDialog
16
17 from .Ui_DjangoRunTestServerDataDialog import Ui_DjangoRunTestServerDataDialog
18
19 import Utilities
20 import UI.PixmapCache
21
22
23 class DjangoRunTestServerDataDialog(QDialog, Ui_DjangoRunTestServerDataDialog):
24 """
25 Class implementing a dialog to enter the data for the 'loaddata' command.
26 """
27 def __init__(self, project, parent=None):
28 """
29 Constructor
30
31 @param project reference to the Django project object
32 @param parent reference to the parent widget (QWidget)
33 """
34 super(DjangoRunTestServerDataDialog, self).__init__(parent)
35 self.setupUi(self)
36
37 self.fixtureFileButton.setIcon(UI.PixmapCache.getIcon("open.png"))
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);;")
61 try:
62 import yaml # __IGNORE_WARNING__
63 fileFilters += self.tr("YAML Files (*.yaml);;")
64 except ImportError:
65 pass
66 fileFilters += self.tr("All Files (*)")
67
68 fixtureFiles = E5FileDialog.getOpenFileNames(
69 self,
70 self.tr("Select fixture file"),
71 self.__project.getProjectPath(),
72 fileFilters)
73
74 if fixtureFiles:
75 self.fixturesEdit.setText(" ".join(
76 [Utilities.toNativeSeparators(f) for f in fixtureFiles]))
77
78 def getData(self):
79 """
80 Public method to get the data entered into the dialog.
81
82 @return list of fixtures (list of strings)
83 """
84 fixturesStr = self.fixturesEdit.text()
85 fixtures = fixturesStr.split()
86
87 return fixtures

eric ide

mercurial