|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2007 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Ericdoc 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.Ericdoc.EricdocConfigDialog import EricdocConfigDialog |
|
22 from DocumentationPlugins.Ericdoc.EricdocExecDialog import EricdocExecDialog |
|
23 |
|
24 import Utilities |
|
25 |
|
26 # Start-Of-Header |
|
27 name = "Ericdoc Plugin" |
|
28 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
|
29 autoactivate = True |
|
30 deactivateable = True |
|
31 version = "5.0.0" |
|
32 className = "EricdocPlugin" |
|
33 packageName = "__core__" |
|
34 shortDescription = "Show the Ericdoc dialogs." |
|
35 longDescription = """This plugin implements the Ericdoc dialogs.""" \ |
|
36 """ Ericdoc is used to generate a source code documentation""" \ |
|
37 """ for Python and Ruby projects.""" |
|
38 pyqtApi = 2 |
|
39 # End-Of-Header |
|
40 |
|
41 error = "" |
|
42 |
|
43 def exeDisplayData(): |
|
44 """ |
|
45 Public method to support the display of some executable info. |
|
46 |
|
47 @return dictionary containing the data to query the presence of |
|
48 the executable |
|
49 """ |
|
50 exe = 'eric4-doc' |
|
51 if Utilities.isWindowsPlatform(): |
|
52 exe += '.bat' |
|
53 |
|
54 data = { |
|
55 "programEntry" : True, |
|
56 "header" : QApplication.translate("EricdocPlugin", |
|
57 "Eric4 Documentation Generator"), |
|
58 "exe" : exe, |
|
59 "versionCommand" : '--version', |
|
60 "versionStartsWith" : 'eric4-', |
|
61 "versionPosition" : -2, |
|
62 "version" : "", |
|
63 "versionCleanup" : None, |
|
64 } |
|
65 |
|
66 return data |
|
67 |
|
68 class EricdocPlugin(QObject): |
|
69 """ |
|
70 Class implementing the Ericdoc plugin. |
|
71 """ |
|
72 def __init__(self, ui): |
|
73 """ |
|
74 Constructor |
|
75 |
|
76 @param ui reference to the user interface object (UI.UserInterface) |
|
77 """ |
|
78 QObject.__init__(self, ui) |
|
79 self.__ui = ui |
|
80 self.__initialize() |
|
81 |
|
82 def __initialize(self): |
|
83 """ |
|
84 Private slot to (re)initialize the plugin. |
|
85 """ |
|
86 self.__projectAct = None |
|
87 |
|
88 def activate(self): |
|
89 """ |
|
90 Public method to activate this plugin. |
|
91 |
|
92 @return tuple of None and activation status (boolean) |
|
93 """ |
|
94 menu = e4App().getObject("Project").getMenu("Apidoc") |
|
95 if menu: |
|
96 self.__projectAct = \ |
|
97 E4Action(self.trUtf8('Generate documentation (eric4-doc)'), |
|
98 self.trUtf8('Generate &documentation (eric4-doc)'), 0, 0, |
|
99 self, 'doc_eric4_doc') |
|
100 self.__projectAct.setStatusTip(\ |
|
101 self.trUtf8('Generate API documentation using eric4-doc')) |
|
102 self.__projectAct.setWhatsThis(self.trUtf8( |
|
103 """<b>Generate documentation</b>""" |
|
104 """<p>Generate API documentation using eric4-doc.</p>""" |
|
105 )) |
|
106 self.connect(self.__projectAct, SIGNAL('triggered()'), self.__doEricdoc) |
|
107 e4App().getObject("Project").addE4Actions([self.__projectAct]) |
|
108 menu.addAction(self.__projectAct) |
|
109 |
|
110 self.connect(e4App().getObject("Project"), SIGNAL("showMenu"), |
|
111 self.__projectShowMenu) |
|
112 |
|
113 return None, True |
|
114 |
|
115 def deactivate(self): |
|
116 """ |
|
117 Public method to deactivate this plugin. |
|
118 """ |
|
119 self.disconnect(e4App().getObject("Project"), SIGNAL("showMenu"), |
|
120 self.__projectShowMenu) |
|
121 |
|
122 menu = e4App().getObject("Project").getMenu("Apidoc") |
|
123 if menu: |
|
124 menu.removeAction(self.__projectAct) |
|
125 e4App().getObject("Project").removeE4Actions([self.__projectAct]) |
|
126 self.__initialize() |
|
127 |
|
128 def __projectShowMenu(self, menuName, menu): |
|
129 """ |
|
130 Private slot called, when the the project menu or a submenu is |
|
131 about to be shown. |
|
132 |
|
133 @param menuName name of the menu to be shown (string) |
|
134 @param menu reference to the menu (QMenu) |
|
135 """ |
|
136 if menuName == "Apidoc": |
|
137 if self.__projectAct is not None: |
|
138 self.__projectAct.setEnabled(\ |
|
139 e4App().getObject("Project").getProjectLanguage() in \ |
|
140 ["Python", "Python3", "Ruby"]) |
|
141 |
|
142 def __doEricdoc(self): |
|
143 """ |
|
144 Private slot to perform the eric4-doc api documentation generation. |
|
145 """ |
|
146 project = e4App().getObject("Project") |
|
147 parms = project.getData('DOCUMENTATIONPARMS', "ERIC4DOC") |
|
148 dlg = EricdocConfigDialog(project.getProjectPath(), parms) |
|
149 if dlg.exec_() == QDialog.Accepted: |
|
150 args, parms = dlg.generateParameters() |
|
151 project.setData('DOCUMENTATIONPARMS', "ERIC4DOC", parms) |
|
152 |
|
153 # now do the call |
|
154 dia = EricdocExecDialog("Ericdoc") |
|
155 res = dia.start(args, project.ppath) |
|
156 if res: |
|
157 dia.exec_() |
|
158 |
|
159 outdir = parms['outputDirectory'] |
|
160 if outdir == '': |
|
161 outdir = 'doc' # that is eric4-docs default output dir |
|
162 |
|
163 # add it to the project data, if it isn't in already |
|
164 outdir = outdir.replace(project.ppath+os.sep, '') |
|
165 if outdir not in project.pdata['OTHERS']: |
|
166 project.pdata['OTHERS'].append(outdir) |
|
167 project.setDirty(True) |
|
168 project.othersAdded(outdir) |
|
169 |
|
170 if parms['qtHelpEnabled']: |
|
171 outdir = parms['qtHelpOutputDirectory'] |
|
172 if outdir == '': |
|
173 outdir = 'help' # that is eric4-docs default QtHelp output dir |
|
174 |
|
175 # add it to the project data, if it isn't in already |
|
176 outdir = outdir.replace(project.ppath+os.sep, '') |
|
177 if outdir not in project.pdata['OTHERS']: |
|
178 project.pdata['OTHERS'].append(outdir) |
|
179 project.setDirty(True) |
|
180 project.othersAdded(outdir) |