15 class EricPathPickerDialog(QDialog): |
15 class EricPathPickerDialog(QDialog): |
16 """ |
16 """ |
17 Class implementing a dialog to enter a file system path using a file |
17 Class implementing a dialog to enter a file system path using a file |
18 picker. |
18 picker. |
19 """ |
19 """ |
|
20 |
20 def __init__(self, parent=None): |
21 def __init__(self, parent=None): |
21 """ |
22 """ |
22 Constructor |
23 Constructor |
23 |
24 |
24 @param parent reference to the parent widget |
25 @param parent reference to the parent widget |
25 @type QWidget |
26 @type QWidget |
26 """ |
27 """ |
27 super().__init__(parent) |
28 super().__init__(parent) |
28 |
29 |
29 self.setMinimumWidth(400) |
30 self.setMinimumWidth(400) |
30 |
31 |
31 self.__layout = QVBoxLayout(self) |
32 self.__layout = QVBoxLayout(self) |
32 |
33 |
33 self.__label = QLabel(self) |
34 self.__label = QLabel(self) |
34 self.__label.setWordWrap(True) |
35 self.__label.setWordWrap(True) |
35 |
36 |
36 self.__pathPicker = EricPathPicker(self) |
37 self.__pathPicker = EricPathPicker(self) |
37 self.__buttonBox = QDialogButtonBox( |
38 self.__buttonBox = QDialogButtonBox( |
38 QDialogButtonBox.StandardButton.Cancel | |
39 QDialogButtonBox.StandardButton.Cancel | QDialogButtonBox.StandardButton.Ok, |
39 QDialogButtonBox.StandardButton.Ok, self) |
40 self, |
40 |
41 ) |
|
42 |
41 self.__layout.addWidget(self.__label) |
43 self.__layout.addWidget(self.__label) |
42 self.__layout.addWidget(self.__pathPicker) |
44 self.__layout.addWidget(self.__pathPicker) |
43 self.__layout.addWidget(self.__buttonBox) |
45 self.__layout.addWidget(self.__buttonBox) |
44 |
46 |
45 self.__buttonBox.accepted.connect(self.accept) |
47 self.__buttonBox.accepted.connect(self.accept) |
46 self.__buttonBox.rejected.connect(self.reject) |
48 self.__buttonBox.rejected.connect(self.reject) |
47 |
49 |
48 def setLabelText(self, text): |
50 def setLabelText(self, text): |
49 """ |
51 """ |
50 Public method to set the label text. |
52 Public method to set the label text. |
51 |
53 |
52 @param text label text |
54 @param text label text |
53 @type str |
55 @type str |
54 """ |
56 """ |
55 self.__label.setText(text) |
57 self.__label.setText(text) |
56 |
58 |
57 def setTitle(self, title): |
59 def setTitle(self, title): |
58 """ |
60 """ |
59 Public method to set the window title. |
61 Public method to set the window title. |
60 |
62 |
61 @param title window title |
63 @param title window title |
62 @type str |
64 @type str |
63 """ |
65 """ |
64 self.setWindowTitle(title) |
66 self.setWindowTitle(title) |
65 self.__pathPicker.setWindowTitle(title) |
67 self.__pathPicker.setWindowTitle(title) |
66 |
68 |
67 def setPickerMode(self, mode): |
69 def setPickerMode(self, mode): |
68 """ |
70 """ |
69 Public method to set the mode of the path picker. |
71 Public method to set the mode of the path picker. |
70 |
72 |
71 @param mode picker mode |
73 @param mode picker mode |
72 @type EricPathPickerModes |
74 @type EricPathPickerModes |
73 """ |
75 """ |
74 self.__pathPicker.setMode(mode) |
76 self.__pathPicker.setMode(mode) |
75 |
77 |
76 def setPickerPath(self, path): |
78 def setPickerPath(self, path): |
77 """ |
79 """ |
78 Public method to set the path of the path picker. |
80 Public method to set the path of the path picker. |
79 |
81 |
80 @param path path to be set |
82 @param path path to be set |
81 @type str |
83 @type str |
82 """ |
84 """ |
83 self.__pathPicker.setPath(path) |
85 self.__pathPicker.setPath(path) |
84 |
86 |
85 def setDefaultDirectory(self, directory): |
87 def setDefaultDirectory(self, directory): |
86 """ |
88 """ |
87 Public method to set the default directory of the path picker. |
89 Public method to set the default directory of the path picker. |
88 |
90 |
89 @param directory default directory |
91 @param directory default directory |
90 @type str |
92 @type str |
91 """ |
93 """ |
92 self.__pathPicker.setDefaultDirectory(directory) |
94 self.__pathPicker.setDefaultDirectory(directory) |
93 |
95 |
94 def setPickerFilters(self, filters): |
96 def setPickerFilters(self, filters): |
95 """ |
97 """ |
96 Public method to set the filters of the path picker. |
98 Public method to set the filters of the path picker. |
97 |
99 |
98 Note: Multiple filters must be separated by ';;'. |
100 Note: Multiple filters must be separated by ';;'. |
99 |
101 |
100 @param filters string containing the file filters |
102 @param filters string containing the file filters |
101 @type str |
103 @type str |
102 """ |
104 """ |
103 self.__pathPicker.setFilters(filters) |
105 self.__pathPicker.setFilters(filters) |
104 |
106 |
105 def getPath(self): |
107 def getPath(self): |
106 """ |
108 """ |
107 Public method to get the current path. |
109 Public method to get the current path. |
108 |
110 |
109 @return current path |
111 @return current path |
110 @rtype str |
112 @rtype str |
111 """ |
113 """ |
112 return self.__pathPicker.path() |
114 return self.__pathPicker.path() |
113 |
115 |
114 |
116 |
115 def getPath(parent, title, label, mode=EricPathPickerModes.OPEN_FILE_MODE, |
117 def getPath( |
116 path="", defaultDirectory="", filters=None): |
118 parent, |
|
119 title, |
|
120 label, |
|
121 mode=EricPathPickerModes.OPEN_FILE_MODE, |
|
122 path="", |
|
123 defaultDirectory="", |
|
124 filters=None, |
|
125 ): |
117 """ |
126 """ |
118 Function to get a file or directory path from the user. |
127 Function to get a file or directory path from the user. |
119 |
128 |
120 @param parent reference to the parent widget |
129 @param parent reference to the parent widget |
121 @type QWidget |
130 @type QWidget |
122 @param title title of the dialog |
131 @param title title of the dialog |
123 @type str |
132 @type str |
124 @param label text to be shown above the path picker |
133 @param label text to be shown above the path picker |