eric6/WebBrowser/CookieJar/CookiesExceptionsDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog for the configuration of cookie exceptions.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot, QSortFilterProxyModel
13 from PyQt5.QtGui import QFont, QFontMetrics
14 from PyQt5.QtWidgets import QDialog, QCompleter
15
16 from .CookieExceptionsModel import CookieExceptionsModel
17
18 from .Ui_CookiesExceptionsDialog import Ui_CookiesExceptionsDialog
19
20
21 class CookiesExceptionsDialog(QDialog, Ui_CookiesExceptionsDialog):
22 """
23 Class implementing a dialog for the configuration of cookie exceptions.
24 """
25 def __init__(self, cookieJar, parent=None):
26 """
27 Constructor
28
29 @param cookieJar reference to the cookie jar (CookieJar)
30 @param parent reference to the parent widget (QWidget)
31 """
32 super(CookiesExceptionsDialog, self).__init__(parent)
33 self.setupUi(self)
34
35 self.__cookieJar = cookieJar
36
37 self.removeButton.clicked.connect(
38 self.exceptionsTable.removeSelected)
39 self.removeAllButton.clicked.connect(
40 self.exceptionsTable.removeAll)
41
42 self.exceptionsTable.verticalHeader().hide()
43 self.__exceptionsModel = CookieExceptionsModel(cookieJar)
44 self.__proxyModel = QSortFilterProxyModel(self)
45 self.__proxyModel.setSourceModel(self.__exceptionsModel)
46 self.searchEdit.textChanged.connect(
47 self.__proxyModel.setFilterFixedString)
48 self.exceptionsTable.setModel(self.__proxyModel)
49
50 self.domainEdit.setCompleter(
51 QCompleter(cookieJar.cookieDomains(), self.domainEdit))
52
53 f = QFont()
54 f.setPointSize(10)
55 fm = QFontMetrics(f)
56 height = fm.height() + fm.height() // 3
57 self.exceptionsTable.verticalHeader().setDefaultSectionSize(height)
58 self.exceptionsTable.verticalHeader().setMinimumSectionSize(-1)
59 for section in range(self.__exceptionsModel.columnCount()):
60 header = self.exceptionsTable.horizontalHeader()\
61 .sectionSizeHint(section)
62 if section == 0:
63 header = fm.width("averagebiglonghost.averagedomain.info")
64 elif section == 1:
65 header = fm.width(self.tr("Allow For Session"))
66 buffer = fm.width("mm")
67 header += buffer
68 self.exceptionsTable.horizontalHeader()\
69 .resizeSection(section, header)
70
71 def setDomainName(self, domain):
72 """
73 Public method to set the domain to be displayed.
74
75 @param domain domain name to be displayed (string)
76 """
77 self.domainEdit.setText(domain)
78
79 @pyqtSlot(str)
80 def on_domainEdit_textChanged(self, txt):
81 """
82 Private slot to handle a change of the domain edit text.
83
84 @param txt current text of the edit (string)
85 """
86 enabled = txt != ""
87 self.blockButton.setEnabled(enabled)
88 self.allowButton.setEnabled(enabled)
89 self.allowForSessionButton.setEnabled(enabled)
90
91 @pyqtSlot()
92 def on_blockButton_clicked(self):
93 """
94 Private slot to block cookies of a domain.
95 """
96 from .CookieJar import CookieJar
97 self.__exceptionsModel.addRule(self.domainEdit.text(), CookieJar.Block)
98 self.domainEdit.clear()
99
100 @pyqtSlot()
101 def on_allowForSessionButton_clicked(self):
102 """
103 Private slot to allow cookies of a domain for the current session only.
104 """
105 from .CookieJar import CookieJar
106 self.__exceptionsModel.addRule(self.domainEdit.text(),
107 CookieJar.AllowForSession)
108 self.domainEdit.clear()
109
110 @pyqtSlot()
111 def on_allowButton_clicked(self):
112 """
113 Private slot to allow cookies of a domain.
114 """
115 from .CookieJar import CookieJar
116 self.__exceptionsModel.addRule(self.domainEdit.text(), CookieJar.Allow)
117 self.domainEdit.clear()

eric ide

mercurial