Support verbatim copy of tags (currently texinfo)
offlate/tagclickedit.py unknown status 1
| 1 | + | from PyQt5.QtWidgets import * | |
| 2 | + | from PyQt5.QtGui import * | |
| 3 | + | from PyQt5.QtCore import * | |
| 4 | + | ||
| 5 | + | import re | |
| 6 | + | import sys | |
| 7 | + | ||
| 8 | + | class TagClickEdit(QTextBrowser): | |
| 9 | + | def __init__(self, *args): | |
| 10 | + | QTextBrowser.__init__(self, *args) | |
| 11 | + | ||
| 12 | + | def createLinks(self): | |
| 13 | + | text = self.toHtml() | |
| 14 | + | for word_object in re.finditer(r'@[a-z]+{[^}]*}', text): | |
| 15 | + | rep = word_object.string[word_object.span()[0] : word_object.span()[1]] | |
| 16 | + | text = text.replace(rep, '<a href="#' + rep + '">' + rep + '</a>') | |
| 17 | + | self.setHtml(text) | |
| 18 | + | ||
| 19 | + | if __name__ == '__main__': | |
| 20 | + | app = QApplication(sys.argv) | |
| 21 | + | w = TagClickEdit() | |
| 22 | + | w.setText("GNU@tie{}Hello provides the @command{hello} command.") | |
| 23 | + | w.createLinks() | |
| 24 | + | w.show() | |
| 25 | + | sys.exit(app.exec_()) |
offlate/window.py
| 7 | 7 | import re | |
| 8 | 8 | import os | |
| 9 | 9 | import math | |
| 10 | + | from urllib.parse import unquote | |
| 10 | 11 | ||
| 11 | 12 | from .manager import ProjectManager | |
| 12 | 13 | from .spellcheckedit import SpellCheckEdit | |
| 14 | + | from .tagclickedit import TagClickEdit | |
| 13 | 15 | ||
| 14 | 16 | class ProjectTab(QTabWidget): | |
| 15 | 17 | def __init__(self, parent = None): | |
… | |||
| 131 | 133 | text = self.msgid.currentWidget().toPlainText() | |
| 132 | 134 | self.msgstr.currentWidget().setText(text) | |
| 133 | 135 | ||
| 136 | + | def copyTag(self, tag): | |
| 137 | + | tag = tag.toDisplayString()[1:] | |
| 138 | + | tag = unquote(tag) | |
| 139 | + | if self.msgstr.__class__.__name__ == "SpellCheckEdit": | |
| 140 | + | self.msgstr.insertPlainText(tag) | |
| 141 | + | else: | |
| 142 | + | self.msgstr.currentWidget.insertPlainText(tag) | |
| 143 | + | ||
| 134 | 144 | def selectItem(self, current, old): | |
| 135 | 145 | if current == None: | |
| 136 | 146 | return | |
… | |||
| 147 | 157 | if len(data.msgstrs) > 1: | |
| 148 | 158 | self.msgid = QTabWidget(); | |
| 149 | 159 | self.msgstr = QTabWidget(); | |
| 150 | - | singular = QTextEdit() | |
| 160 | + | singular = TagClickEdit() | |
| 151 | 161 | singular.setFont(QFont(font)) | |
| 152 | 162 | singular.setReadOnly(True) | |
| 153 | 163 | singular.setText(data.msgids[0]) | |
| 154 | - | plural = QTextEdit() | |
| 164 | + | singular.createLinks() | |
| 165 | + | singular.anchorClicked.connect(self.copyTag) | |
| 166 | + | plural = TagClickEdit() | |
| 155 | 167 | plural.setFont(QFont(font)) | |
| 156 | 168 | plural.setReadOnly(True) | |
| 157 | 169 | plural.setText(data.msgids[1]) | |
| 170 | + | plural.createLinks() | |
| 171 | + | plural.anchorClicked.connect(self.copyTag) | |
| 158 | 172 | self.msgid.addTab(singular, self.tr("Singular")) | |
| 159 | 173 | self.msgid.addTab(plural, self.tr("Plural")) | |
| 160 | 174 | i = 0 | |
… | |||
| 168 | 182 | focuser = form | |
| 169 | 183 | i=i+1 | |
| 170 | 184 | else: | |
| 171 | - | self.msgid = QTextEdit() | |
| 185 | + | self.msgid = TagClickEdit() | |
| 172 | 186 | self.msgid.setFont(QFont(font)) | |
| 173 | 187 | self.msgid.setReadOnly(True) | |
| 174 | 188 | self.msgid.setText(data.msgids[0]) | |
| 189 | + | self.msgid.createLinks() | |
| 190 | + | self.msgid.anchorClicked.connect(self.copyTag) | |
| 175 | 191 | self.msgstr = SpellCheckEdit(self.project.lang) | |
| 176 | 192 | self.msgstr.setFont(QFont(font)) | |
| 177 | 193 | self.msgstr.setText(data.msgstrs[0]) | |