--- a/src/eric7/WebBrowser/FeaturePermissions/FeaturePermissionsDialog.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/WebBrowser/FeaturePermissions/FeaturePermissionsDialog.py Wed Jul 13 14:55:47 2022 +0200 @@ -8,9 +8,7 @@ """ from PyQt6.QtCore import pyqtSlot, Qt -from PyQt6.QtWidgets import ( - QDialog, QTreeWidgetItem, QTreeWidget, QAbstractItemView -) +from PyQt6.QtWidgets import QDialog, QTreeWidgetItem, QTreeWidget, QAbstractItemView from PyQt6.QtWebEngineCore import QWebEnginePage import UI.PixmapCache @@ -22,10 +20,11 @@ """ Class implementing the feature permission dialog. """ + def __init__(self, featurePermissions, parent=None): """ Constructor - + @param featurePermissions dictionary with remembered feature permissions @type dict of dict of list @@ -34,13 +33,14 @@ """ super().__init__(parent) self.setupUi(self) - + # add the various lists - + self.notifList = QTreeWidget() self.notifList.setAlternatingRowColors(True) self.notifList.setSelectionMode( - QAbstractItemView.SelectionMode.ExtendedSelection) + QAbstractItemView.SelectionMode.ExtendedSelection + ) self.notifList.setRootIsDecorated(False) self.notifList.setItemsExpandable(False) self.notifList.setAllColumnsShowFocus(True) @@ -51,12 +51,12 @@ self.tabWidget.addTab( self.notifList, UI.PixmapCache.getIcon("notification"), - self.tr("Notifications")) - + self.tr("Notifications"), + ) + self.geoList = QTreeWidget() self.geoList.setAlternatingRowColors(True) - self.geoList.setSelectionMode( - QAbstractItemView.SelectionMode.ExtendedSelection) + self.geoList.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection) self.geoList.setRootIsDecorated(False) self.geoList.setItemsExpandable(False) self.geoList.setAllColumnsShowFocus(True) @@ -65,14 +65,12 @@ self.geoList.headerItem().setText(0, self.tr("Host")) self.geoList.headerItem().setText(1, self.tr("Permission")) self.tabWidget.addTab( - self.geoList, - UI.PixmapCache.getIcon("geolocation"), - self.tr("Geolocation")) - + self.geoList, UI.PixmapCache.getIcon("geolocation"), self.tr("Geolocation") + ) + self.micList = QTreeWidget() self.micList.setAlternatingRowColors(True) - self.micList.setSelectionMode( - QAbstractItemView.SelectionMode.ExtendedSelection) + self.micList.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection) self.micList.setRootIsDecorated(False) self.micList.setItemsExpandable(False) self.micList.setAllColumnsShowFocus(True) @@ -81,14 +79,12 @@ self.micList.headerItem().setText(0, self.tr("Host")) self.micList.headerItem().setText(1, self.tr("Permission")) self.tabWidget.addTab( - self.micList, - UI.PixmapCache.getIcon("audiocapture"), - self.tr("Microphone")) - + self.micList, UI.PixmapCache.getIcon("audiocapture"), self.tr("Microphone") + ) + self.camList = QTreeWidget() self.camList.setAlternatingRowColors(True) - self.camList.setSelectionMode( - QAbstractItemView.SelectionMode.ExtendedSelection) + self.camList.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection) self.camList.setRootIsDecorated(False) self.camList.setItemsExpandable(False) self.camList.setAllColumnsShowFocus(True) @@ -97,14 +93,14 @@ self.camList.headerItem().setText(0, self.tr("Host")) self.camList.headerItem().setText(1, self.tr("Permission")) self.tabWidget.addTab( - self.camList, - UI.PixmapCache.getIcon("camera"), - self.tr("Camera")) - + self.camList, UI.PixmapCache.getIcon("camera"), self.tr("Camera") + ) + self.micCamList = QTreeWidget() self.micCamList.setAlternatingRowColors(True) self.micCamList.setSelectionMode( - QAbstractItemView.SelectionMode.ExtendedSelection) + QAbstractItemView.SelectionMode.ExtendedSelection + ) self.micCamList.setRootIsDecorated(False) self.micCamList.setItemsExpandable(False) self.micCamList.setAllColumnsShowFocus(True) @@ -115,12 +111,14 @@ self.tabWidget.addTab( self.micCamList, UI.PixmapCache.getIcon("audio-video"), - self.tr("Microphone && Camera")) - + self.tr("Microphone && Camera"), + ) + self.mouseLockList = QTreeWidget() self.mouseLockList.setAlternatingRowColors(True) self.mouseLockList.setSelectionMode( - QAbstractItemView.SelectionMode.ExtendedSelection) + QAbstractItemView.SelectionMode.ExtendedSelection + ) self.mouseLockList.setRootIsDecorated(False) self.mouseLockList.setItemsExpandable(False) self.mouseLockList.setAllColumnsShowFocus(True) @@ -129,14 +127,14 @@ self.mouseLockList.headerItem().setText(0, self.tr("Host")) self.mouseLockList.headerItem().setText(1, self.tr("Permission")) self.tabWidget.addTab( - self.mouseLockList, - UI.PixmapCache.getIcon("mouse"), - self.tr("Mouse Lock")) - + self.mouseLockList, UI.PixmapCache.getIcon("mouse"), self.tr("Mouse Lock") + ) + self.deskVidList = QTreeWidget() self.deskVidList.setAlternatingRowColors(True) self.deskVidList.setSelectionMode( - QAbstractItemView.SelectionMode.ExtendedSelection) + QAbstractItemView.SelectionMode.ExtendedSelection + ) self.deskVidList.setRootIsDecorated(False) self.deskVidList.setItemsExpandable(False) self.deskVidList.setAllColumnsShowFocus(True) @@ -147,12 +145,14 @@ self.tabWidget.addTab( self.deskVidList, UI.PixmapCache.getIcon("desktopVideoCapture"), - self.tr("Desktop Video")) - + self.tr("Desktop Video"), + ) + self.deskAudVidList = QTreeWidget() self.deskAudVidList.setAlternatingRowColors(True) self.deskAudVidList.setSelectionMode( - QAbstractItemView.SelectionMode.ExtendedSelection) + QAbstractItemView.SelectionMode.ExtendedSelection + ) self.deskAudVidList.setRootIsDecorated(False) self.deskAudVidList.setItemsExpandable(False) self.deskAudVidList.setAllColumnsShowFocus(True) @@ -163,8 +163,9 @@ self.tabWidget.addTab( self.deskAudVidList, UI.PixmapCache.getIcon("desktopAudioVideoCapture"), - self.tr("Desktop Audio && Video")) - + self.tr("Desktop Audio && Video"), + ) + self.setTabOrder(self.tabWidget, self.notifList) self.setTabOrder(self.notifList, self.geoList) self.setTabOrder(self.geoList, self.micList) @@ -175,14 +176,12 @@ self.setTabOrder(self.deskVidList, self.deskAudVidList) self.setTabOrder(self.deskAudVidList, self.removeButton) self.setTabOrder(self.removeButton, self.removeAllButton) - + self.__permissionStrings = { - QWebEnginePage.PermissionPolicy.PermissionGrantedByUser: - self.tr("Allow"), - QWebEnginePage.PermissionPolicy.PermissionDeniedByUser: - self.tr("Deny"), + QWebEnginePage.PermissionPolicy.PermissionGrantedByUser: self.tr("Allow"), + QWebEnginePage.PermissionPolicy.PermissionDeniedByUser: self.tr("Deny"), } - + self.__permissionsLists = { QWebEnginePage.Feature.Geolocation: self.geoList, QWebEnginePage.Feature.MediaAudioCapture: self.micList, @@ -190,59 +189,55 @@ QWebEnginePage.Feature.MediaAudioVideoCapture: self.micCamList, QWebEnginePage.Feature.MouseLock: self.mouseLockList, QWebEnginePage.Feature.DesktopVideoCapture: self.deskVidList, - QWebEnginePage.Feature.DesktopAudioVideoCapture: - self.deskAudVidList, + QWebEnginePage.Feature.DesktopAudioVideoCapture: self.deskAudVidList, QWebEnginePage.Feature.Notifications: self.notifList, } - + for feature, permissionsList in self.__permissionsLists.items(): for permission in featurePermissions[feature]: for host in featurePermissions[feature][permission]: itm = QTreeWidgetItem( - permissionsList, - [host, self.__permissionStrings[permission]]) + permissionsList, [host, self.__permissionStrings[permission]] + ) itm.setData(0, Qt.ItemDataRole.UserRole, permission) - + self.__previousCurrent = -1 self.tabWidget.currentChanged.connect(self.__currentTabChanged) self.tabWidget.setCurrentIndex(0) - + @pyqtSlot(int) def __currentTabChanged(self, index): """ Private slot handling changes of the selected tab. - + @param index index of the current tab @type int """ if self.__previousCurrent >= 0: previousList = self.tabWidget.widget(self.__previousCurrent) - previousList.itemSelectionChanged.disconnect( - self.__itemSelectionChanged) - + previousList.itemSelectionChanged.disconnect(self.__itemSelectionChanged) + self.__updateButtons() - + currentList = self.tabWidget.currentWidget() currentList.itemSelectionChanged.connect(self.__itemSelectionChanged) self.__previousCurrent = index - + def __updateButtons(self): """ Private method to update the buttons. """ currentList = self.tabWidget.currentWidget() - self.removeAllButton.setEnabled( - currentList.topLevelItemCount() > 0) - self.removeButton.setEnabled( - len(currentList.selectedItems()) > 0) - + self.removeAllButton.setEnabled(currentList.topLevelItemCount() > 0) + self.removeButton.setEnabled(len(currentList.selectedItems()) > 0) + @pyqtSlot() def __itemSelectionChanged(self): """ Private slot handling changes in the current list of selected items. """ self.__updateButtons() - + @pyqtSlot() def on_removeButton_clicked(self): """ @@ -254,7 +249,7 @@ itm = currentList.takeTopLevelItem(row) del itm self.__updateButtons() - + @pyqtSlot() def on_removeAllButton_clicked(self): """ @@ -262,14 +257,14 @@ """ currentList = self.tabWidget.currentWidget() while currentList.topLevelItemCount() > 0: - itm = currentList.takeTopLevelItem(0) # __IGNORE_WARNING__ + itm = currentList.takeTopLevelItem(0) # __IGNORE_WARNING__ del itm self.__updateButtons() - + def getData(self): """ Public method to retrieve the dialog contents. - + @return new feature permission settings @rtype dict of dict of list """ @@ -284,5 +279,5 @@ host = itm.text(0) permission = itm.data(0, Qt.ItemDataRole.UserRole) featurePermissions[feature][permission].append(host) - + return featurePermissions