eric6/Helpviewer/Network/NoCacheHostsDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2012 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to manage the list of hosts not to be cached.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot, Qt, QSortFilterProxyModel, QStringListModel
13 from PyQt5.QtWidgets import QDialog, QInputDialog, QLineEdit
14
15 from .Ui_NoCacheHostsDialog import Ui_NoCacheHostsDialog
16
17 import Preferences
18
19
20 class NoCacheHostsDialog(QDialog, Ui_NoCacheHostsDialog):
21 """
22 Class implementing a dialog to manage the list of hosts not to be cached.
23 """
24 def __init__(self, parent=None):
25 """
26 Constructor
27
28 @param parent reference to the parent widget (QWidget)
29 """
30 super(NoCacheHostsDialog, self).__init__(parent)
31 self.setupUi(self)
32
33 self.__model = QStringListModel(
34 Preferences.getHelp("NoCacheHosts"), self)
35 self.__model.sort(0)
36 self.__proxyModel = QSortFilterProxyModel(self)
37 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
38 self.__proxyModel.setSourceModel(self.__model)
39 self.noCacheList.setModel(self.__proxyModel)
40
41 self.searchEdit.textChanged.connect(
42 self.__proxyModel.setFilterFixedString)
43
44 self.removeButton.clicked.connect(self.noCacheList.removeSelected)
45 self.removeAllButton.clicked.connect(self.noCacheList.removeAll)
46
47 @pyqtSlot()
48 def on_addButton_clicked(self):
49 """
50 Private slot to add an entry to the list.
51 """
52 host, ok = QInputDialog.getText(
53 self,
54 self.tr("Not Cached Hosts"),
55 self.tr("Enter host name to add to the list:"),
56 QLineEdit.Normal)
57 if ok and host != "" and host not in self.__model.stringList():
58 self.__model.insertRow(self.__model.rowCount())
59 self.__model.setData(
60 self.__model.index(self.__model.rowCount() - 1), host)
61 self.__model.sort(0)
62
63 def accept(self):
64 """
65 Public method to accept the dialog data.
66 """
67 Preferences.setHelp("NoCacheHosts", self.__model.stringList())
68
69 super(NoCacheHostsDialog, self).accept()

eric ide

mercurial