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