eric6/Plugins/PluginEricdoc.py

changeset 6942
2602857055c5
parent 6666
06f6e0f24e89
child 7178
43e994af5ee0
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Ericdoc plugin.
8 """
9
10 from __future__ import unicode_literals
11
12 import os
13
14 from PyQt5.QtCore import QObject, QCoreApplication
15 from PyQt5.QtWidgets import QDialog
16
17 from E5Gui.E5Application import e5App
18
19 from E5Gui.E5Action import E5Action
20
21 import Utilities
22 import UI.Info
23
24 from eric6config import getConfig
25
26 # Start-Of-Header
27 name = "Ericdoc Plugin"
28 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
29 autoactivate = True
30 deactivateable = True
31 version = UI.Info.VersionOnly
32 className = "EricdocPlugin"
33 packageName = "__core__"
34 shortDescription = "Show the Ericdoc dialogs."
35 longDescription = """This plugin implements the Ericdoc dialogs.""" \
36 """ Ericdoc is used to generate a source code documentation""" \
37 """ for Python and Ruby projects."""
38 pyqtApi = 2
39 python2Compatible = True
40 # End-Of-Header
41
42 error = ""
43
44
45 def exeDisplayDataList():
46 """
47 Public method to support the display of some executable info.
48
49 @return dictionary containing the data to query the presence of
50 the executable
51 """
52 dataList = []
53
54 # 1. eric6_doc
55 exe = 'eric6_doc'
56 if Utilities.isWindowsPlatform():
57 exe = os.path.join(getConfig("bindir"), exe + '.cmd')
58 if not os.path.exists(exe):
59 exe = os.path.join(getConfig("bindir"), exe + '.bat')
60 else:
61 exe = os.path.join(getConfig("bindir"), exe)
62 dataList.append({
63 "programEntry": True,
64 "header": QCoreApplication.translate(
65 "EricdocPlugin", "Eric6 Documentation Generator"),
66 "exe": exe,
67 "versionCommand": '--version',
68 "versionStartsWith": 'eric6_',
69 "versionPosition": -3,
70 "version": "",
71 "versionCleanup": None,
72 })
73
74 # 2. Qt Help Generator
75 exe = os.path.join(
76 Utilities.getQtBinariesPath(),
77 Utilities.generateQtToolName('qhelpgenerator')
78 )
79 if Utilities.isWindowsPlatform():
80 exe += '.exe'
81 dataList.append({
82 "programEntry": True,
83 "header": QCoreApplication.translate(
84 "EricdocPlugin", "Qt Help Tools"),
85 "exe": exe,
86 "versionCommand": '-v',
87 "versionStartsWith": 'Qt',
88 "versionPosition": -1,
89 "version": "",
90 "versionCleanup": (0, -1),
91 })
92
93 # 3. Qt Collection Generator
94 exe = os.path.join(
95 Utilities.getQtBinariesPath(),
96 Utilities.generateQtToolName('qcollectiongenerator')
97 )
98 if Utilities.isWindowsPlatform():
99 exe += '.exe'
100 if Utilities.isExecutable(exe):
101 # assume Qt 5.,12 if it is missing
102 dataList.append({
103 "programEntry": True,
104 "header": QCoreApplication.translate(
105 "EricdocPlugin", "Qt Help Tools"),
106 "exe": exe,
107 "versionCommand": '-v',
108 "versionStartsWith": 'Qt',
109 "versionPosition": -1,
110 "version": "",
111 "versionCleanup": (0, -1),
112 })
113
114 return dataList
115
116
117 class EricdocPlugin(QObject):
118 """
119 Class implementing the Ericdoc plugin.
120 """
121 def __init__(self, ui):
122 """
123 Constructor
124
125 @param ui reference to the user interface object (UI.UserInterface)
126 """
127 super(EricdocPlugin, self).__init__(ui)
128 self.__ui = ui
129 self.__initialize()
130
131 def __initialize(self):
132 """
133 Private slot to (re)initialize the plugin.
134 """
135 self.__projectAct = None
136
137 def activate(self):
138 """
139 Public method to activate this plugin.
140
141 @return tuple of None and activation status (boolean)
142 """
143 menu = e5App().getObject("Project").getMenu("Apidoc")
144 if menu:
145 self.__projectAct = \
146 E5Action(
147 self.tr('Generate documentation (eric6_doc)'),
148 self.tr('Generate &documentation (eric6_doc)'), 0, 0,
149 self, 'doc_eric6_doc')
150 self.__projectAct.setStatusTip(
151 self.tr('Generate API documentation using eric6_doc'))
152 self.__projectAct.setWhatsThis(self.tr(
153 """<b>Generate documentation</b>"""
154 """<p>Generate API documentation using eric6_doc.</p>"""
155 ))
156 self.__projectAct.triggered.connect(self.__doEricdoc)
157 e5App().getObject("Project").addE5Actions([self.__projectAct])
158 menu.addAction(self.__projectAct)
159
160 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu)
161
162 return None, True
163
164 def deactivate(self):
165 """
166 Public method to deactivate this plugin.
167 """
168 e5App().getObject("Project").showMenu.disconnect(
169 self.__projectShowMenu)
170
171 menu = e5App().getObject("Project").getMenu("Apidoc")
172 if menu:
173 menu.removeAction(self.__projectAct)
174 e5App().getObject("Project").removeE5Actions([self.__projectAct])
175 self.__initialize()
176
177 def __projectShowMenu(self, menuName, menu):
178 """
179 Private slot called, when the the project menu or a submenu is
180 about to be shown.
181
182 @param menuName name of the menu to be shown (string)
183 @param menu reference to the menu (QMenu)
184 """
185 if menuName == "Apidoc":
186 if self.__projectAct is not None:
187 self.__projectAct.setEnabled(
188 e5App().getObject("Project").getProjectLanguage() in
189 ["Python", "Python2", "Python3", "Ruby"])
190
191 def __doEricdoc(self):
192 """
193 Private slot to perform the eric6_doc api documentation generation.
194 """
195 from DocumentationPlugins.Ericdoc.EricdocConfigDialog import \
196 EricdocConfigDialog
197 eolTranslation = {
198 '\r': 'cr',
199 '\n': 'lf',
200 '\r\n': 'crlf',
201 }
202 project = e5App().getObject("Project")
203 parms = project.getData('DOCUMENTATIONPARMS', "ERIC4DOC")
204 dlg = EricdocConfigDialog(project, parms)
205 if dlg.exec_() == QDialog.Accepted:
206 args, parms = dlg.generateParameters()
207 project.setData('DOCUMENTATIONPARMS', "ERIC4DOC", parms)
208
209 # add parameter for the eol setting
210 if not project.useSystemEol():
211 args.append(
212 "--eol={0}".format(eolTranslation[project.getEolString()]))
213
214 # now do the call
215 from DocumentationPlugins.Ericdoc.EricdocExecDialog import \
216 EricdocExecDialog
217 dia = EricdocExecDialog("Ericdoc")
218 res = dia.start(args, project.ppath)
219 if res:
220 dia.exec_()
221
222 outdir = Utilities.toNativeSeparators(parms['outputDirectory'])
223 if outdir == '':
224 outdir = 'doc' # that is eric6_docs default output dir
225
226 # add it to the project data, if it isn't in already
227 outdir = project.getRelativePath(outdir)
228 if outdir not in project.pdata['OTHERS']:
229 project.pdata['OTHERS'].append(outdir)
230 project.setDirty(True)
231 project.othersAdded(outdir)
232
233 if parms['qtHelpEnabled']:
234 outdir = Utilities.toNativeSeparators(
235 parms['qtHelpOutputDirectory'])
236 if outdir == '':
237 outdir = 'help'
238 # that is eric6_docs default QtHelp output dir
239
240 # add it to the project data, if it isn't in already
241 outdir = project.getRelativePath(outdir)
242 if outdir not in project.pdata['OTHERS']:
243 project.pdata['OTHERS'].append(outdir)
244 project.setDirty(True)
245 project.othersAdded(outdir)

eric ide

mercurial