eric6/Helpviewer/OpenSearch/OpenSearchDialog.py

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

eric ide

mercurial