Helpviewer/FeaturePermissionBar.py

changeset 4353
cff7e27fb7b8
parent 4332
64034d85c709
equal deleted inserted replaced
4352:86f7a3344d38 4353:cff7e27fb7b8
7 Module implementing the feature permission bar widget. 7 Module implementing the feature permission bar widget.
8 """ 8 """
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 from PyQt5.QtCore import pyqtSignal, QPropertyAnimation, QByteArray, \ 12 from PyQt5.QtCore import pyqtSignal
13 QEasingCurve, QPoint 13 from PyQt5.QtWidgets import QLabel, QHBoxLayout, QPushButton
14 from PyQt5.QtWidgets import QWidget, QLabel, QHBoxLayout, QPushButton
15 from PyQt5.QtWebKitWidgets import QWebFrame, QWebPage 14 from PyQt5.QtWebKitWidgets import QWebFrame, QWebPage
15
16 from E5Gui.E5AnimatedWidget import E5AnimatedWidget
16 17
17 import UI.PixmapCache 18 import UI.PixmapCache
18 19
19 20
20 class FeaturePermissionBar(QWidget): 21 class FeaturePermissionBar(E5AnimatedWidget):
21 """ 22 """
22 Class implementing the feature permission bar widget. 23 Class implementing the feature permission bar widget.
23 """ 24 """
24 featurePermissionProvided = pyqtSignal(QWebFrame, QWebPage.Feature, 25 featurePermissionProvided = pyqtSignal(QWebFrame, QWebPage.Feature,
25 QWebPage.PermissionPolicy) 26 QWebPage.PermissionPolicy)
26 27
27 DefaultHeight = 30 28 DefaultHeight = 30
28 29
29 def __init__(self, view): 30 def __init__(self, view, frame, feature):
30 """ 31 """
31 Constructor 32 Constructor
32 33
33 @param view reference to the web view 34 @param view reference to the web view
34 @type QWebView 35 @type QWebView
36 @param frame frame sending the request
37 @type QWebFrame
38 @param feature requested feature
39 @type QWebPage.Feature
35 """ 40 """
36 super(FeaturePermissionBar, self).__init__(view) 41 super(FeaturePermissionBar, self).__init__(parent=view)
37 42
38 self.__messageLabel = QLabel(self) 43 self.__messageLabel = QLabel(self)
39 44
40 self.__frame = None 45 self.__frame = frame
41 self.__feature = None 46 self.__feature = feature
42 47
43 self.__permissionFeatureTexts = { 48 self.__permissionFeatureTexts = {
44 QWebPage.Notifications: 49 QWebPage.Notifications:
45 self.tr("{0} wants to use desktop notifications."), 50 self.tr("{0} wants to use desktop notifications."),
46 QWebPage.Geolocation: 51 QWebPage.Geolocation:
61 self.__denyButton.clicked.connect(self.__permissionDenied) 66 self.__denyButton.clicked.connect(self.__permissionDenied)
62 self.__discardButton.clicked.connect(self.__permissionUnknown) 67 self.__discardButton.clicked.connect(self.__permissionUnknown)
63 self.__layout.addWidget(self.__allowButton) 68 self.__layout.addWidget(self.__allowButton)
64 self.__layout.addWidget(self.__denyButton) 69 self.__layout.addWidget(self.__denyButton)
65 self.__layout.addWidget(self.__discardButton) 70 self.__layout.addWidget(self.__discardButton)
66 self.setGeometry(0, -self.DefaultHeight, view.width(),
67 self.DefaultHeight)
68
69 def requestPermission(self, frame, feature):
70 """
71 Public method to ask the user for a permission.
72
73 @param frame frame sending the request
74 @type QWebFrame
75 @param feature requested feature
76 @type QWebPage.Feature
77 """
78 self.__frame = frame
79 self.__feature = feature
80 71
81 try: 72 try:
82 self.__messageLabel.setText( 73 self.__messageLabel.setText(
83 self.__permissionFeatureTexts[self.__feature].format( 74 self.__permissionFeatureTexts[self.__feature].format(
84 self.__frame.securityOrigin().host())) 75 self.__frame.securityOrigin().host()))
85 except KeyError: 76 except KeyError:
86 self.__messageLabel.setText( 77 self.__messageLabel.setText(
87 self.tr("{0} wants to use an unknown feature.").format( 78 self.tr("{0} wants to use an unknown feature.").format(
88 self.__frame.securityOrigin().host())) 79 self.__frame.securityOrigin().host()))
89 self.show()
90 80
91 self.__animation = QPropertyAnimation(self) 81 self.resize(view.width(), self.height())
92 self.__animation.setTargetObject(self) 82 self.startAnimation()
93 self.__animation.setPropertyName(QByteArray(b"pos"))
94 self.__animation.setDuration(300)
95 self.__animation.setStartValue(self.pos())
96 self.__animation.setEndValue(QPoint(0, 0))
97 self.__animation.setEasingCurve(QEasingCurve.InOutQuad)
98 self.__animation.start(QPropertyAnimation.DeleteWhenStopped)
99 83
100 def __permissionDenied(self): 84 def __permissionDenied(self):
101 """ 85 """
102 Private slot handling the user pressing the deny button. 86 Private slot handling the user pressing the deny button.
103 """ 87 """
104 self.featurePermissionProvided.emit(self.__frame, self.__feature, 88 self.featurePermissionProvided.emit(self.__frame, self.__feature,
105 QWebPage.PermissionDeniedByUser) 89 QWebPage.PermissionDeniedByUser)
90 self.hide()
106 91
107 def __permissionGranted(self): 92 def __permissionGranted(self):
108 """ 93 """
109 Private slot handling the user pressing the allow button. 94 Private slot handling the user pressing the allow button.
110 """ 95 """
111 self.featurePermissionProvided.emit(self.__frame, self.__feature, 96 self.featurePermissionProvided.emit(self.__frame, self.__feature,
112 QWebPage.PermissionGrantedByUser) 97 QWebPage.PermissionGrantedByUser)
98 self.hide()
113 99
114 def __permissionUnknown(self): 100 def __permissionUnknown(self):
115 """ 101 """
116 Private slot handling the user closing the dialog without. 102 Private slot handling the user closing the dialog without.
117 """ 103 """
118 self.featurePermissionProvided.emit(self.__frame, self.__feature, 104 self.featurePermissionProvided.emit(self.__frame, self.__feature,
119 QWebPage.PermissionUnknown) 105 QWebPage.PermissionUnknown)
106 self.hide()

eric ide

mercurial