WebBrowser/PageScreenDialog.py

changeset 6155
ae44225e7e7c
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
equal deleted inserted replaced
6154:11ea3d31937a 6155:ae44225e7e7c
20 20
21 class PageScreenDialog(QDialog, Ui_PageScreenDialog): 21 class PageScreenDialog(QDialog, Ui_PageScreenDialog):
22 """ 22 """
23 Class implementing a dialog to save a screenshot of a web page. 23 Class implementing a dialog to save a screenshot of a web page.
24 """ 24 """
25 def __init__(self, view, visibleOnly=False, parent=None): 25 def __init__(self, view, parent=None):
26 """ 26 """
27 Constructor 27 Constructor
28 28
29 @param view reference to the web view containing the page to be saved 29 @param view reference to the web view containing the page to be saved
30 (WebBrowserView) 30 (WebBrowserView)
31 @param visibleOnly flag indicating to just save the visible part
32 of the page (boolean)
33 @param parent reference to the parent widget (QWidget) 31 @param parent reference to the parent widget (QWidget)
34 """ 32 """
35 super(PageScreenDialog, self).__init__(parent) 33 super(PageScreenDialog, self).__init__(parent)
36 self.setupUi(self) 34 self.setupUi(self)
37 self.setWindowFlags(Qt.Window) 35 self.setWindowFlags(Qt.Window)
38 36
39 self.__view = view 37 self.__view = view
40 self.__createPixmap(visibleOnly) 38 self.__createPixmap()
41 self.pageScreenLabel.setPixmap(self.__pagePixmap) 39 self.pageScreenLabel.setPixmap(self.__pagePixmap)
42 40
43 def __createPixmap(self, visibleOnly): 41 def __createPixmap(self):
44 """ 42 """
45 Private slot to create a pixmap of the associated view's page. 43 Private slot to create a pixmap of the associated view's page.
46
47 @param visibleOnly flag indicating to just save the visible part
48 of the page (boolean)
49 """ 44 """
50 res = self.__view.page().execJavaScript( 45 res = self.__view.page().execJavaScript(
51 "(function() {" 46 "(function() {"
52 "var res = {" 47 "var res = {"
53 " width: 0," 48 " width: 0,"
57 "res.height = document.body.scrollHeight;" 52 "res.height = document.body.scrollHeight;"
58 "return res;" 53 "return res;"
59 "})()" 54 "})()"
60 ) 55 )
61 if res is not None: 56 if res is not None:
62 if visibleOnly: 57 image = QImage(QSize(res["width"], self.__view.height()),
63 image = QImage(QSize(res["width"], self.__view.height()), 58 QImage.Format_ARGB32)
64 QImage.Format_ARGB32) 59 painter = QPainter(image)
65 painter = QPainter(image) 60 self.__view.render(painter)
66 self.__view.render(painter) 61 painter.end()
67 painter.end()
68 else:
69 # TODO: once QWebEngineView supports this
70 image = QImage(QSize(res["width"], self.__view.height()),
71 QImage.Format_ARGB32)
72 painter = QPainter(image)
73 self.__view.render(painter)
74 painter.end()
75 62
76 self.__pagePixmap = QPixmap.fromImage(image) 63 self.__pagePixmap = QPixmap.fromImage(image)
77 64
78 def __savePageScreen(self): 65 def __savePageScreen(self):
79 """ 66 """

eric ide

mercurial