eric7/WebBrowser/OpenSearch/OpenSearchDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8260
2161475d9639
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog for the configuration of search engines.
8 """
9
10 from PyQt5.QtWidgets import QDialog
11 from PyQt5.QtCore import pyqtSlot
12
13 from E5Gui import E5MessageBox, E5FileDialog
14
15 from .OpenSearchEngineModel import OpenSearchEngineModel
16
17 from .Ui_OpenSearchDialog import Ui_OpenSearchDialog
18
19
20 class OpenSearchDialog(QDialog, Ui_OpenSearchDialog):
21 """
22 Class implementing a dialog for the configuration of search engines.
23 """
24 def __init__(self, parent=None):
25 """
26 Constructor
27
28 @param parent reference to the parent object (QWidget)
29 """
30 super().__init__(parent)
31 self.setupUi(self)
32
33 self.setModal(True)
34
35 self.__mw = parent
36
37 self.__model = OpenSearchEngineModel(
38 self.__mw.openSearchManager(), self)
39 self.enginesTable.setModel(self.__model)
40 self.enginesTable.horizontalHeader().resizeSection(0, 200)
41 self.enginesTable.horizontalHeader().setStretchLastSection(True)
42 self.enginesTable.verticalHeader().hide()
43 self.enginesTable.verticalHeader().setDefaultSectionSize(
44 1.2 * self.fontMetrics().height())
45
46 self.enginesTable.selectionModel().selectionChanged.connect(
47 self.__selectionChanged)
48 self.editButton.setEnabled(False)
49
50 @pyqtSlot()
51 def on_addButton_clicked(self):
52 """
53 Private slot to add a new search engine.
54 """
55 fileNames = E5FileDialog.getOpenFileNames(
56 self,
57 self.tr("Add search engine"),
58 "",
59 self.tr("OpenSearch (*.xml);;All Files (*)"))
60
61 osm = self.__mw.openSearchManager()
62 for fileName in fileNames:
63 if not osm.addEngine(fileName):
64 E5MessageBox.critical(
65 self,
66 self.tr("Add search engine"),
67 self.tr(
68 """{0} is not a valid OpenSearch 1.1 description or"""
69 """ is already on your list.""").format(fileName))
70
71 @pyqtSlot()
72 def on_deleteButton_clicked(self):
73 """
74 Private slot to delete the selected search engines.
75 """
76 if self.enginesTable.model().rowCount() == 1:
77 E5MessageBox.critical(
78 self,
79 self.tr("Delete selected engines"),
80 self.tr("""You must have at least one search engine."""))
81
82 self.enginesTable.removeSelected()
83
84 @pyqtSlot()
85 def on_restoreButton_clicked(self):
86 """
87 Private slot to restore the default search engines.
88 """
89 self.__mw.openSearchManager().restoreDefaults()
90
91 @pyqtSlot()
92 def on_editButton_clicked(self):
93 """
94 Private slot to edit the data of the current search engine.
95 """
96 from .OpenSearchEditDialog import OpenSearchEditDialog
97
98 rows = self.enginesTable.selectionModel().selectedRows()
99 row = (
100 self.enginesTable.selectionModel().currentIndex().row()
101 if len(rows) == 0 else
102 rows[0].row()
103 )
104
105 osm = self.__mw.openSearchManager()
106 engineName = osm.allEnginesNames()[row]
107 engine = osm.engine(engineName)
108 dlg = OpenSearchEditDialog(engine, self)
109 if dlg.exec() == QDialog.DialogCode.Accepted:
110 osm.enginesChanged()
111
112 def __selectionChanged(self, selected, deselected):
113 """
114 Private slot to handle a change of the selection.
115
116 @param selected item selection of selected items (QItemSelection)
117 @param deselected item selection of deselected items (QItemSelection)
118 """
119 self.editButton.setEnabled(
120 len(self.enginesTable.selectionModel().selectedRows()) <= 1)

eric ide

mercurial