12 import os |
12 import os |
13 |
13 |
14 from PyQt5.QtCore import pyqtSlot |
14 from PyQt5.QtCore import pyqtSlot |
15 from PyQt5.QtWidgets import QListWidgetItem, QDialog, QDialogButtonBox |
15 from PyQt5.QtWidgets import QListWidgetItem, QDialog, QDialogButtonBox |
16 |
16 |
17 from E5Gui.E5Completers import E5FileCompleter, E5DirCompleter |
17 from E5Gui.E5Completers import E5FileCompleter |
18 from E5Gui import E5FileDialog |
18 from E5Gui import E5FileDialog |
|
19 from E5Gui.E5PathPicker import E5PathPickerModes |
19 |
20 |
20 from .Ui_TranslationPropertiesDialog import Ui_TranslationPropertiesDialog |
21 from .Ui_TranslationPropertiesDialog import Ui_TranslationPropertiesDialog |
21 |
22 |
22 import Utilities |
23 import Utilities |
23 import UI.PixmapCache |
|
24 |
24 |
25 |
25 |
26 class TranslationPropertiesDialog(QDialog, Ui_TranslationPropertiesDialog): |
26 class TranslationPropertiesDialog(QDialog, Ui_TranslationPropertiesDialog): |
27 """ |
27 """ |
28 Class implementing the Translations Properties dialog. |
28 Class implementing the Translations Properties dialog. |
36 @param parent parent widget of this dialog (QWidget) |
36 @param parent parent widget of this dialog (QWidget) |
37 """ |
37 """ |
38 super(TranslationPropertiesDialog, self).__init__(parent) |
38 super(TranslationPropertiesDialog, self).__init__(parent) |
39 self.setupUi(self) |
39 self.setupUi(self) |
40 |
40 |
41 self.transBinPathButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
41 self.transPatternPicker.setMode(E5PathPickerModes.SaveFileMode) |
42 self.transPatternButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
42 self.transPatternPicker.setDefaultDirectory(project.ppath) |
|
43 self.transBinPathPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
44 self.transBinPathPicker.setDefaultDirectory(project.ppath) |
43 |
45 |
44 self.project = project |
46 self.project = project |
45 self.parent = parent |
47 self.parent = parent |
46 |
48 |
47 self.transPatternCompleter = E5FileCompleter(self.transPatternEdit) |
|
48 self.transBinPathCompleter = E5DirCompleter(self.transBinPathEdit) |
|
49 self.exceptionCompleter = E5FileCompleter(self.exceptionEdit) |
49 self.exceptionCompleter = E5FileCompleter(self.exceptionEdit) |
50 |
50 |
51 self.initFilters() |
51 self.initFilters() |
52 if not new: |
52 if not new: |
53 self.initDialog() |
53 self.initDialog() |
73 """ |
73 """ |
74 Public method to initialize the dialogs data. |
74 Public method to initialize the dialogs data. |
75 """ |
75 """ |
76 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
76 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
77 try: |
77 try: |
78 self.transPatternEdit.setText(Utilities.toNativeSeparators( |
78 self.transPatternPicker.setText( |
79 self.project.pdata["TRANSLATIONPATTERN"][0])) |
79 self.project.pdata["TRANSLATIONPATTERN"][0]) |
80 except IndexError: |
80 except IndexError: |
81 pass |
81 pass |
82 try: |
82 try: |
83 self.transBinPathEdit.setText(Utilities.toNativeSeparators( |
83 self.transBinPathPicker.setText( |
84 self.project.pdata["TRANSLATIONSBINPATH"][0])) |
84 self.project.pdata["TRANSLATIONSBINPATH"][0]) |
85 except IndexError: |
85 except IndexError: |
86 pass |
86 pass |
87 self.exceptionsList.clear() |
87 self.exceptionsList.clear() |
88 for texcept in self.project.pdata["TRANSLATIONEXCEPTIONS"]: |
88 for texcept in self.project.pdata["TRANSLATIONEXCEPTIONS"]: |
89 if texcept: |
89 if texcept: |
90 self.exceptionsList.addItem(texcept) |
90 self.exceptionsList.addItem(texcept) |
91 |
91 |
92 @pyqtSlot() |
|
93 def on_transPatternButton_clicked(self): |
|
94 """ |
|
95 Private slot to display a file selection dialog. |
|
96 """ |
|
97 tp = Utilities.fromNativeSeparators(self.transPatternEdit.text()) |
|
98 if "%language%" in tp: |
|
99 tp = tp.split("%language%")[0] |
|
100 if not os.path.isabs(tp): |
|
101 tp = Utilities.fromNativeSeparators( |
|
102 os.path.join(self.project.ppath, tp)) |
|
103 tsfile = E5FileDialog.getOpenFileName( |
|
104 self, |
|
105 self.tr("Select translation file"), |
|
106 tp, |
|
107 "") |
|
108 |
|
109 if tsfile: |
|
110 self.transPatternEdit.setText(self.project.getRelativePath( |
|
111 Utilities.toNativeSeparators(tsfile))) |
|
112 |
|
113 @pyqtSlot(str) |
92 @pyqtSlot(str) |
114 def on_transPatternEdit_textChanged(self, txt): |
93 def on_transPatternPicker_pathSelected(self, path): |
|
94 """ |
|
95 Private slot handling the selection of a translation path. |
|
96 |
|
97 @param path selected path |
|
98 @type str |
|
99 """ |
|
100 self.transPatternPicker.setText(self.project.getRelativePath(path)) |
|
101 |
|
102 @pyqtSlot(str) |
|
103 def on_transPatternPicker_textChanged(self, txt): |
115 """ |
104 """ |
116 Private slot to check the translation pattern for correctness. |
105 Private slot to check the translation pattern for correctness. |
117 |
106 |
118 @param txt text of the transPatternEdit lineedit (string) |
107 @param txt text of the transPatternPicker line edit (string) |
119 """ |
108 """ |
120 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
109 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
121 "%language%" in txt) |
110 "%language%" in txt) |
122 |
111 |
123 @pyqtSlot() |
112 @pyqtSlot(str) |
124 def on_transBinPathButton_clicked(self): |
113 def on_transBinPathPicker_pathSelected(self, path): |
125 """ |
114 """ |
126 Private slot to display a directory selection dialog. |
115 Private slot handling the selection of a binary translations path. |
127 """ |
116 |
128 tbp = Utilities.fromNativeSeparators(self.transBinPathEdit.text()) |
117 @param path selected path |
129 if not os.path.isabs(tbp): |
118 @type str |
130 tbp = Utilities.fromNativeSeparators( |
119 """ |
131 os.path.join(self.project.ppath, tbp)) |
120 self.transBinPathPicker.setText(self.project.getRelativePath(path)) |
132 directory = E5FileDialog.getExistingDirectory( |
|
133 self, |
|
134 self.tr("Select directory for binary translations"), |
|
135 tbp) |
|
136 |
|
137 if directory: |
|
138 self.transBinPathEdit.setText(self.project.getRelativePath( |
|
139 Utilities.toNativeSeparators(directory))) |
|
140 |
121 |
141 @pyqtSlot() |
122 @pyqtSlot() |
142 def on_deleteExceptionButton_clicked(self): |
123 def on_deleteExceptionButton_clicked(self): |
143 """ |
124 """ |
144 Private slot to delete the currently selected entry of the listwidget. |
125 Private slot to delete the currently selected entry of the listwidget. |
215 |
196 |
216 def storeData(self): |
197 def storeData(self): |
217 """ |
198 """ |
218 Public method to store the entered/modified data. |
199 Public method to store the entered/modified data. |
219 """ |
200 """ |
220 tp = Utilities.toNativeSeparators(self.transPatternEdit.text()) |
201 tp = self.transPatternPicker.text() |
221 if tp: |
202 if tp: |
222 tp = self.project.getRelativePath(tp) |
203 tp = self.project.getRelativePath(tp) |
223 self.project.pdata["TRANSLATIONPATTERN"] = [tp] |
204 self.project.pdata["TRANSLATIONPATTERN"] = [tp] |
224 self.project.translationsRoot = tp.split("%language%")[0] |
205 self.project.translationsRoot = tp.split("%language%")[0] |
225 else: |
206 else: |
226 self.project.pdata["TRANSLATIONPATTERN"] = [] |
207 self.project.pdata["TRANSLATIONPATTERN"] = [] |
227 tp = Utilities.toNativeSeparators(self.transBinPathEdit.text()) |
208 tp = self.transBinPathPicker.text() |
228 if tp: |
209 if tp: |
229 tp = self.project.getRelativePath(tp) |
210 tp = self.project.getRelativePath(tp) |
230 self.project.pdata["TRANSLATIONSBINPATH"] = [tp] |
211 self.project.pdata["TRANSLATIONSBINPATH"] = [tp] |
231 else: |
212 else: |
232 self.project.pdata["TRANSLATIONSBINPATH"] = [] |
213 self.project.pdata["TRANSLATIONSBINPATH"] = [] |