eric6/WebBrowser/AdBlock/AdBlockExceptionsDialog.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7781
607a6098cb44
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to configure the AdBlock exceptions.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
4278
ccd1e13cb9bd Fixed issues where dialogs could not be minimized on some desktop environments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
10 from PyQt5.QtCore import pyqtSlot, Qt
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
11 from PyQt5.QtWidgets import QDialog
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from .Ui_AdBlockExceptionsDialog import Ui_AdBlockExceptionsDialog
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 import UI.PixmapCache
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class AdBlockExceptionsDialog(QDialog, Ui_AdBlockExceptionsDialog):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Class implementing a dialog to configure the AdBlock exceptions.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 def __init__(self, parent=None):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Constructor
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
26 @param parent reference to the parent widget
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
27 @type QWidget
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
29 super(AdBlockExceptionsDialog, self).__init__(parent)
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.setupUi(self)
4278
ccd1e13cb9bd Fixed issues where dialogs could not be minimized on some desktop environments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
31 self.setWindowFlags(Qt.Window)
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
2991
226481ff40d1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
33 self.iconLabel.setPixmap(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
34 UI.PixmapCache.getPixmap("adBlockPlusGreen48"))
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
36 self.hostEdit.setInactiveText(self.tr("Enter host to be added..."))
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.buttonBox.setFocus()
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 def load(self, hosts):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 Public slot to load the list of excepted hosts.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @param hosts list of excepted hosts
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
45 @type list of str
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.hostList.clear()
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.hostList.addItems(hosts)
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @pyqtSlot(str)
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 def on_hostEdit_textChanged(self, txt):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 Private slot to handle changes of the host edit.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
55 @param txt text of the edit
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
56 @type str
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.addButton.setEnabled(bool(txt))
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 @pyqtSlot()
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 def on_addButton_clicked(self):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 Private slot to handle a click of the add button.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.hostList.addItem(self.hostEdit.text())
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.hostEdit.clear()
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 @pyqtSlot()
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 def on_hostList_itemSelectionChanged(self):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 Private slot handling a change of the number of selected items.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.deleteButton.setEnabled(len(self.hostList.selectedItems()) > 0)
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 @pyqtSlot()
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 def on_deleteButton_clicked(self):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 Private slot handling a click of the delete button.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 for itm in self.hostList.selectedItems():
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 row = self.hostList.row(itm)
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 removedItem = self.hostList.takeItem(row)
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 del removedItem
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 def accept(self):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 Public slot handling the acceptance of the dialog.
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 """
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 hosts = []
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 for row in range(self.hostList.count()):
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 hosts.append(self.hostList.item(row).text())
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
93 from WebBrowser.WebBrowserWindow import WebBrowserWindow
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
94 WebBrowserWindow.adBlockManager().setExceptions(hosts)
1972
5341662d6cfb Added support for AdBlock exceptions to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
96 super(AdBlockExceptionsDialog, self).accept()

eric ide

mercurial