src/eric7/Plugins/PluginEricapi.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9212
1c5cf2022c7e
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
43 43
44 44
45 def exeDisplayData(): 45 def exeDisplayData():
46 """ 46 """
47 Public method to support the display of some executable info. 47 Public method to support the display of some executable info.
48 48
49 @return dictionary containing the data to query the presence of 49 @return dictionary containing the data to query the presence of
50 the executable 50 the executable
51 """ 51 """
52 exe = 'eric7_api' 52 exe = "eric7_api"
53 if Utilities.isWindowsPlatform(): 53 if Utilities.isWindowsPlatform():
54 for exepath in ( 54 for exepath in (
55 getConfig("bindir"), 55 getConfig("bindir"),
56 os.path.join(sys.exec_prefix, "Scripts"), 56 os.path.join(sys.exec_prefix, "Scripts"),
57 ): 57 ):
71 ): 71 ):
72 exe_ = os.path.join(exepath, exe) 72 exe_ = os.path.join(exepath, exe)
73 if os.path.exists(exe_): 73 if os.path.exists(exe_):
74 exe = exe_ 74 exe = exe_
75 break 75 break
76 76
77 data = { 77 data = {
78 "programEntry": True, 78 "programEntry": True,
79 "header": QCoreApplication.translate( 79 "header": QCoreApplication.translate(
80 "EricapiPlugin", "eric API File Generator"), 80 "EricapiPlugin", "eric API File Generator"
81 ),
81 "exe": exe, 82 "exe": exe,
82 "versionCommand": '--version', 83 "versionCommand": "--version",
83 "versionStartsWith": 'eric7_', 84 "versionStartsWith": "eric7_",
84 "versionPosition": -3, 85 "versionPosition": -3,
85 "version": "", 86 "version": "",
86 "versionCleanup": None, 87 "versionCleanup": None,
87 } 88 }
88 89
89 return data 90 return data
90 91
91 92
92 class EricapiPlugin(QObject): 93 class EricapiPlugin(QObject):
93 """ 94 """
94 Class implementing the Ericapi plugin. 95 Class implementing the Ericapi plugin.
95 """ 96 """
97
96 def __init__(self, ui): 98 def __init__(self, ui):
97 """ 99 """
98 Constructor 100 Constructor
99 101
100 @param ui reference to the user interface object (UI.UserInterface) 102 @param ui reference to the user interface object (UI.UserInterface)
101 """ 103 """
102 super().__init__(ui) 104 super().__init__(ui)
103 self.__ui = ui 105 self.__ui = ui
104 self.__initialize() 106 self.__initialize()
105 107
106 def __initialize(self): 108 def __initialize(self):
107 """ 109 """
108 Private slot to (re)initialize the plugin. 110 Private slot to (re)initialize the plugin.
109 """ 111 """
110 self.__projectAct = None 112 self.__projectAct = None
111 113
112 def activate(self): 114 def activate(self):
113 """ 115 """
114 Public method to activate this plugin. 116 Public method to activate this plugin.
115 117
116 @return tuple of None and activation status (boolean) 118 @return tuple of None and activation status (boolean)
117 """ 119 """
118 menu = ericApp().getObject("Project").getMenu("Apidoc") 120 menu = ericApp().getObject("Project").getMenu("Apidoc")
119 if menu: 121 if menu:
120 self.__projectAct = EricAction( 122 self.__projectAct = EricAction(
121 self.tr('Generate API file (eric7_api)'), 123 self.tr("Generate API file (eric7_api)"),
122 self.tr('Generate &API file (eric7_api)'), 0, 0, 124 self.tr("Generate &API file (eric7_api)"),
123 self, 'doc_eric7_api') 125 0,
124 self.__projectAct.setStatusTip(self.tr( 126 0,
125 'Generate an API file using eric7_api')) 127 self,
126 self.__projectAct.setWhatsThis(self.tr( 128 "doc_eric7_api",
127 """<b>Generate API file</b>""" 129 )
128 """<p>Generate an API file using eric7_api.</p>""" 130 self.__projectAct.setStatusTip(
129 )) 131 self.tr("Generate an API file using eric7_api")
132 )
133 self.__projectAct.setWhatsThis(
134 self.tr(
135 """<b>Generate API file</b>"""
136 """<p>Generate an API file using eric7_api.</p>"""
137 )
138 )
130 self.__projectAct.triggered.connect(self.__doEricapi) 139 self.__projectAct.triggered.connect(self.__doEricapi)
131 ericApp().getObject("Project").addEricActions([self.__projectAct]) 140 ericApp().getObject("Project").addEricActions([self.__projectAct])
132 menu.addAction(self.__projectAct) 141 menu.addAction(self.__projectAct)
133 142
134 ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu) 143 ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu)
135 144
136 return None, True 145 return None, True
137 146
138 def deactivate(self): 147 def deactivate(self):
139 """ 148 """
140 Public method to deactivate this plugin. 149 Public method to deactivate this plugin.
141 """ 150 """
142 ericApp().getObject("Project").showMenu.disconnect( 151 ericApp().getObject("Project").showMenu.disconnect(self.__projectShowMenu)
143 self.__projectShowMenu) 152
144
145 menu = ericApp().getObject("Project").getMenu("Apidoc") 153 menu = ericApp().getObject("Project").getMenu("Apidoc")
146 if menu: 154 if menu:
147 menu.removeAction(self.__projectAct) 155 menu.removeAction(self.__projectAct)
148 ericApp().getObject("Project").removeEricActions( 156 ericApp().getObject("Project").removeEricActions([self.__projectAct])
149 [self.__projectAct])
150 self.__initialize() 157 self.__initialize()
151 158
152 def __projectShowMenu(self, menuName, menu): 159 def __projectShowMenu(self, menuName, menu):
153 """ 160 """
154 Private slot called, when the the project menu or a submenu is 161 Private slot called, when the the project menu or a submenu is
155 about to be shown. 162 about to be shown.
156 163
157 @param menuName name of the menu to be shown (string) 164 @param menuName name of the menu to be shown (string)
158 @param menu reference to the menu (QMenu) 165 @param menu reference to the menu (QMenu)
159 """ 166 """
160 if menuName == "Apidoc" and self.__projectAct is not None: 167 if menuName == "Apidoc" and self.__projectAct is not None:
161 self.__projectAct.setEnabled( 168 self.__projectAct.setEnabled(
162 ericApp().getObject("Project").getProjectLanguage() in 169 ericApp().getObject("Project").getProjectLanguage()
163 ["Python", "Python3", "Ruby", "MicroPython"]) 170 in ["Python", "Python3", "Ruby", "MicroPython"]
164 171 )
172
165 def __doEricapi(self): 173 def __doEricapi(self):
166 """ 174 """
167 Private slot to perform the eric7_api api generation. 175 Private slot to perform the eric7_api api generation.
168 """ 176 """
169 from DocumentationPlugins.Ericapi.EricapiConfigDialog import ( 177 from DocumentationPlugins.Ericapi.EricapiConfigDialog import EricapiConfigDialog
170 EricapiConfigDialog 178
171 )
172 eolTranslation = { 179 eolTranslation = {
173 '\r': 'cr', 180 "\r": "cr",
174 '\n': 'lf', 181 "\n": "lf",
175 '\r\n': 'crlf', 182 "\r\n": "crlf",
176 } 183 }
177 project = ericApp().getObject("Project") 184 project = ericApp().getObject("Project")
178 parms = project.getData('DOCUMENTATIONPARMS', "ERIC4API") 185 parms = project.getData("DOCUMENTATIONPARMS", "ERIC4API")
179 dlg = EricapiConfigDialog(project, parms) 186 dlg = EricapiConfigDialog(project, parms)
180 if dlg.exec() == QDialog.DialogCode.Accepted: 187 if dlg.exec() == QDialog.DialogCode.Accepted:
181 args, parms, startDir = dlg.generateParameters() 188 args, parms, startDir = dlg.generateParameters()
182 project.setData('DOCUMENTATIONPARMS', "ERIC4API", parms) 189 project.setData("DOCUMENTATIONPARMS", "ERIC4API", parms)
183 190
184 if not startDir: 191 if not startDir:
185 startDir = project.ppath 192 startDir = project.ppath
186 193
187 # add parameter for the eol setting 194 # add parameter for the eol setting
188 if not project.useSystemEol(): 195 if not project.useSystemEol():
189 args.append( 196 args.append("--eol={0}".format(eolTranslation[project.getEolString()]))
190 "--eol={0}".format(eolTranslation[project.getEolString()])) 197
191
192 # now do the call 198 # now do the call
193 from DocumentationPlugins.Ericapi.EricapiExecDialog import ( 199 from DocumentationPlugins.Ericapi.EricapiExecDialog import EricapiExecDialog
194 EricapiExecDialog 200
195 )
196 dia = EricapiExecDialog("Ericapi") 201 dia = EricapiExecDialog("Ericapi")
197 res = dia.start(args, startDir) 202 res = dia.start(args, startDir)
198 if res: 203 if res:
199 dia.exec() 204 dia.exec()
200 205
201 outputFileName = Utilities.toNativeSeparators(parms['outputFile']) 206 outputFileName = Utilities.toNativeSeparators(parms["outputFile"])
202 207
203 # add output files to the project data, if they aren't in already 208 # add output files to the project data, if they aren't in already
204 for progLanguage in parms['languages']: 209 for progLanguage in parms["languages"]:
205 if "%L" in outputFileName: 210 if "%L" in outputFileName:
206 outfile = outputFileName.replace("%L", progLanguage) 211 outfile = outputFileName.replace("%L", progLanguage)
207 else: 212 else:
208 if len(parms['languages']) == 1: 213 if len(parms["languages"]) == 1:
209 outfile = outputFileName 214 outfile = outputFileName
210 else: 215 else:
211 root, ext = os.path.splitext(outputFileName) 216 root, ext = os.path.splitext(outputFileName)
212 outfile = "{0}-{1}{2}".format( 217 outfile = "{0}-{1}{2}".format(root, progLanguage.lower(), ext)
213 root, progLanguage.lower(), ext) 218
214
215 outfile = project.getRelativePath(outfile) 219 outfile = project.getRelativePath(outfile)
216 if outfile not in project.pdata['OTHERS']: 220 if outfile not in project.pdata["OTHERS"]:
217 project.pdata['OTHERS'].append(outfile) 221 project.pdata["OTHERS"].append(outfile)
218 project.setDirty(True) 222 project.setDirty(True)
219 project.othersAdded(outfile) 223 project.othersAdded(outfile)

eric ide

mercurial