eric6/WebBrowser/WebBrowserSnap.py

Sun, 14 Apr 2019 15:09:21 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 14 Apr 2019 15:09:21 +0200
changeset 6942
2602857055c5
parent 6645
WebBrowser/WebBrowserSnap.py@ad476851d7e0
child 7229
53054eb5b15a
permissions
-rw-r--r--

Major restructuring of the source tree to get prepared for a setup.py based installation.

# -*- coding: utf-8 -*-

# Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing functions to generate page previews.
"""

from __future__ import unicode_literals

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QPainter


def renderTabPreview(view, w, h):
    """
    Public function to render a pixmap of a page.
    
    @param view reference to the view to be previewed (QWebEngineView)
    @param w width of the preview pixmap (integer)
    @param h height of the preview pixmap (integer)
    @return preview pixmap (QPixmap)
    """
    pageImage = __render(view, view.width(), view.height())
    return pageImage.scaled(
        w, h, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)


def __render(view, w, h):
    """
    Private function to render a pixmap of given size for a web page.
    
    @param view reference to the view to be previewed (QWebEngineView)
    @param w width of the pixmap (integer)
    @param h height of the pixmap (integer)
    @return rendered pixmap (QPixmap)
    """
    # create the page image
    pageImage = QPixmap(w, h)
    pageImage.fill(Qt.transparent)
    
    # render it
    p = QPainter(pageImage)
    view.render(p)
    p.end()
    
    return pageImage

eric ide

mercurial