Project/AddDirectoryDialog.py

changeset 0
de9c2efb9d02
child 7
c679fb30c8f3
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2002 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to add files of a directory to the project.
8 """
9
10 from PyQt4.QtCore import *
11 from PyQt4.QtGui import *
12
13 from E4Gui.E4Completers import E4DirCompleter
14
15 from Ui_AddDirectoryDialog import Ui_AddDirectoryDialog
16
17 import Utilities
18
19 class AddDirectoryDialog(QDialog, Ui_AddDirectoryDialog):
20 """
21 Class implementing a dialog to add files of a directory to the project.
22 """
23 def __init__(self, pro, filter = 'source', parent = None, name = None,
24 startdir = None):
25 """
26 Constructor
27
28 @param pro reference to the project object
29 @param filter file type filter (string)
30 @param parent parent widget of this dialog (QWidget)
31 @param name name of this dialog (string)
32 @param startdir start directory for the selection dialog
33 """
34 QDialog.__init__(self,parent)
35 if name:
36 self.setObjectName(name)
37 self.setupUi(self)
38
39 self.sourceDirCompleter = E4DirCompleter(self.sourceDirEdit)
40 self.targetDirCompleter = E4DirCompleter(self.targetDirEdit)
41
42 self.ppath = pro.ppath
43 self.targetDirEdit.setText(self.ppath)
44 self.startdir = startdir
45 self.on_filterComboBox_highlighted('(*.py)') # enable all dialog elements
46 if filter == 'source': # it is a source file
47 self.filterComboBox.addItem(self.trUtf8("Source Files"),
48 QVariant("SOURCES"))
49 elif filter == 'form':
50 self.filterComboBox.addItem(self.trUtf8("Forms Files"),
51 QVariant("FORMS"))
52 elif filter == 'resource':
53 self.filterComboBox.addItem(self.trUtf8("Resource Files"),
54 QVariant("RESOURCES"))
55 elif filter == 'interface':
56 self.filterComboBox.addItem(self.trUtf8("Interface Files"),
57 QVariant("INTERFACES"))
58 elif filter == 'others':
59 self.filterComboBox.addItem(self.trUtf8("Other Files (*)"),
60 QVariant("OTHERS"))
61 self.on_filterComboBox_highlighted('(*)')
62 else:
63 self.filterComboBox.addItem(self.trUtf8("Source Files"),
64 QVariant("SOURCES"))
65 self.filterComboBox.addItem(self.trUtf8("Forms Files"),
66 QVariant("FORMS"))
67 self.filterComboBox.addItem(self.trUtf8("Resource Files"),
68 QVariant("RESOURCES"))
69 self.filterComboBox.addItem(self.trUtf8("Interface Files"),
70 QVariant("INTERFACES"))
71 self.filterComboBox.addItem(self.trUtf8("Other Files (*)"),
72 QVariant("OTHERS"))
73 self.filterComboBox.setCurrentIndex(0)
74
75 @pyqtSlot(str)
76 def on_filterComboBox_highlighted(self, fileType):
77 """
78 Private slot to handle the selection of a file type.
79
80 @param fileType the selected file type (string)
81 """
82 if fileType.endswith('(*)'):
83 self.targetDirLabel.setEnabled(False)
84 self.targetDirEdit.setEnabled(False)
85 self.targetDirButton.setEnabled(False)
86 self.recursiveCheckBox.setEnabled(False)
87 else:
88 self.targetDirLabel.setEnabled(True)
89 self.targetDirEdit.setEnabled(True)
90 self.targetDirButton.setEnabled(True)
91 self.recursiveCheckBox.setEnabled(True)
92
93 def __dirDialog(self, textEdit):
94 """
95 Private slot to display a directory selection dialog.
96
97 @param textEdit field for the display of the selected directory name
98 (QLineEdit)
99 """
100 startdir = textEdit.text()
101 if not startdir and self.startdir is not None:
102 startdir = self.startdir
103
104 directory = QFileDialog.getExistingDirectory(
105 self,
106 self.trUtf8("Select directory"),
107 startdir,
108 QFileDialog.Options(QFileDialog.Option(0)))
109
110 if directory:
111 textEdit.setText(Utilities.toNativeSeparators(directory))
112
113 @pyqtSlot()
114 def on_sourceDirButton_clicked(self):
115 """
116 Private slot to handle the source dir button press.
117 """
118 self.__dirDialog(self.sourceDirEdit)
119
120 @pyqtSlot()
121 def on_targetDirButton_clicked(self):
122 """
123 Private slot to handle the target dir button press.
124 """
125 self.__dirDialog(self.targetDirEdit)
126
127 @pyqtSlot(str)
128 def on_sourceDirEdit_textChanged(self, dir):
129 """
130 Private slot to handle the source dir text changed.
131
132 If the entered source directory is a subdirectory of the current
133 projects main directory, the target directory path is synchronized.
134 It is assumed, that the user wants to add a bunch of files to
135 the project in place.
136
137 @param dir the text of the source directory line edit (string)
138 """
139 if dir.startswith(self.ppath):
140 self.targetDirEdit.setText(dir)
141
142 def getData(self):
143 """
144 Public slot to retrieve the dialogs data.
145
146 @return tuple of four values (string, string, string, boolean) giving
147 the selected file type, the source and target directory and
148 a flag indicating a recursive add
149 """
150 filetype = \
151 self.filterComboBox.itemData(self.filterComboBox.currentIndex()).toString()
152 return (filetype, self.sourceDirEdit.text(),
153 self.targetDirEdit.text(),
154 self.recursiveCheckBox.isChecked())

eric ide

mercurial