Helpviewer/QtHelpDocumentationDialog.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to manage the QtHelp documentation database.
8 """
9
10 from PyQt4.QtGui import *
11 from PyQt4.QtCore import *
12 from PyQt4.QtHelp import QHelpEngineCore
13
14 from Ui_QtHelpDocumentationDialog import Ui_QtHelpDocumentationDialog
15
16 class QtHelpDocumentationDialog(QDialog, Ui_QtHelpDocumentationDialog):
17 """
18 Class implementing a dialog to manage the QtHelp documentation database.
19 """
20 def __init__(self, engine, parent):
21 """
22 Constructor
23
24 @param engine reference to the help engine (QHelpEngine)
25 @param parent reference to the parent widget (QWidget)
26 """
27 QDialog.__init__(self, parent)
28 self.setupUi(self)
29
30 self.removeButton.setEnabled(False)
31
32 self.__engine = engine
33 self.__mw = parent
34
35 docs = self.__engine.registeredDocumentations()
36 self.documentsList.addItems(docs)
37
38 self.__registeredDocs = []
39 self.__unregisteredDocs = []
40 self.__tabsToClose = []
41
42 @pyqtSlot()
43 def on_documentsList_itemSelectionChanged(self):
44 """
45 Private slot handling a change of the documents selection.
46 """
47 self.removeButton.setEnabled(len(self.documentsList.selectedItems()) != 0)
48
49 @pyqtSlot()
50 def on_addButton_clicked(self):
51 """
52 Private slot to add documents to the help database.
53 """
54 fileNames = QFileDialog.getOpenFileNames(
55 self,
56 self.trUtf8("Add Documentation"),
57 "",
58 self.trUtf8("Qt Compressed Help Files (*.qch)"))
59 if not fileNames:
60 return
61
62 for fileName in fileNames:
63 ns = QHelpEngineCore.namespaceName(fileName)
64 if not ns:
65 QMessageBox.warning(self,
66 self.trUtf8("Add Documentation"),
67 self.trUtf8("""The file <b>{0}</b> is not a valid Qt Help File.""")\
68 .format(fileName)
69 )
70 continue
71
72 if len(self.documentsList.findItems(ns, Qt.MatchFixedString)):
73 QMessageBox.warning(self,
74 self.trUtf8("Add Documentation"),
75 self.trUtf8("""The namespace <b>{0}</b> is already registered.""")\
76 .format(ns)
77 )
78 continue
79
80 self.__engine.registerDocumentation(fileName)
81 self.documentsList.addItem(ns)
82 self.__registeredDocs.append(ns)
83 if ns in self.__unregisteredDocs:
84 self.__unregisteredDocs.remove(ns)
85
86 @pyqtSlot()
87 def on_removeButton_clicked(self):
88 """
89 Private slot to remove a document from the help database.
90 """
91 res = QMessageBox.question(None,
92 self.trUtf8("Remove Documentation"),
93 self.trUtf8("""Do you really want to remove the selected documentation """
94 """sets from the database?"""),
95 QMessageBox.StandardButtons(\
96 QMessageBox.No | \
97 QMessageBox.Yes),
98 QMessageBox.No)
99 if res == QMessageBox.No:
100 return
101
102 openedDocs = self.__mw.getSourceFileList()
103
104 items = self.documentsList.selectedItems()
105 for item in items:
106 ns = item.text()
107 if ns in openedDocs.values():
108 res = QMessageBox.information(self,
109 self.trUtf8("Remove Documentation"),
110 self.trUtf8("""Some documents currently opened reference the """
111 """documentation you are attempting to remove. """
112 """Removing the documentation will close those """
113 """documents."""),
114 QMessageBox.StandardButtons(\
115 QMessageBox.Cancel | \
116 QMessageBox.Ok))
117 if res == QMessageBox.Cancel:
118 return
119 self.__unregisteredDocs.append(ns)
120 for id in openedDocs:
121 if openedDocs[id] == ns and id not in self.__tabsToClose:
122 self.__tabsToClose.append(id)
123 itm = self.documentsList.takeItem(self.documentsList.row(item))
124 del itm
125
126 self.__engine.unregisterDocumentation(ns)
127
128 if self.documentsList.count():
129 self.documentsList.setCurrentRow(0, QItemSelectionModel.ClearAndSelect)
130
131 def hasChanges(self):
132 """
133 Public slot to test the dialog for changes.
134
135 @return flag indicating presence of changes
136 """
137 return len(self.__registeredDocs) > 0 or \
138 len(self.__unregisteredDocs) > 0
139
140 def getTabsToClose(self):
141 """
142 Public method to get the list of tabs to close.
143
144 @return list of tab ids to be closed (list of integers)
145 """
146 return self.__tabsToClose

eric ide

mercurial