|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to configure the AdBlock exceptions. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot, Qt |
|
11 from PyQt6.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.buttonBox.setFocus() |
|
37 |
|
38 def load(self, hosts): |
|
39 """ |
|
40 Public slot to load the list of excepted hosts. |
|
41 |
|
42 @param hosts list of excepted hosts |
|
43 @type list of str |
|
44 """ |
|
45 self.hostList.clear() |
|
46 self.hostList.addItems(hosts) |
|
47 |
|
48 @pyqtSlot(str) |
|
49 def on_hostEdit_textChanged(self, txt): |
|
50 """ |
|
51 Private slot to handle changes of the host edit. |
|
52 |
|
53 @param txt text of the edit |
|
54 @type str |
|
55 """ |
|
56 self.addButton.setEnabled(bool(txt)) |
|
57 |
|
58 @pyqtSlot() |
|
59 def on_addButton_clicked(self): |
|
60 """ |
|
61 Private slot to handle a click of the add button. |
|
62 """ |
|
63 self.hostList.addItem(self.hostEdit.text()) |
|
64 self.hostEdit.clear() |
|
65 |
|
66 @pyqtSlot() |
|
67 def on_hostList_itemSelectionChanged(self): |
|
68 """ |
|
69 Private slot handling a change of the number of selected items. |
|
70 """ |
|
71 self.deleteButton.setEnabled(len(self.hostList.selectedItems()) > 0) |
|
72 |
|
73 @pyqtSlot() |
|
74 def on_deleteButton_clicked(self): |
|
75 """ |
|
76 Private slot handling a click of the delete button. |
|
77 """ |
|
78 for itm in self.hostList.selectedItems(): |
|
79 row = self.hostList.row(itm) |
|
80 removedItem = self.hostList.takeItem(row) |
|
81 del removedItem |
|
82 |
|
83 def accept(self): |
|
84 """ |
|
85 Public slot handling the acceptance of the dialog. |
|
86 """ |
|
87 hosts = [] |
|
88 for row in range(self.hostList.count()): |
|
89 hosts.append(self.hostList.item(row).text()) |
|
90 |
|
91 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
|
92 WebBrowserWindow.adBlockManager().setExceptions(hosts) |
|
93 |
|
94 super().accept() |