src/eric7/Project/NewDirectoryDialog.py

branch
eric7
changeset 10845
bbcad422aea7
child 11090
f5f5f5803935
equal deleted inserted replaced
10844:a7c73526f336 10845:bbcad422aea7
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter the data for a new project sub-directory.
8 """
9
10 from PyQt6.QtWidgets import QCheckBox, QDialog, QDialogButtonBox, QLabel, QVBoxLayout
11
12 from eric7.EricWidgets.EricPathPicker import EricPathPicker, EricPathPickerModes
13
14
15 class NewDirectoryDialog(QDialog):
16 """
17 Class implementing a dialog to enter the data for a new project sub-directory.
18 """
19
20 def __init__(
21 self,
22 title=None,
23 label=None,
24 mode=EricPathPickerModes.DIRECTORY_MODE,
25 strPath=None,
26 defaultDirectory=None,
27 remote=False,
28 parent=None,
29 ):
30 """
31 Constructor
32
33 @param title title of the dialog (defaults to None)
34 @type str (optional)
35 @param label text to be shown above the directory path picker (defaults to None)
36 @type str (optional)
37 @param mode mode of the path picker (defaults to
38 EricPathPickerModes.DIRECTORY_MODE)
39 @type EricPathPickerModes (optional)
40 @param strPath initial path to be shown (defaults to None)
41 @type str (optional)
42 @param defaultDirectory default directory of the path picker selection dialog
43 (defaults to None)
44 @type str (optional)
45 @param remote flag indicating the remote mode (defaults to False)
46 @type bool (optional)
47 @param parent reference to the parent widget (defaults to None)
48 @type QWidget (optional)
49 """
50 super().__init__(parent)
51
52 self.setMinimumWidth(400)
53
54 self.__layout = QVBoxLayout(self)
55
56 self.__label = QLabel(self)
57 self.__label.setWordWrap(True)
58
59 self.__pathPicker = EricPathPicker(self)
60 self.__pathPicker.setMode(mode)
61 self.__addToProjectCheckBox = QCheckBox(self.tr("Add to project"), self)
62 self.__buttonBox = QDialogButtonBox(
63 QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok,
64 self,
65 )
66
67 self.__layout.addWidget(self.__label)
68 self.__layout.addWidget(self.__pathPicker)
69 self.__layout.addWidget(self.__addToProjectCheckBox)
70 self.__layout.addWidget(self.__buttonBox)
71
72 self.setWindowTitle(self.tr("New directory") if title is None else title)
73 self.__label.setText(
74 self.tr("Enter the path of the new directory:") if label is None else label
75 )
76 if strPath:
77 self.__pathPicker.setText(strPath)
78 if defaultDirectory:
79 self.__pathPicker.setDefaultDirectory(defaultDirectory)
80 self.__pathPicker.setRemote(remote)
81
82 self.__buttonBox.accepted.connect(self.accept)
83 self.__buttonBox.rejected.connect(self.reject)
84
85 msh = self.minimumSizeHint()
86 self.resize(max(self.width(), msh.width()), msh.height())
87
88 def getDirectory(self):
89 """
90 Public method to get the entered directory.
91
92 @return tuple containing the entered directory and a flag indicating to add
93 that directory to the project
94 @rtype tuple of (str, bool)
95 """
96 return (
97 self.__pathPicker.text().strip(),
98 self.__addToProjectCheckBox.isChecked(),
99 )

eric ide

mercurial