|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2007 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Ericapi 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 = "Ericapi Plugin" |
|
28 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
|
29 autoactivate = True |
|
30 deactivateable = True |
|
31 version = UI.Info.VersionOnly |
|
32 className = "EricapiPlugin" |
|
33 packageName = "__core__" |
|
34 shortDescription = "Show the Ericapi dialogs." |
|
35 longDescription = """This plugin implements the Ericapi dialogs.""" \ |
|
36 """ Ericapi is used to generate a QScintilla API file for Python and""" \ |
|
37 """ Ruby projects.""" |
|
38 pyqtApi = 2 |
|
39 python2Compatible = True |
|
40 # End-Of-Header |
|
41 |
|
42 error = "" |
|
43 |
|
44 |
|
45 def exeDisplayData(): |
|
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 exe = 'eric6_api' |
|
53 if Utilities.isWindowsPlatform(): |
|
54 exe = os.path.join(getConfig("bindir"), exe + '.cmd') |
|
55 if not os.path.exists(exe): |
|
56 exe = os.path.join(getConfig("bindir"), exe + '.bat') |
|
57 else: |
|
58 exe = os.path.join(getConfig("bindir"), exe) |
|
59 |
|
60 data = { |
|
61 "programEntry": True, |
|
62 "header": QCoreApplication.translate( |
|
63 "EricapiPlugin", "Eric6 API File Generator"), |
|
64 "exe": exe, |
|
65 "versionCommand": '--version', |
|
66 "versionStartsWith": 'eric6_', |
|
67 "versionPosition": -3, |
|
68 "version": "", |
|
69 "versionCleanup": None, |
|
70 } |
|
71 |
|
72 return data |
|
73 |
|
74 |
|
75 class EricapiPlugin(QObject): |
|
76 """ |
|
77 Class implementing the Ericapi plugin. |
|
78 """ |
|
79 def __init__(self, ui): |
|
80 """ |
|
81 Constructor |
|
82 |
|
83 @param ui reference to the user interface object (UI.UserInterface) |
|
84 """ |
|
85 super(EricapiPlugin, self).__init__(ui) |
|
86 self.__ui = ui |
|
87 self.__initialize() |
|
88 |
|
89 def __initialize(self): |
|
90 """ |
|
91 Private slot to (re)initialize the plugin. |
|
92 """ |
|
93 self.__projectAct = None |
|
94 |
|
95 def activate(self): |
|
96 """ |
|
97 Public method to activate this plugin. |
|
98 |
|
99 @return tuple of None and activation status (boolean) |
|
100 """ |
|
101 menu = e5App().getObject("Project").getMenu("Apidoc") |
|
102 if menu: |
|
103 self.__projectAct = E5Action( |
|
104 self.tr('Generate API file (eric6_api)'), |
|
105 self.tr('Generate &API file (eric6_api)'), 0, 0, |
|
106 self, 'doc_eric6_api') |
|
107 self.__projectAct.setStatusTip(self.tr( |
|
108 'Generate an API file using eric6_api')) |
|
109 self.__projectAct.setWhatsThis(self.tr( |
|
110 """<b>Generate API file</b>""" |
|
111 """<p>Generate an API file using eric6_api.</p>""" |
|
112 )) |
|
113 self.__projectAct.triggered.connect(self.__doEricapi) |
|
114 e5App().getObject("Project").addE5Actions([self.__projectAct]) |
|
115 menu.addAction(self.__projectAct) |
|
116 |
|
117 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) |
|
118 |
|
119 return None, True |
|
120 |
|
121 def deactivate(self): |
|
122 """ |
|
123 Public method to deactivate this plugin. |
|
124 """ |
|
125 e5App().getObject("Project").showMenu.disconnect( |
|
126 self.__projectShowMenu) |
|
127 |
|
128 menu = e5App().getObject("Project").getMenu("Apidoc") |
|
129 if menu: |
|
130 menu.removeAction(self.__projectAct) |
|
131 e5App().getObject("Project").removeE5Actions([self.__projectAct]) |
|
132 self.__initialize() |
|
133 |
|
134 def __projectShowMenu(self, menuName, menu): |
|
135 """ |
|
136 Private slot called, when the the project menu or a submenu is |
|
137 about to be shown. |
|
138 |
|
139 @param menuName name of the menu to be shown (string) |
|
140 @param menu reference to the menu (QMenu) |
|
141 """ |
|
142 if menuName == "Apidoc": |
|
143 if self.__projectAct is not None: |
|
144 self.__projectAct.setEnabled( |
|
145 e5App().getObject("Project").getProjectLanguage() in |
|
146 ["Python", "Python2", "Python3", "Ruby"]) |
|
147 |
|
148 def __doEricapi(self): |
|
149 """ |
|
150 Private slot to perform the eric6_api api generation. |
|
151 """ |
|
152 from DocumentationPlugins.Ericapi.EricapiConfigDialog import \ |
|
153 EricapiConfigDialog |
|
154 eolTranslation = { |
|
155 '\r': 'cr', |
|
156 '\n': 'lf', |
|
157 '\r\n': 'crlf', |
|
158 } |
|
159 project = e5App().getObject("Project") |
|
160 parms = project.getData('DOCUMENTATIONPARMS', "ERIC4API") |
|
161 dlg = EricapiConfigDialog(project, parms) |
|
162 if dlg.exec_() == QDialog.Accepted: |
|
163 args, parms = dlg.generateParameters() |
|
164 project.setData('DOCUMENTATIONPARMS', "ERIC4API", parms) |
|
165 |
|
166 # add parameter for the eol setting |
|
167 if not project.useSystemEol(): |
|
168 args.append( |
|
169 "--eol={0}".format(eolTranslation[project.getEolString()])) |
|
170 |
|
171 # now do the call |
|
172 from DocumentationPlugins.Ericapi.EricapiExecDialog import \ |
|
173 EricapiExecDialog |
|
174 dia = EricapiExecDialog("Ericapi") |
|
175 res = dia.start(args, project.ppath) |
|
176 if res: |
|
177 dia.exec_() |
|
178 |
|
179 outputFileName = Utilities.toNativeSeparators(parms['outputFile']) |
|
180 |
|
181 # add output files to the project data, if they aren't in already |
|
182 for progLanguage in parms['languages']: |
|
183 if "%L" in outputFileName: |
|
184 outfile = outputFileName.replace("%L", progLanguage) |
|
185 else: |
|
186 if len(parms['languages']) == 1: |
|
187 outfile = outputFileName |
|
188 else: |
|
189 root, ext = os.path.splitext(outputFileName) |
|
190 outfile = "{0}-{1}{2}".format( |
|
191 root, progLanguage.lower(), ext) |
|
192 |
|
193 outfile = project.getRelativePath(outfile) |
|
194 if outfile not in project.pdata['OTHERS']: |
|
195 project.pdata['OTHERS'].append(outfile) |
|
196 project.setDirty(True) |
|
197 project.othersAdded(outfile) |