|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2007 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Ericapi plugin. |
|
8 """ |
|
9 |
|
10 import os |
|
11 import sys |
|
12 import copy |
|
13 |
|
14 from PyQt4.QtCore import QObject, SIGNAL |
|
15 from PyQt4.QtGui import QDialog, QApplication |
|
16 |
|
17 from E4Gui.E4Application import e4App |
|
18 |
|
19 from E4Gui.E4Action import E4Action |
|
20 |
|
21 from DocumentationPlugins.Ericapi.EricapiConfigDialog import EricapiConfigDialog |
|
22 from DocumentationPlugins.Ericapi.EricapiExecDialog import EricapiExecDialog |
|
23 |
|
24 import Utilities |
|
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 = "5.0.0" |
|
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 Ruby projects.""" |
|
37 pyqtApi = 2 |
|
38 # End-Of-Header |
|
39 |
|
40 error = "" |
|
41 |
|
42 def exeDisplayData(): |
|
43 """ |
|
44 Public method to support the display of some executable info. |
|
45 |
|
46 @return dictionary containing the data to query the presence of |
|
47 the executable |
|
48 """ |
|
49 exe = 'eric4-api' |
|
50 if Utilities.isWindowsPlatform(): |
|
51 exe += '.bat' |
|
52 |
|
53 data = { |
|
54 "programEntry" : True, |
|
55 "header" : QApplication.translate("EricapiPlugin", |
|
56 "Eric4 API File Generator"), |
|
57 "exe" : exe, |
|
58 "versionCommand" : '--version', |
|
59 "versionStartsWith" : 'eric4-', |
|
60 "versionPosition" : -2, |
|
61 "version" : "", |
|
62 "versionCleanup" : None, |
|
63 } |
|
64 |
|
65 return data |
|
66 |
|
67 class EricapiPlugin(QObject): |
|
68 """ |
|
69 Class implementing the Ericapi plugin. |
|
70 """ |
|
71 def __init__(self, ui): |
|
72 """ |
|
73 Constructor |
|
74 |
|
75 @param ui reference to the user interface object (UI.UserInterface) |
|
76 """ |
|
77 QObject.__init__(self, ui) |
|
78 self.__ui = ui |
|
79 self.__initialize() |
|
80 |
|
81 def __initialize(self): |
|
82 """ |
|
83 Private slot to (re)initialize the plugin. |
|
84 """ |
|
85 self.__projectAct = None |
|
86 |
|
87 def activate(self): |
|
88 """ |
|
89 Public method to activate this plugin. |
|
90 |
|
91 @return tuple of None and activation status (boolean) |
|
92 """ |
|
93 menu = e4App().getObject("Project").getMenu("Apidoc") |
|
94 if menu: |
|
95 self.__projectAct = E4Action(self.trUtf8('Generate API file (eric4-api)'), |
|
96 self.trUtf8('Generate &API file (eric4-api)'), 0, 0, |
|
97 self, 'doc_eric4_api') |
|
98 self.__projectAct.setStatusTip(\ |
|
99 self.trUtf8('Generate an API file using eric4-api')) |
|
100 self.__projectAct.setWhatsThis(self.trUtf8( |
|
101 """<b>Generate API file</b>""" |
|
102 """<p>Generate an API file using eric4-api.</p>""" |
|
103 )) |
|
104 self.connect(self.__projectAct, SIGNAL('triggered()'), self.__doEricapi) |
|
105 e4App().getObject("Project").addE4Actions([self.__projectAct]) |
|
106 menu.addAction(self.__projectAct) |
|
107 |
|
108 self.connect(e4App().getObject("Project"), SIGNAL("showMenu"), |
|
109 self.__projectShowMenu) |
|
110 |
|
111 return None, True |
|
112 |
|
113 def deactivate(self): |
|
114 """ |
|
115 Public method to deactivate this plugin. |
|
116 """ |
|
117 self.disconnect(e4App().getObject("Project"), SIGNAL("showMenu"), |
|
118 self.__projectShowMenu) |
|
119 |
|
120 menu = e4App().getObject("Project").getMenu("Apidoc") |
|
121 if menu: |
|
122 menu.removeAction(self.__projectAct) |
|
123 e4App().getObject("Project").removeE4Actions([self.__projectAct]) |
|
124 self.__initialize() |
|
125 |
|
126 def __projectShowMenu(self, menuName, menu): |
|
127 """ |
|
128 Private slot called, when the the project menu or a submenu is |
|
129 about to be shown. |
|
130 |
|
131 @param menuName name of the menu to be shown (string) |
|
132 @param menu reference to the menu (QMenu) |
|
133 """ |
|
134 if menuName == "Apidoc": |
|
135 if self.__projectAct is not None: |
|
136 self.__projectAct.setEnabled(\ |
|
137 e4App().getObject("Project").getProjectLanguage() in \ |
|
138 ["Python", "Python3", "Ruby"]) |
|
139 |
|
140 def __doEricapi(self): |
|
141 """ |
|
142 Private slot to perform the eric4-api api generation. |
|
143 """ |
|
144 project = e4App().getObject("Project") |
|
145 parms = project.getData('DOCUMENTATIONPARMS', "ERIC4API") |
|
146 dlg = EricapiConfigDialog(project, parms) |
|
147 if dlg.exec_() == QDialog.Accepted: |
|
148 args, parms = dlg.generateParameters() |
|
149 project.setData('DOCUMENTATIONPARMS', "ERIC4API", parms) |
|
150 |
|
151 # now do the call |
|
152 dia = EricapiExecDialog("Ericapi") |
|
153 res = dia.start(args, project.ppath) |
|
154 if res: |
|
155 dia.exec_() |
|
156 |
|
157 outputFileName = parms['outputFile'] |
|
158 |
|
159 # add output files to the project data, if they aren't in already |
|
160 for progLanguage in parms['languages']: |
|
161 if "%L" in outputFileName: |
|
162 outfile = outputFileName.replace("%L", progLanguage) |
|
163 else: |
|
164 if len(progLanguages) == 1: |
|
165 outfile = outputFileName |
|
166 else: |
|
167 root, ext = os.path.splitext(outputFileName) |
|
168 outfile = "%s-%s%s" % (root, progLanguage.lower(), ext) |
|
169 |
|
170 outfile = outfile.replace(project.ppath+os.sep, '') |
|
171 if outfile not in project.pdata['OTHERS']: |
|
172 project.pdata['OTHERS'].append(outfile) |
|
173 project.setDirty(True) |
|
174 project.othersAdded(outfile) |