23 |
23 |
24 class TranslationPropertiesDialog(QDialog, Ui_TranslationPropertiesDialog): |
24 class TranslationPropertiesDialog(QDialog, Ui_TranslationPropertiesDialog): |
25 """ |
25 """ |
26 Class implementing the Translations Properties dialog. |
26 Class implementing the Translations Properties dialog. |
27 """ |
27 """ |
|
28 |
28 def __init__(self, project, new, parent): |
29 def __init__(self, project, new, parent): |
29 """ |
30 """ |
30 Constructor |
31 Constructor |
31 |
32 |
32 @param project reference to the project object |
33 @param project reference to the project object |
33 @param new flag indicating the generation of a new project |
34 @param new flag indicating the generation of a new project |
34 @param parent parent widget of this dialog (QWidget) |
35 @param parent parent widget of this dialog (QWidget) |
35 """ |
36 """ |
36 super().__init__(parent) |
37 super().__init__(parent) |
37 self.setupUi(self) |
38 self.setupUi(self) |
38 |
39 |
39 self.transPatternPicker.setMode(EricPathPickerModes.SAVE_FILE_MODE) |
40 self.transPatternPicker.setMode(EricPathPickerModes.SAVE_FILE_MODE) |
40 self.transPatternPicker.setDefaultDirectory(project.ppath) |
41 self.transPatternPicker.setDefaultDirectory(project.ppath) |
41 self.transBinPathPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
42 self.transBinPathPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) |
42 self.transBinPathPicker.setDefaultDirectory(project.ppath) |
43 self.transBinPathPicker.setDefaultDirectory(project.ppath) |
43 |
44 |
44 self.project = project |
45 self.project = project |
45 self.parent = parent |
46 self.parent = parent |
46 |
47 |
47 self.exceptionCompleter = EricFileCompleter(self.exceptionEdit) |
48 self.exceptionCompleter = EricFileCompleter(self.exceptionEdit) |
48 |
49 |
49 self.initFilters() |
50 self.initFilters() |
50 if not new: |
51 if not new: |
51 self.initDialog() |
52 self.initDialog() |
52 |
53 |
53 def initFilters(self): |
54 def initFilters(self): |
54 """ |
55 """ |
55 Public method to initialize the filters. |
56 Public method to initialize the filters. |
56 """ |
57 """ |
57 patterns = { |
58 patterns = { |
59 "FORMS": [], |
60 "FORMS": [], |
60 } |
61 } |
61 for pattern, filetype in list(self.project.pdata["FILETYPES"].items()): |
62 for pattern, filetype in list(self.project.pdata["FILETYPES"].items()): |
62 if filetype in patterns: |
63 if filetype in patterns: |
63 patterns[filetype].append(pattern) |
64 patterns[filetype].append(pattern) |
64 self.filters = self.tr("Source Files ({0});;" |
65 self.filters = self.tr("Source Files ({0});;").format( |
65 ).format(" ".join(patterns["SOURCES"])) |
66 " ".join(patterns["SOURCES"]) |
66 self.filters += self.tr("Forms Files ({0});;" |
67 ) |
67 ).format(" ".join(patterns["FORMS"])) |
68 self.filters += self.tr("Forms Files ({0});;").format( |
|
69 " ".join(patterns["FORMS"]) |
|
70 ) |
68 self.filters += self.tr("All Files (*)") |
71 self.filters += self.tr("All Files (*)") |
69 |
72 |
70 def initDialog(self): |
73 def initDialog(self): |
71 """ |
74 """ |
72 Public method to initialize the dialogs data. |
75 Public method to initialize the dialogs data. |
73 """ |
76 """ |
74 self.buttonBox.button( |
77 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
75 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
78 self.transPatternPicker.setText(self.project.pdata["TRANSLATIONPATTERN"]) |
76 self.transPatternPicker.setText( |
79 self.transBinPathPicker.setText(self.project.pdata["TRANSLATIONSBINPATH"]) |
77 self.project.pdata["TRANSLATIONPATTERN"]) |
|
78 self.transBinPathPicker.setText( |
|
79 self.project.pdata["TRANSLATIONSBINPATH"]) |
|
80 self.exceptionsList.clear() |
80 self.exceptionsList.clear() |
81 for texcept in self.project.pdata["TRANSLATIONEXCEPTIONS"]: |
81 for texcept in self.project.pdata["TRANSLATIONEXCEPTIONS"]: |
82 if texcept: |
82 if texcept: |
83 self.exceptionsList.addItem(texcept) |
83 self.exceptionsList.addItem(texcept) |
84 |
84 |
85 @pyqtSlot(str) |
85 @pyqtSlot(str) |
86 def on_transPatternPicker_pathSelected(self, path): |
86 def on_transPatternPicker_pathSelected(self, path): |
87 """ |
87 """ |
88 Private slot handling the selection of a translation path. |
88 Private slot handling the selection of a translation path. |
89 |
89 |
90 @param path selected path |
90 @param path selected path |
91 @type str |
91 @type str |
92 """ |
92 """ |
93 self.transPatternPicker.setText(self.project.getRelativePath(path)) |
93 self.transPatternPicker.setText(self.project.getRelativePath(path)) |
94 |
94 |
95 @pyqtSlot(str) |
95 @pyqtSlot(str) |
96 def on_transPatternPicker_textChanged(self, txt): |
96 def on_transPatternPicker_textChanged(self, txt): |
97 """ |
97 """ |
98 Private slot to check the translation pattern for correctness. |
98 Private slot to check the translation pattern for correctness. |
99 |
99 |
100 @param txt text of the transPatternPicker line edit (string) |
100 @param txt text of the transPatternPicker line edit (string) |
101 """ |
101 """ |
102 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
102 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
103 "%language%" in txt) |
103 "%language%" in txt |
104 |
104 ) |
|
105 |
105 @pyqtSlot(str) |
106 @pyqtSlot(str) |
106 def on_transBinPathPicker_pathSelected(self, path): |
107 def on_transBinPathPicker_pathSelected(self, path): |
107 """ |
108 """ |
108 Private slot handling the selection of a binary translations path. |
109 Private slot handling the selection of a binary translations path. |
109 |
110 |
110 @param path selected path |
111 @param path selected path |
111 @type str |
112 @type str |
112 """ |
113 """ |
113 self.transBinPathPicker.setText(self.project.getRelativePath(path)) |
114 self.transBinPathPicker.setText(self.project.getRelativePath(path)) |
114 |
115 |
115 @pyqtSlot() |
116 @pyqtSlot() |
116 def on_deleteExceptionButton_clicked(self): |
117 def on_deleteExceptionButton_clicked(self): |
117 """ |
118 """ |
118 Private slot to delete the currently selected entry of the listwidget. |
119 Private slot to delete the currently selected entry of the listwidget. |
119 """ |
120 """ |
120 row = self.exceptionsList.currentRow() |
121 row = self.exceptionsList.currentRow() |
121 itm = self.exceptionsList.takeItem(row) |
122 itm = self.exceptionsList.takeItem(row) |
122 del itm |
123 del itm |
123 row = self.exceptionsList.currentRow() |
124 row = self.exceptionsList.currentRow() |
124 self.on_exceptionsList_currentRowChanged(row) |
125 self.on_exceptionsList_currentRowChanged(row) |
125 |
126 |
126 @pyqtSlot() |
127 @pyqtSlot() |
127 def on_addExceptionButton_clicked(self): |
128 def on_addExceptionButton_clicked(self): |
128 """ |
129 """ |
129 Private slot to add the shown exception to the listwidget. |
130 Private slot to add the shown exception to the listwidget. |
130 """ |
131 """ |
131 texcept = self.exceptionEdit.text() |
132 texcept = self.exceptionEdit.text() |
132 texcept = ( |
133 texcept = ( |
133 texcept.replace(self.parent.getPPath() + os.sep, "") |
134 texcept.replace(self.parent.getPPath() + os.sep, "") |
134 if self.project.ppath == '' else |
135 if self.project.ppath == "" |
135 self.project.getRelativePath(texcept) |
136 else self.project.getRelativePath(texcept) |
136 ) |
137 ) |
137 if texcept.endswith(os.sep): |
138 if texcept.endswith(os.sep): |
138 texcept = texcept[:-1] |
139 texcept = texcept[:-1] |
139 if texcept: |
140 if texcept: |
140 QListWidgetItem(texcept, self.exceptionsList) |
141 QListWidgetItem(texcept, self.exceptionsList) |
141 self.exceptionEdit.clear() |
142 self.exceptionEdit.clear() |
142 row = self.exceptionsList.currentRow() |
143 row = self.exceptionsList.currentRow() |
143 self.on_exceptionsList_currentRowChanged(row) |
144 self.on_exceptionsList_currentRowChanged(row) |
144 |
145 |
145 @pyqtSlot() |
146 @pyqtSlot() |
146 def on_exceptFileButton_clicked(self): |
147 def on_exceptFileButton_clicked(self): |
147 """ |
148 """ |
148 Private slot to select a file to exempt from translation. |
149 Private slot to select a file to exempt from translation. |
149 """ |
150 """ |
150 texcept = EricFileDialog.getOpenFileName( |
151 texcept = EricFileDialog.getOpenFileName( |
151 self, |
152 self, |
152 self.tr("Exempt file from translation"), |
153 self.tr("Exempt file from translation"), |
153 self.project.ppath, |
154 self.project.ppath, |
154 self.filters) |
155 self.filters, |
|
156 ) |
155 if texcept: |
157 if texcept: |
156 self.exceptionEdit.setText(Utilities.toNativeSeparators(texcept)) |
158 self.exceptionEdit.setText(Utilities.toNativeSeparators(texcept)) |
157 |
159 |
158 @pyqtSlot() |
160 @pyqtSlot() |
159 def on_exceptDirButton_clicked(self): |
161 def on_exceptDirButton_clicked(self): |
160 """ |
162 """ |
161 Private slot to select a file to exempt from translation. |
163 Private slot to select a file to exempt from translation. |
162 """ |
164 """ |
163 texcept = EricFileDialog.getExistingDirectory( |
165 texcept = EricFileDialog.getExistingDirectory( |
164 self, |
166 self, |
165 self.tr("Exempt directory from translation"), |
167 self.tr("Exempt directory from translation"), |
166 self.project.ppath, |
168 self.project.ppath, |
167 EricFileDialog.ShowDirsOnly) |
169 EricFileDialog.ShowDirsOnly, |
|
170 ) |
168 if texcept: |
171 if texcept: |
169 self.exceptionEdit.setText(Utilities.toNativeSeparators(texcept)) |
172 self.exceptionEdit.setText(Utilities.toNativeSeparators(texcept)) |
170 |
173 |
171 def on_exceptionsList_currentRowChanged(self, row): |
174 def on_exceptionsList_currentRowChanged(self, row): |
172 """ |
175 """ |
173 Private slot to handle the currentRowChanged signal of the exceptions |
176 Private slot to handle the currentRowChanged signal of the exceptions |
174 list. |
177 list. |
175 |
178 |
176 @param row the current row (integer) |
179 @param row the current row (integer) |
177 """ |
180 """ |
178 if row == -1: |
181 if row == -1: |
179 self.deleteExceptionButton.setEnabled(False) |
182 self.deleteExceptionButton.setEnabled(False) |
180 else: |
183 else: |
181 self.deleteExceptionButton.setEnabled(True) |
184 self.deleteExceptionButton.setEnabled(True) |
182 |
185 |
183 def on_exceptionEdit_textChanged(self, txt): |
186 def on_exceptionEdit_textChanged(self, txt): |
184 """ |
187 """ |
185 Private slot to handle the textChanged signal of the exception edit. |
188 Private slot to handle the textChanged signal of the exception edit. |
186 |
189 |
187 @param txt the text of the exception edit (string) |
190 @param txt the text of the exception edit (string) |
188 """ |
191 """ |
189 self.addExceptionButton.setEnabled(txt != "") |
192 self.addExceptionButton.setEnabled(txt != "") |
190 |
193 |
191 def storeData(self): |
194 def storeData(self): |
192 """ |
195 """ |
193 Public method to store the entered/modified data. |
196 Public method to store the entered/modified data. |
194 """ |
197 """ |
195 tp = self.transPatternPicker.text() |
198 tp = self.transPatternPicker.text() |