eric7/Project/AddDirectoryDialog.py

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

eric ide

mercurial