"Fossies" - the Fresh Open Source Software Archive

Member "eric6-20.8/eric/eric6/WebBrowser/AdBlock/AdBlockExceptionsDialog.py" (2 May 2020, 2751 Bytes) of package /linux/misc/eric6-20.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "AdBlockExceptionsDialog.py" see the Fossies "Dox" file reference documentation.

    1 # -*- coding: utf-8 -*-
    2 
    3 # Copyright (c) 2012 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
    4 #
    5 
    6 """
    7 Module implementing a dialog to configure the AdBlock exceptions.
    8 """
    9 
   10 
   11 from PyQt5.QtCore import pyqtSlot, Qt
   12 from PyQt5.QtWidgets import QDialog
   13 
   14 from .Ui_AdBlockExceptionsDialog import Ui_AdBlockExceptionsDialog
   15 
   16 import UI.PixmapCache
   17 
   18 
   19 class AdBlockExceptionsDialog(QDialog, Ui_AdBlockExceptionsDialog):
   20     """
   21     Class implementing a dialog to configure the AdBlock exceptions.
   22     """
   23     def __init__(self, parent=None):
   24         """
   25         Constructor
   26         
   27         @param parent reference to the parent widget
   28         @type QWidget
   29         """
   30         super(AdBlockExceptionsDialog, self).__init__(parent)
   31         self.setupUi(self)
   32         self.setWindowFlags(Qt.Window)
   33         
   34         self.iconLabel.setPixmap(
   35             UI.PixmapCache.getPixmap("adBlockPlusGreen48"))
   36         
   37         self.hostEdit.setInactiveText(self.tr("Enter host to be added..."))
   38         
   39         self.buttonBox.setFocus()
   40     
   41     def load(self, hosts):
   42         """
   43         Public slot to load the list of excepted hosts.
   44         
   45         @param hosts list of excepted hosts
   46         @type list of str
   47         """
   48         self.hostList.clear()
   49         self.hostList.addItems(hosts)
   50     
   51     @pyqtSlot(str)
   52     def on_hostEdit_textChanged(self, txt):
   53         """
   54         Private slot to handle changes of the host edit.
   55         
   56         @param txt text of the edit
   57         @type str
   58         """
   59         self.addButton.setEnabled(bool(txt))
   60     
   61     @pyqtSlot()
   62     def on_addButton_clicked(self):
   63         """
   64         Private slot to handle a click of the add button.
   65         """
   66         self.hostList.addItem(self.hostEdit.text())
   67         self.hostEdit.clear()
   68     
   69     @pyqtSlot()
   70     def on_hostList_itemSelectionChanged(self):
   71         """
   72         Private slot handling a change of the number of selected items.
   73         """
   74         self.deleteButton.setEnabled(len(self.hostList.selectedItems()) > 0)
   75     
   76     @pyqtSlot()
   77     def on_deleteButton_clicked(self):
   78         """
   79         Private slot handling a click of the delete button.
   80         """
   81         for itm in self.hostList.selectedItems():
   82             row = self.hostList.row(itm)
   83             removedItem = self.hostList.takeItem(row)
   84             del removedItem
   85     
   86     def accept(self):
   87         """
   88         Public slot handling the acceptance of the dialog.
   89         """
   90         hosts = []
   91         for row in range(self.hostList.count()):
   92             hosts.append(self.hostList.item(row).text())
   93         
   94         from WebBrowser.WebBrowserWindow import WebBrowserWindow
   95         WebBrowserWindow.adBlockManager().setExceptions(hosts)
   96         
   97         super(AdBlockExceptionsDialog, self).accept()