|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2007 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Ericdoc plugin. |
|
8 """ |
|
9 |
|
10 import os |
|
11 import sys |
|
12 |
|
13 from PyQt6.QtCore import QObject, QCoreApplication |
|
14 from PyQt6.QtWidgets import QDialog |
|
15 |
|
16 from EricWidgets.EricApplication import ericApp |
|
17 |
|
18 from EricGui.EricAction import EricAction |
|
19 |
|
20 import Utilities |
|
21 import UI.Info |
|
22 |
|
23 from eric7config import getConfig |
|
24 |
|
25 # Start-Of-Header |
|
26 name = "Ericdoc Plugin" |
|
27 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
|
28 autoactivate = True |
|
29 deactivateable = True |
|
30 version = UI.Info.VersionOnly |
|
31 className = "EricdocPlugin" |
|
32 packageName = "__core__" |
|
33 shortDescription = "Show the Ericdoc dialogs." |
|
34 longDescription = ( |
|
35 """This plugin implements the Ericdoc dialogs.""" |
|
36 """ Ericdoc is used to generate a source code documentation""" |
|
37 """ for Python and Ruby projects.""" |
|
38 ) |
|
39 pyqtApi = 2 |
|
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. eric7_doc |
|
55 exe = 'eric7_doc' |
|
56 if Utilities.isWindowsPlatform(): |
|
57 for exepath in ( |
|
58 getConfig("bindir"), |
|
59 os.path.join(sys.exec_prefix, "Scripts"), |
|
60 ): |
|
61 found = False |
|
62 for ext in (".exe", ".cmd", ".bat"): |
|
63 exe_ = os.path.join(exepath, exe + ext) |
|
64 if os.path.exists(exe_): |
|
65 exe = exe_ |
|
66 found = True |
|
67 break |
|
68 if found: |
|
69 break |
|
70 else: |
|
71 for exepath in ( |
|
72 getConfig("bindir"), |
|
73 os.path.join(sys.exec_prefix, "bin"), |
|
74 ): |
|
75 exe_ = os.path.join(exepath, exe) |
|
76 if os.path.exists(exe_): |
|
77 exe = exe_ |
|
78 break |
|
79 |
|
80 dataList.append({ |
|
81 "programEntry": True, |
|
82 "header": QCoreApplication.translate( |
|
83 "EricdocPlugin", "eric Documentation Generator"), |
|
84 "exe": exe, |
|
85 "versionCommand": '--version', |
|
86 "versionStartsWith": 'eric7_', |
|
87 "versionPosition": -3, |
|
88 "version": "", |
|
89 "versionCleanup": None, |
|
90 }) |
|
91 |
|
92 # 2. Qt Help Generator |
|
93 # 2.1 location before 6.3 (Linux and macOS) and Windows |
|
94 exe = os.path.join( |
|
95 Utilities.getQtBinariesPath(), |
|
96 Utilities.generateQtToolName('qhelpgenerator') |
|
97 ) |
|
98 if Utilities.isWindowsPlatform(): |
|
99 exe += '.exe' |
|
100 if os.path.exists(exe): |
|
101 dataList.append({ |
|
102 "programEntry": True, |
|
103 "header": QCoreApplication.translate( |
|
104 "EricdocPlugin", "Qt Help Tools"), |
|
105 "exe": exe, |
|
106 "versionCommand": '-v', |
|
107 "versionStartsWith": 'Qt', |
|
108 "versionPosition": -1, |
|
109 "version": "", |
|
110 "versionCleanup": (0, -1), |
|
111 }) |
|
112 else: |
|
113 # 2.2 location starting with 6.3.0 (Linux and macOS) |
|
114 exe = os.path.join( |
|
115 Utilities.getQtBinariesPath(libexec=True), |
|
116 Utilities.generateQtToolName('qhelpgenerator') |
|
117 ) |
|
118 dataList.append({ |
|
119 "programEntry": True, |
|
120 "header": QCoreApplication.translate( |
|
121 "EricdocPlugin", "Qt Help Tools"), |
|
122 "exe": exe, |
|
123 "versionCommand": '-v', |
|
124 "versionStartsWith": 'Qt', |
|
125 "versionPosition": -1, |
|
126 "version": "", |
|
127 "versionCleanup": (0, -1), |
|
128 }) |
|
129 |
|
130 return dataList |
|
131 |
|
132 |
|
133 class EricdocPlugin(QObject): |
|
134 """ |
|
135 Class implementing the Ericdoc plugin. |
|
136 """ |
|
137 def __init__(self, ui): |
|
138 """ |
|
139 Constructor |
|
140 |
|
141 @param ui reference to the user interface object (UI.UserInterface) |
|
142 """ |
|
143 super().__init__(ui) |
|
144 self.__ui = ui |
|
145 self.__initialize() |
|
146 |
|
147 def __initialize(self): |
|
148 """ |
|
149 Private slot to (re)initialize the plugin. |
|
150 """ |
|
151 self.__projectAct = None |
|
152 |
|
153 def activate(self): |
|
154 """ |
|
155 Public method to activate this plugin. |
|
156 |
|
157 @return tuple of None and activation status (boolean) |
|
158 """ |
|
159 menu = ericApp().getObject("Project").getMenu("Apidoc") |
|
160 if menu: |
|
161 self.__projectAct = EricAction( |
|
162 self.tr('Generate documentation (eric7_doc)'), |
|
163 self.tr('Generate &documentation (eric7_doc)'), 0, 0, |
|
164 self, 'doc_eric7_doc') |
|
165 self.__projectAct.setStatusTip( |
|
166 self.tr('Generate API documentation using eric7_doc')) |
|
167 self.__projectAct.setWhatsThis(self.tr( |
|
168 """<b>Generate documentation</b>""" |
|
169 """<p>Generate API documentation using eric7_doc.</p>""" |
|
170 )) |
|
171 self.__projectAct.triggered.connect(self.__doEricdoc) |
|
172 ericApp().getObject("Project").addEricActions([self.__projectAct]) |
|
173 menu.addAction(self.__projectAct) |
|
174 |
|
175 ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu) |
|
176 |
|
177 return None, True |
|
178 |
|
179 def deactivate(self): |
|
180 """ |
|
181 Public method to deactivate this plugin. |
|
182 """ |
|
183 ericApp().getObject("Project").showMenu.disconnect( |
|
184 self.__projectShowMenu) |
|
185 |
|
186 menu = ericApp().getObject("Project").getMenu("Apidoc") |
|
187 if menu: |
|
188 menu.removeAction(self.__projectAct) |
|
189 ericApp().getObject("Project").removeEricActions( |
|
190 [self.__projectAct]) |
|
191 self.__initialize() |
|
192 |
|
193 def __projectShowMenu(self, menuName, menu): |
|
194 """ |
|
195 Private slot called, when the the project menu or a submenu is |
|
196 about to be shown. |
|
197 |
|
198 @param menuName name of the menu to be shown (string) |
|
199 @param menu reference to the menu (QMenu) |
|
200 """ |
|
201 if menuName == "Apidoc" and self.__projectAct is not None: |
|
202 self.__projectAct.setEnabled( |
|
203 ericApp().getObject("Project").getProjectLanguage() in |
|
204 ["Python", "Python3", "Ruby", "MicroPython"]) |
|
205 |
|
206 def __doEricdoc(self): |
|
207 """ |
|
208 Private slot to perform the eric7_doc api documentation generation. |
|
209 """ |
|
210 from DocumentationPlugins.Ericdoc.EricdocConfigDialog import ( |
|
211 EricdocConfigDialog |
|
212 ) |
|
213 eolTranslation = { |
|
214 '\r': 'cr', |
|
215 '\n': 'lf', |
|
216 '\r\n': 'crlf', |
|
217 } |
|
218 project = ericApp().getObject("Project") |
|
219 parms = project.getData('DOCUMENTATIONPARMS', "ERIC4DOC") |
|
220 dlg = EricdocConfigDialog(project, parms) |
|
221 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
222 args, parms = dlg.generateParameters() |
|
223 project.setData('DOCUMENTATIONPARMS', "ERIC4DOC", parms) |
|
224 |
|
225 # add parameter for the eol setting |
|
226 if not project.useSystemEol(): |
|
227 args.append( |
|
228 "--eol={0}".format(eolTranslation[project.getEolString()])) |
|
229 |
|
230 # now do the call |
|
231 from DocumentationPlugins.Ericdoc.EricdocExecDialog import ( |
|
232 EricdocExecDialog |
|
233 ) |
|
234 dia = EricdocExecDialog("Ericdoc") |
|
235 res = dia.start(args, project.ppath) |
|
236 if res: |
|
237 dia.exec() |
|
238 |
|
239 outdir = Utilities.toNativeSeparators(parms['outputDirectory']) |
|
240 if outdir == '': |
|
241 outdir = 'doc' # that is eric7_docs default output dir |
|
242 |
|
243 # add it to the project data, if it isn't in already |
|
244 outdir = project.getRelativePath(outdir) |
|
245 if outdir not in project.pdata['OTHERS']: |
|
246 project.pdata['OTHERS'].append(outdir) |
|
247 project.setDirty(True) |
|
248 project.othersAdded(outdir) |
|
249 |
|
250 if parms['qtHelpEnabled']: |
|
251 outdir = Utilities.toNativeSeparators( |
|
252 parms['qtHelpOutputDirectory']) |
|
253 if outdir == '': |
|
254 outdir = 'help' |
|
255 # that is eric7_docs default QtHelp output dir |
|
256 |
|
257 # add it to the project data, if it isn't in already |
|
258 outdir = project.getRelativePath(outdir) |
|
259 if outdir not in project.pdata['OTHERS']: |
|
260 project.pdata['OTHERS'].append(outdir) |
|
261 project.setDirty(True) |
|
262 project.othersAdded(outdir) |