src/eric7/Plugins/PluginEricapi.py

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

eric ide

mercurial