Support verbatim copy of tags (currently texinfo)

Julien LepillerSun Aug 19 11:21:15+0200 2018

a8d9ce6

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

77
import re
88
import os
99
import math
10+
from urllib.parse import unquote
1011
1112
from .manager import ProjectManager
1213
from .spellcheckedit import SpellCheckEdit
14+
from .tagclickedit import TagClickEdit
1315
1416
class ProjectTab(QTabWidget):
1517
    def __init__(self, parent = None):

131133
            text = self.msgid.currentWidget().toPlainText()
132134
            self.msgstr.currentWidget().setText(text)
133135
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+
134144
    def selectItem(self, current, old):
135145
        if current == None:
136146
            return

147157
        if len(data.msgstrs) > 1:
148158
            self.msgid = QTabWidget();
149159
            self.msgstr = QTabWidget();
150-
            singular = QTextEdit()
160+
            singular = TagClickEdit()
151161
            singular.setFont(QFont(font))
152162
            singular.setReadOnly(True)
153163
            singular.setText(data.msgids[0])
154-
            plural = QTextEdit()
164+
            singular.createLinks()
165+
            singular.anchorClicked.connect(self.copyTag)
166+
            plural = TagClickEdit()
155167
            plural.setFont(QFont(font))
156168
            plural.setReadOnly(True)
157169
            plural.setText(data.msgids[1])
170+
            plural.createLinks()
171+
            plural.anchorClicked.connect(self.copyTag)
158172
            self.msgid.addTab(singular, self.tr("Singular"))
159173
            self.msgid.addTab(plural, self.tr("Plural"))
160174
            i = 0

168182
                    focuser = form
169183
                i=i+1
170184
        else:
171-
            self.msgid = QTextEdit()
185+
            self.msgid = TagClickEdit()
172186
            self.msgid.setFont(QFont(font))
173187
            self.msgid.setReadOnly(True)
174188
            self.msgid.setText(data.msgids[0])
189+
            self.msgid.createLinks()
190+
            self.msgid.anchorClicked.connect(self.copyTag)
175191
            self.msgstr = SpellCheckEdit(self.project.lang)
176192
            self.msgstr.setFont(QFont(font))
177193
            self.msgstr.setText(data.msgstrs[0])