eric6/Project/AddDirectoryDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2002 - 2019 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 __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtWidgets import QDialog
14
15 from E5Gui.E5PathPicker import E5PathPickerModes
16
17 from .Ui_AddDirectoryDialog import Ui_AddDirectoryDialog
18
19
20 class AddDirectoryDialog(QDialog, Ui_AddDirectoryDialog):
21 """
22 Class implementing a dialog to add files of a directory to the project.
23 """
24 def __init__(self, pro, fileTypeFilter='source', parent=None, name=None,
25 startdir=None):
26 """
27 Constructor
28
29 @param pro reference to the project object
30 @param fileTypeFilter file type filter (string)
31 @param parent parent widget of this dialog (QWidget)
32 @param name name of this dialog (string)
33 @param startdir start directory for the selection dialog
34 """
35 super(AddDirectoryDialog, self).__init__(parent)
36 if name:
37 self.setObjectName(name)
38 self.setupUi(self)
39
40 self.sourceDirPicker.setMode(E5PathPickerModes.DirectoryMode)
41 self.sourceDirPicker.setDefaultDirectory(startdir)
42 self.targetDirPicker.setMode(E5PathPickerModes.DirectoryMode)
43 self.targetDirPicker.setDefaultDirectory(startdir)
44
45 self.ppath = pro.ppath
46 self.targetDirPicker.setText(self.ppath)
47 self.on_filterComboBox_highlighted('(*.py)')
48 # enable all dialog elements
49 if fileTypeFilter == 'source': # it is a source file
50 self.filterComboBox.addItem(
51 self.tr("Source Files"), "SOURCES")
52 elif fileTypeFilter == 'form':
53 self.filterComboBox.addItem(
54 self.tr("Forms Files"), "FORMS")
55 elif fileTypeFilter == 'resource':
56 self.filterComboBox.addItem(
57 self.tr("Resource Files"), "RESOURCES")
58 elif fileTypeFilter == 'interface':
59 self.filterComboBox.addItem(
60 self.tr("Interface Files"), "INTERFACES")
61 elif fileTypeFilter == 'protocol':
62 self.filterComboBox.addItem(
63 self.tr("Protocol Files"), "PROTOCOLS")
64 elif fileTypeFilter == 'others':
65 self.filterComboBox.addItem(
66 self.tr("Other Files (*)"), "OTHERS")
67 self.on_filterComboBox_highlighted('(*)')
68 else:
69 self.filterComboBox.addItem(
70 self.tr("Source Files"), "SOURCES")
71 self.filterComboBox.addItem(
72 self.tr("Forms Files"), "FORMS")
73 self.filterComboBox.addItem(
74 self.tr("Resource Files"), "RESOURCES")
75 self.filterComboBox.addItem(
76 self.tr("Interface Files"), "INTERFACES")
77 self.filterComboBox.addItem(
78 self.tr("Protocol Files"), "PROTOCOLS")
79 self.filterComboBox.addItem(
80 self.tr("Other Files (*)"), "OTHERS")
81 self.filterComboBox.setCurrentIndex(0)
82
83 msh = self.minimumSizeHint()
84 self.resize(max(self.width(), msh.width()), msh.height())
85
86 @pyqtSlot(str)
87 def on_filterComboBox_highlighted(self, fileType):
88 """
89 Private slot to handle the selection of a file type.
90
91 @param fileType the selected file type (string)
92 """
93 if fileType.endswith('(*)'):
94 self.targetDirLabel.setEnabled(False)
95 self.targetDirPicker.setEnabled(False)
96 self.recursiveCheckBox.setEnabled(False)
97 else:
98 self.targetDirLabel.setEnabled(True)
99 self.targetDirPicker.setEnabled(True)
100 self.recursiveCheckBox.setEnabled(True)
101
102 @pyqtSlot(str)
103 def on_sourceDirPicker_textChanged(self, directory):
104 """
105 Private slot to handle the source directory text changed.
106
107 If the entered source directory is a subdirectory of the current
108 projects main directory, the target directory path is synchronized.
109 It is assumed, that the user wants to add a bunch of files to
110 the project in place.
111
112 @param directory the text of the source directory line edit (string)
113 """
114 if directory.startswith(self.ppath):
115 self.targetDirPicker.setText(directory)
116
117 def getData(self):
118 """
119 Public slot to retrieve the dialogs data.
120
121 @return tuple of four values (string, string, string, boolean) giving
122 the selected file type, the source and target directory and
123 a flag indicating a recursive add
124 """
125 filetype = \
126 self.filterComboBox.itemData(self.filterComboBox.currentIndex())
127 return (
128 filetype,
129 self.sourceDirPicker.text(),
130 self.targetDirPicker.text(),
131 self.recursiveCheckBox.isChecked())

eric ide

mercurial