how to edit formatted text html python

Solutions on MaxInterview for how to edit formatted text html python by the best coders in the world

showing results for - "how to edit formatted text html python"
Vinnie
02 Jul 2019
1class TextEdit(QTextEdit):
2
3    def canInsertFromMimeData(self, source):
4
5        if source.hasImage():
6            return True
7        else:
8            return super(TextEdit, self).canInsertFromMimeData(source)
9
10    def insertFromMimeData(self, source):
11
12        cursor = self.textCursor()
13        document = self.document()
14
15        if source.hasUrls():
16
17            for u in source.urls():
18                file_ext = splitext(str(u.toLocalFile()))
19                if u.isLocalFile() and file_ext in IMAGE_EXTENSIONS:
20                    image = QImage(u.toLocalFile())
21                    document.addResource(QTextDocument.ImageResource, u, image)
22                    cursor.insertImage(u.toLocalFile())
23
24                else:
25                    # If we hit a non-image or non-local URL break the loop and fall out
26                    # to the super call & let Qt handle it
27                    break
28
29            else:
30                # If all were valid images, finish here.
31                return
32
33
34        elif source.hasImage():
35            image = source.imageData()
36            uuid = hexuuid()
37            document.addResource(QTextDocument.ImageResource, uuid, image)
38            cursor.insertImage(uuid)
39            return
40
41        super(TextEdit, self).insertFromMimeData(source)
42