eric6/Helpviewer/HelpSnap.py

branch
maintenance
changeset 7286
7eb04391adf7
parent 7226
babe80d84a3e
parent 7285
1ff497f33f31
child 7287
1c17f2191bdd
equal deleted inserted replaced
7226:babe80d84a3e 7286:7eb04391adf7
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing functions to generate page previews.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import QSize, Qt
13 from PyQt5.QtGui import QPixmap, QPainter
14 from PyQt5.QtWebKitWidgets import QWebFrame
15
16
17 def renderTabPreview(page, w, h):
18 """
19 Public function to render a pixmap of a page.
20
21 @param page reference to the page to be previewed (QWebPage)
22 @param w width of the preview pixmap (integer)
23 @param h height of the preview pixmap (integer)
24 @return preview pixmap (QPixmap)
25 """
26 oldSize = page.viewportSize()
27 width = page.mainFrame().contentsSize().width()
28 page.setViewportSize(QSize(width, int(width * h / w)))
29 pageImage = __render(page, page.viewportSize().width(),
30 page.viewportSize().height())
31 page.setViewportSize(oldSize)
32 return pageImage.scaled(
33 w, h, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
34
35
36 def __render(page, w, h):
37 """
38 Private function to render a pixmap of given size for a web page.
39
40 @param page reference to the page to be rendered (QWebPage)
41 @param w width of the pixmap (integer)
42 @param h height of the pixmap (integer)
43 @return rendered pixmap (QPixmap)
44 """
45 # create the page image
46 pageImage = QPixmap(w, h)
47 pageImage.fill(Qt.transparent)
48
49 # render it
50 p = QPainter(pageImage)
51 page.mainFrame().render(p, QWebFrame.ContentsLayer)
52 p.end()
53
54 return pageImage

eric ide

mercurial