WebBrowser/AdBlock/AdBlockExceptionsDialog.py

branch
QtWebEngine
changeset 4858
19dff9c9cf26
parent 4631
5c1a96925da4
child 5389
9b1c800daff3
equal deleted inserted replaced
4857:8dba5fb92f12 4858:19dff9c9cf26
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2012 - 2016 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to configure the AdBlock exceptions.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot, Qt
13 from PyQt5.QtWidgets import QDialog
14
15 from .Ui_AdBlockExceptionsDialog import Ui_AdBlockExceptionsDialog
16
17 import UI.PixmapCache
18
19
20 class AdBlockExceptionsDialog(QDialog, Ui_AdBlockExceptionsDialog):
21 """
22 Class implementing a dialog to configure the AdBlock exceptions.
23 """
24 def __init__(self, parent=None):
25 """
26 Constructor
27
28 @param parent reference to the parent widget (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.png"))
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 """
47 self.hostList.clear()
48 self.hostList.addItems(hosts)
49
50 @pyqtSlot(str)
51 def on_hostEdit_textChanged(self, txt):
52 """
53 Private slot to handle changes of the host edit.
54
55 @param txt text of the edit (string)
56 """
57 self.addButton.setEnabled(bool(txt))
58
59 @pyqtSlot()
60 def on_addButton_clicked(self):
61 """
62 Private slot to handle a click of the add button.
63 """
64 self.hostList.addItem(self.hostEdit.text())
65 self.hostEdit.clear()
66
67 @pyqtSlot()
68 def on_hostList_itemSelectionChanged(self):
69 """
70 Private slot handling a change of the number of selected items.
71 """
72 self.deleteButton.setEnabled(len(self.hostList.selectedItems()) > 0)
73
74 @pyqtSlot()
75 def on_deleteButton_clicked(self):
76 """
77 Private slot handling a click of the delete button.
78 """
79 for itm in self.hostList.selectedItems():
80 row = self.hostList.row(itm)
81 removedItem = self.hostList.takeItem(row)
82 del removedItem
83
84 def accept(self):
85 """
86 Public slot handling the acceptance of the dialog.
87 """
88 hosts = []
89 for row in range(self.hostList.count()):
90 hosts.append(self.hostList.item(row).text())
91
92 from WebBrowser.WebBrowserWindow import WebBrowserWindow
93 WebBrowserWindow.adBlockManager().setExceptions(hosts)
94
95 super(AdBlockExceptionsDialog, self).accept()

eric ide

mercurial