Move UI elements around
offlate/formats/entry.py
21 | 21 | translation. Some formats handle plurals, and each variant is saved as an | |
22 | 22 | additional string in the same entry. | |
23 | 23 | """ | |
24 | - | def __init__(self, msgids, msgstrs, fuzzy, obsolete): | |
24 | + | def __init__(self, msgids, msgstrs, fuzzy, obsolete, info = []): | |
25 | 25 | """ | |
26 | 26 | Create an entry. | |
27 | 27 | ||
… | |||
29 | 29 | :param strs msgstrs: the set of target language strings (translated) | |
30 | 30 | :param bool fuzzy: whether the entry is fuzzy | |
31 | 31 | :param bool obsolete: whether the entry is obsolete | |
32 | + | :param dicts info: structured information about this entry | |
32 | 33 | """ | |
33 | 34 | self.msgids = msgids | |
34 | 35 | self.msgstrs = msgstrs | |
35 | 36 | self.fuzzy = fuzzy | |
36 | 37 | self.obsolete = obsolete | |
38 | + | self.info = info | |
37 | 39 | ||
38 | 40 | def isTranslated(self): | |
39 | 41 | """ | |
… | |||
59 | 61 | """ | |
60 | 62 | return self.obsolete | |
61 | 63 | ||
64 | + | def getInfo(self): | |
65 | + | """ | |
66 | + | :returns: Structured information about this entry (location, comments, ...) | |
67 | + | :rtype: dicts | |
68 | + | """ | |
69 | + | return self.info | |
70 | + | ||
62 | 71 | def update(self, index, content): | |
63 | 72 | """ | |
64 | 73 | Update the entry by replacing the translation number index with content. |
offlate/ui/editor.py
138 | 138 | self.translationModified.emit() | |
139 | 139 | ||
140 | 140 | def initUI(self): | |
141 | + | layout = QHBoxLayout() | |
142 | + | self.setLayout(layout) | |
143 | + | ||
141 | 144 | vbox = QVBoxLayout() | |
142 | - | self.setLayout(vbox) | |
143 | 145 | model = QStandardItemModel() | |
144 | 146 | self.treeWidget = QTreeWidget() | |
145 | 147 | self.treeWidget.setColumnCount(2) | |
… | |||
164 | 166 | vbox.addWidget(self.openExternal) | |
165 | 167 | ||
166 | 168 | self.updateContent() | |
167 | - | vbox.addWidget(self.treeWidget, 4) | |
168 | - | self.hbox = QHBoxLayout() | |
169 | - | self.hbox.addWidget(self.msgid) | |
170 | - | self.hbox.addLayout(self.buttons) | |
171 | - | self.hbox.addWidget(self.msgstr) | |
172 | - | vbox.addLayout(self.hbox, 1) | |
169 | + | vbox.addWidget(self.treeWidget) | |
170 | + | ||
171 | + | self.entryBox = QVBoxLayout() | |
172 | + | self.entryBox.addStretch(1) | |
173 | + | self.entryBox.addWidget(self.msgid) | |
174 | + | self.entryBox.addLayout(self.buttons) | |
175 | + | self.entryBox.addWidget(self.msgstr) | |
176 | + | layout.addLayout(vbox, 2) | |
177 | + | layout.addLayout(self.entryBox, 1) | |
178 | + | ||
173 | 179 | size = self.treeWidget.size() | |
174 | 180 | self.treeWidget.setColumnWidth(0, size.width()/2) | |
175 | 181 | self.treeWidget.currentItemChanged.connect(self.selectItem) | |
… | |||
247 | 253 | else: | |
248 | 254 | self.msgstr.currentWidget().clearFocus() | |
249 | 255 | data = current.data(0, Qt.UserRole) | |
250 | - | self.hbox.removeWidget(self.msgid) | |
251 | - | self.hbox.removeItem(self.buttons) | |
252 | - | self.hbox.removeWidget(self.msgstr) | |
253 | - | self.msgid.deleteLater() | |
254 | - | self.msgstr.deleteLater() | |
256 | + | ||
257 | + | w = self.entryBox.takeAt(0) | |
258 | + | while w is not None: | |
259 | + | if w.widget() is not None: | |
260 | + | w.widget().deleteLater() | |
261 | + | w = self.entryBox.takeAt(0) | |
255 | 262 | ||
256 | 263 | font = "monospace" if self.monospace else "sans-serif" | |
257 | 264 | focuser = None | |
… | |||
343 | 350 | self.msgstr.setPlainText(data.msgstrs[0]) | |
344 | 351 | self.msgstr.textChanged.connect(self.modify) | |
345 | 352 | focuser = self.msgstr | |
346 | - | self.hbox.addWidget(self.msgid) | |
347 | - | self.hbox.addLayout(self.buttons) | |
348 | - | self.hbox.addWidget(self.msgstr) | |
353 | + | ||
354 | + | for info in data.getInfo(): | |
355 | + | self.entryBox.addWidget(self.getInfoWidget(info)) | |
356 | + | ||
357 | + | self.entryBox.addStretch(1) | |
358 | + | ||
359 | + | self.entryBox.addWidget(self.msgid) | |
360 | + | self.entryBox.addLayout(self.buttons) | |
361 | + | self.entryBox.addWidget(self.msgstr) | |
349 | 362 | focuser.setFocus() | |
350 | 363 | ||
364 | + | def getInfoWidget(self, info): | |
365 | + | label = QLabel() | |
366 | + | label.setWordWrap(True) | |
367 | + | if info['type'] == 'location': | |
368 | + | label.setText(self.tr('<b>location</b>: {0} line {1}'.format(info['file'], info['line']))) | |
369 | + | return label | |
370 | + | ||
351 | 371 | def modify(self): | |
352 | 372 | item = self.treeWidget.currentItem() | |
353 | 373 | data = item.data(0, Qt.UserRole) |