eric7/HelpViewer/HelpViewerImpl_qtb.py

branch
eric7
changeset 8680
85503ff2fce9
parent 8679
fd172973428e
child 8681
6285e8374d99
equal deleted inserted replaced
8679:fd172973428e 8680:85503ff2fce9
5 5
6 """ 6 """
7 Module implementing the QTextBrowser based help viewer class. 7 Module implementing the QTextBrowser based help viewer class.
8 """ 8 """
9 9
10 from PyQt6.QtCore import Qt, QByteArray, QUrl
11 from PyQt6.QtGui import QDesktopServices, QImage
10 from PyQt6.QtWidgets import QTextBrowser 12 from PyQt6.QtWidgets import QTextBrowser
11 13
12 from .HelpViewerImpl import HelpViewerImpl 14 from .HelpViewerImpl import HelpViewerImpl
13 15
14 16
15 class HelpViewerImpl_qtb(QTextBrowser, HelpViewerImpl): 17 class HelpViewerImpl_qtb(HelpViewerImpl, QTextBrowser):
16 """ 18 """
17 Class implementing the QTextBrowser based help viewer class. 19 Class implementing the QTextBrowser based help viewer class.
18 """ 20 """
19 def __init__(self, parent): 21 def __init__(self, engine, parent=None):
20 """ 22 """
21 Constructor 23 Constructor
22 24
25 @param engine reference to the help engine
26 @type QHelpEngine
23 @param parent reference to the parent widget 27 @param parent reference to the parent widget
24 @type QWidget 28 @type QWidget
25 """ 29 """
26 super().__init__(parent) 30 QTextBrowser.__init__(self, parent=parent)
27 # HelpViewerImpl.__init__(self) 31 HelpViewerImpl.__init__(self, engine)
32
33 self.sourceChanged.connect(self.titleChanged)
34
35 def setUrl(self, url):
36 """
37 Public method to set the URL of the document to be shown.
38
39 @param url source of the document
40 @type QUrl
41 """
42 self.setSource(url)
43
44 def doSetSource(self, url, type):
45 """
46 Public method to load the data and show it.
47
48 @param url DESCRIPTION
49 @type TYPE
50 @param type DESCRIPTION
51 @type TYPE
52 """
53 data = self.getData(url)
54 if data is None:
55 QDesktopServices.openUrl(url)
56 return
57
58 if url != QUrl("about:blank"):
59 super().doSetSource(url, type)
60
61 self.setHtml(data)
62 self.sourceChanged.emit(url)
63 self.loadFinished.emit(True)
64
65 def title(self):
66 """
67 Public method get the page title.
68
69 @return page title
70 @rtype str
71 """
72 return self.documentTitle()
73
74 def loadResource(self, type_, name):
75 """
76 Public method to load data of the specified type from the resource with
77 the given name.
78
79 @param type_ resource type
80 @type int
81 @param name resource name
82 @type QUrl
83 """
84 ba = QByteArray()
85
86 if type_ < 4: # QTextDocument.ResourceType.MarkdownResource
87 url = self._engine.findFile(name)
88 ba = self._engine.fileData(url)
89 if url.toString().lower().endswith(".svg"):
90 image = QImage()
91 image.loadFromData(ba, "svg")
92 if not image.isNull():
93 return image
94
95 return ba
96
97 def mousePressEvent(self, evt):
98 """
99 Protected method called by a mouse press event.
100
101 @param evt reference to the mouse event
102 @type QMouseEvent
103 """
104 if evt.button() == Qt.MouseButton.XButton1:
105 self.backward()
106 elif evt.button() == Qt.MouseButton.XButton2:
107 self.forward()
108 else:
109 super().mousePressEvent(evt)
110
111 def gotoHistory(self, index):
112 """
113 Public method to step through the history.
114
115 @param index history index (<0 backward, >0 forward)
116 @type int
117 """
118 if index < 0:
119 # backward
120 for ind in range(-index):
121 self.backward()
122 else:
123 # forward
124 for ind in range(index):
125 self.forward()

eric ide

mercurial