ProjectDjango/DjangoLoaddataDataDialog.py

changeset 2
1e97424fda0c
child 26
2dd206cd1aa2
equal deleted inserted replaced
1:13a0cced0c6e 2:1e97424fda0c
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2013 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 PyQt4.QtCore import pyqtSlot
11 from PyQt4.QtGui import QDialog, QDialogButtonBox
12
13 from E5Gui import E5FileDialog
14
15 from .Ui_DjangoLoaddataDataDialog import Ui_DjangoLoaddataDataDialog
16
17 import Utilities
18
19
20 class DjangoLoaddataDataDialog(QDialog, Ui_DjangoLoaddataDataDialog):
21 """
22 Class implementing a dialog to enter the data for the 'loaddata' command.
23 """
24 def __init__(self, project, parent=None):
25 """
26 Constructor
27
28 @param project reference to the Django project object
29 @param parent reference to the parent widget (QWidget)
30 """
31 super().__init__(parent)
32 self.setupUi(self)
33
34 self.__project = project
35
36 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
37
38 @pyqtSlot(str)
39 def on_fixturesEdit_textChanged(self, txt):
40 """
41 Private slot to handle a change of the fixtures text.
42 """
43 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(bool(txt))
44
45 @pyqtSlot()
46 def on_fixtureFileButton_clicked(self):
47 """
48 Private slot to select a fixture file via a file selection dialog.
49 """
50 fileFilters = self.trUtf8("JSON Files (*.json);;XML Files (*.xml);;")
51 try:
52 import yaml # __IGNORE_WARNING__
53 fileFilters += self.trUtf8("YAML Files (*.yaml);;")
54 except ImportError:
55 pass
56 fileFilters += self.trUtf8("All Files (*)")
57
58 fixtureFiles = E5FileDialog.getOpenFileNames(
59 self,
60 self.trUtf8("Select fixture file"),
61 self.__project.getProjectPath(),
62 fileFilters)
63
64 if fixtureFiles:
65 self.fixturesEdit.setText(" ".join(
66 [Utilities.toNativeSeparators(f) for f in fixtureFiles]))
67
68 def getData(self):
69 """
70 Public method to get the data entered into the dialog.
71
72 @return list of fixtures (list of strings)
73 """
74 fixturesStr = self.fixturesEdit.text()
75 fixtures = fixturesStr.split()
76
77 return fixtures

eric ide

mercurial