|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the parameters for eric4-doc. |
|
8 """ |
|
9 |
|
10 import sys |
|
11 import os |
|
12 import copy |
|
13 |
|
14 from PyQt4.QtCore import * |
|
15 from PyQt4.QtGui import * |
|
16 |
|
17 from E4Gui.E4Completers import E4DirCompleter |
|
18 |
|
19 from Ui_EricdocConfigDialog import Ui_EricdocConfigDialog |
|
20 from DocumentationTools.Config import eric4docDefaultColors, eric4docColorParameterNames |
|
21 import Utilities |
|
22 |
|
23 from eric4config import getConfig |
|
24 |
|
25 class EricdocConfigDialog(QDialog, Ui_EricdocConfigDialog): |
|
26 """ |
|
27 Class implementing a dialog to enter the parameters for eric4-doc. |
|
28 """ |
|
29 def __init__(self, ppath, parms = None, parent = None): |
|
30 """ |
|
31 Constructor |
|
32 |
|
33 @param ppath project path of the current project (string) |
|
34 @param parms parameters to set in the dialog |
|
35 @param parent parent widget of this dialog |
|
36 """ |
|
37 QDialog.__init__(self,parent) |
|
38 self.setupUi(self) |
|
39 |
|
40 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
|
41 |
|
42 self.__initializeDefaults() |
|
43 |
|
44 self.sampleText = self.trUtf8(\ |
|
45 '''<?xml version="1.0" encoding="utf-8"?>''' |
|
46 '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"''' |
|
47 '''"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">''' |
|
48 '''<html><head>''' |
|
49 '''<title>%%(Title)s</title>''' |
|
50 '''</head>''' |
|
51 '''<body style="background-color:%(BodyBgColor)s;color:%(BodyColor)s">''' |
|
52 '''<h1 style="background-color:%(Level1HeaderBgColor)s;color:%(Level1HeaderColor)s">''' |
|
53 '''Level 1 Header</h1>''' |
|
54 '''<h3 style="background-color:%(Level2HeaderBgColor)s;color:%(Level2HeaderColor)s">''' |
|
55 '''Level 2 Header</h3>''' |
|
56 '''<h2 style="background-color:%(CFBgColor)s;color:%(CFColor)s">''' |
|
57 '''Class and Function Header</h2>''' |
|
58 '''Standard body text with ''' |
|
59 '''<a style="color:%(LinkColor)s">some links</a> embedded.''' |
|
60 '''</body></html>''' |
|
61 ) |
|
62 |
|
63 # get a copy of the defaults to store the user settings |
|
64 self.parameters = copy.deepcopy(self.defaults) |
|
65 self.colors = eric4docDefaultColors.copy() |
|
66 |
|
67 # combine it with the values of parms |
|
68 if parms is not None: |
|
69 for key, value in parms.items(): |
|
70 if key.endswith("Color"): |
|
71 self.colors[key] = parms[key] |
|
72 else: |
|
73 self.parameters[key] = parms[key] |
|
74 |
|
75 self.ppath = ppath |
|
76 |
|
77 self.outputDirCompleter = E4DirCompleter(self.outputDirEdit) |
|
78 self.ignoreDirCompleter = E4DirCompleter(self.ignoreDirEdit) |
|
79 self.qtHelpDirCompleter = E4DirCompleter(self.qtHelpDirEdit) |
|
80 |
|
81 self.recursionCheckBox.setChecked(self.parameters['useRecursion']) |
|
82 self.noindexCheckBox.setChecked(self.parameters['noindex']) |
|
83 self.noemptyCheckBox.setChecked(self.parameters['noempty']) |
|
84 self.outputDirEdit.setText(self.parameters['outputDirectory']) |
|
85 self.ignoreDirsList.clear() |
|
86 for d in self.parameters['ignoreDirectories']: |
|
87 self.ignoreDirsList.addItem(d) |
|
88 self.cssEdit.setText(self.parameters['cssFile']) |
|
89 self.sourceExtEdit.setText(", ".join(self.parameters['sourceExtensions'])) |
|
90 self.excludeFilesEdit.setText(", ".join(self.parameters['ignoreFilePatterns'])) |
|
91 self.sample.setHtml(self.sampleText % self.colors) |
|
92 |
|
93 self.qtHelpGroup.setChecked(self.parameters['qtHelpEnabled']) |
|
94 self.qtHelpDirEdit.setText(self.parameters['qtHelpOutputDirectory']) |
|
95 self.qtHelpNamespaceEdit.setText(self.parameters['qtHelpNamespace']) |
|
96 self.qtHelpFolderEdit.setText(self.parameters['qtHelpVirtualFolder']) |
|
97 self.qtHelpFilterNameEdit.setText(self.parameters['qtHelpFilterName']) |
|
98 self.qtHelpFilterAttributesEdit.setText(self.parameters['qtHelpFilterAttributes']) |
|
99 self.qtHelpTitleEdit.setText(self.parameters['qtHelpTitle']) |
|
100 self.qtHelpGenerateCollectionCheckBox.setChecked( |
|
101 self.parameters['qtHelpCreateCollection']) |
|
102 |
|
103 def __initializeDefaults(self): |
|
104 """ |
|
105 Private method to set the default values. |
|
106 |
|
107 These are needed later on to generate the commandline |
|
108 parameters. |
|
109 """ |
|
110 self.defaults = { |
|
111 'useRecursion' : 0, |
|
112 'noindex' : 0, |
|
113 'noempty' : 0, |
|
114 'outputDirectory' : '', |
|
115 'ignoreDirectories' : [], |
|
116 'ignoreFilePatterns' : [], |
|
117 'cssFile' : '', |
|
118 'sourceExtensions' : [], |
|
119 |
|
120 'qtHelpEnabled' : False, |
|
121 'qtHelpOutputDirectory' : '', |
|
122 'qtHelpNamespace' : '', |
|
123 'qtHelpVirtualFolder' : 'source', |
|
124 'qtHelpFilterName' : 'unknown', |
|
125 'qtHelpFilterAttributes' : '', |
|
126 'qtHelpTitle' : '', |
|
127 'qtHelpCreateCollection' : False, |
|
128 } |
|
129 |
|
130 def generateParameters(self): |
|
131 """ |
|
132 Public method that generates the commandline parameters. |
|
133 |
|
134 It generates a list of strings to be used |
|
135 to set the QProcess arguments for the ericdoc call and |
|
136 a dictionary containing the non default parameters. This |
|
137 dictionary can be passed back upon object generation to overwrite |
|
138 the default settings. |
|
139 |
|
140 @return a tuple of the commandline parameters and non default parameters |
|
141 (list of strings, dictionary) |
|
142 """ |
|
143 parms = {} |
|
144 args = [] |
|
145 |
|
146 # 1. the program name |
|
147 args.append(sys.executable) |
|
148 args.append(Utilities.normabsjoinpath(getConfig('ericDir'), "eric4-doc.py")) |
|
149 |
|
150 # 2. the commandline options |
|
151 # 2a. general commandline options |
|
152 if self.parameters['outputDirectory'] != self.defaults['outputDirectory']: |
|
153 parms['outputDirectory'] = self.parameters['outputDirectory'] |
|
154 args.append('-o') |
|
155 if os.path.isabs(self.parameters['outputDirectory']): |
|
156 args.append(self.parameters['outputDirectory']) |
|
157 else: |
|
158 args.append(os.path.join(self.ppath, self.parameters['outputDirectory'])) |
|
159 if self.parameters['ignoreDirectories'] != self.defaults['ignoreDirectories']: |
|
160 parms['ignoreDirectories'] = self.parameters['ignoreDirectories'][:] |
|
161 for d in self.parameters['ignoreDirectories']: |
|
162 args.append('-x') |
|
163 args.append(d) |
|
164 if self.parameters['ignoreFilePatterns'] != self.defaults['ignoreFilePatterns']: |
|
165 parms['ignoreFilePatterns'] = self.parameters['ignoreFilePatterns'][:] |
|
166 for pattern in self.parameters['ignoreFilePatterns']: |
|
167 args.append("--exclude-file=%s" % pattern) |
|
168 if self.parameters['useRecursion'] != self.defaults['useRecursion']: |
|
169 parms['useRecursion'] = self.parameters['useRecursion'] |
|
170 args.append('-r') |
|
171 if self.parameters['noindex'] != self.defaults['noindex']: |
|
172 parms['noindex'] = self.parameters['noindex'] |
|
173 args.append('-i') |
|
174 if self.parameters['noempty'] != self.defaults['noempty']: |
|
175 parms['noempty'] = self.parameters['noempty'] |
|
176 args.append('-e') |
|
177 if self.parameters['sourceExtensions'] != self.defaults['sourceExtensions']: |
|
178 parms['sourceExtensions'] = self.parameters['sourceExtensions'][:] |
|
179 for ext in self.parameters['sourceExtensions']: |
|
180 args.append('-t') |
|
181 args.append(ext) |
|
182 |
|
183 # 2b. style commandline options |
|
184 if self.parameters['cssFile'] != self.defaults['cssFile']: |
|
185 parms['cssFile'] = self.parameters['cssFile'] |
|
186 args.append('-c') |
|
187 if os.path.isabs(self.parameters['cssFile']): |
|
188 args.append(self.parameters['cssFile']) |
|
189 else: |
|
190 args.append(os.path.join(self.ppath, self.parameters['cssFile'])) |
|
191 for key, value in self.colors.items(): |
|
192 if self.colors[key] != eric4docDefaultColors[key]: |
|
193 parms[key] = self.colors[key] |
|
194 args.append("--%s=%s" % \ |
|
195 (eric4docColorParameterNames[key], self.colors[key])) |
|
196 |
|
197 # 2c. QtHelp commandline options |
|
198 parms['qtHelpEnabled'] = self.parameters['qtHelpEnabled'] |
|
199 if self.parameters['qtHelpEnabled']: |
|
200 args.append('--create-qhp') |
|
201 if self.parameters['qtHelpOutputDirectory'] != \ |
|
202 self.defaults['qtHelpOutputDirectory']: |
|
203 parms['qtHelpOutputDirectory'] = self.parameters['qtHelpOutputDirectory'] |
|
204 if os.path.isabs(self.parameters['outputDirectory']): |
|
205 args.append("--qhp-outdir=%s" % self.parameters['qtHelpOutputDirectory']) |
|
206 else: |
|
207 args.append("--qhp-outdir=%s" % \ |
|
208 os.path.join(self.ppath, self.parameters['qtHelpOutputDirectory'])) |
|
209 if self.parameters['qtHelpNamespace'] != self.defaults['qtHelpNamespace']: |
|
210 parms['qtHelpNamespace'] = self.parameters['qtHelpNamespace'] |
|
211 args.append("--qhp-namespace=%s" % self.parameters['qtHelpNamespace']) |
|
212 if self.parameters['qtHelpVirtualFolder'] != self.defaults['qtHelpVirtualFolder']: |
|
213 parms['qtHelpVirtualFolder'] = self.parameters['qtHelpVirtualFolder'] |
|
214 args.append("--qhp-virtualfolder=%s" % self.parameters['qtHelpVirtualFolder']) |
|
215 if self.parameters['qtHelpFilterName'] != self.defaults['qtHelpFilterName']: |
|
216 parms['qtHelpFilterName'] = self.parameters['qtHelpFilterName'] |
|
217 args.append("--qhp-filtername=%s" % self.parameters['qtHelpFilterName']) |
|
218 if self.parameters['qtHelpFilterAttributes'] != \ |
|
219 self.defaults['qtHelpFilterAttributes']: |
|
220 parms['qtHelpFilterAttributes'] = self.parameters['qtHelpFilterAttributes'] |
|
221 args.append("--qhp-filterattribs=%s" % \ |
|
222 self.parameters['qtHelpFilterAttributes']) |
|
223 if self.parameters['qtHelpTitle'] != self.defaults['qtHelpTitle']: |
|
224 parms['qtHelpTitle'] = self.parameters['qtHelpTitle'] |
|
225 args.append("--qhp-title=%s" % self.parameters['qtHelpTitle']) |
|
226 if self.parameters['qtHelpCreateCollection'] != \ |
|
227 self.defaults['qtHelpCreateCollection']: |
|
228 parms['qtHelpCreateCollection'] = self.parameters['qtHelpCreateCollection'] |
|
229 args.append('--create-qhc') |
|
230 |
|
231 return (args, parms) |
|
232 |
|
233 @pyqtSlot() |
|
234 def on_outputDirButton_clicked(self): |
|
235 """ |
|
236 Private slot to select the output directory. |
|
237 |
|
238 It displays a directory selection dialog to |
|
239 select the directory the documentations is written to. |
|
240 """ |
|
241 directory = QFileDialog.getExistingDirectory(\ |
|
242 self, |
|
243 self.trUtf8("Select output directory"), |
|
244 self.outputDirEdit.text(), |
|
245 QFileDialog.Options(QFileDialog.ShowDirsOnly)) |
|
246 |
|
247 if directory: |
|
248 # make it relative, if it is a subdirectory of the project path |
|
249 dn = Utilities.toNativeSeparators(directory) |
|
250 dn = dn.replace(self.ppath + os.sep, '') |
|
251 while dn.endswith(os.sep): |
|
252 dn = dn[:-1] |
|
253 self.outputDirEdit.setText(dn) |
|
254 |
|
255 @pyqtSlot() |
|
256 def on_ignoreDirButton_clicked(self): |
|
257 """ |
|
258 Private slot to select a directory to be ignored. |
|
259 |
|
260 It displays a directory selection dialog to |
|
261 select a directory to be ignored. |
|
262 """ |
|
263 startDir = self.ignoreDirEdit.text() |
|
264 if not startDir: |
|
265 startDir = self.ppath |
|
266 directory = QFileDialog.getExistingDirectory(\ |
|
267 self, |
|
268 self.trUtf8("Select directory to exclude"), |
|
269 startDir, |
|
270 QFileDialog.Options(QFileDialog.ShowDirsOnly)) |
|
271 |
|
272 if directory: |
|
273 # make it relative, if it is a subdirectory of the project path |
|
274 dn = Utilities.toNativeSeparators(directory) |
|
275 dn = dn.replace(self.ppath + os.sep, '') |
|
276 while dn.endswith(os.sep): |
|
277 dn = dn[:-1] |
|
278 self.ignoreDirEdit.setText(dn) |
|
279 |
|
280 @pyqtSlot() |
|
281 def on_addButton_clicked(self): |
|
282 """ |
|
283 Private slot to add the directory displayed to the listview. |
|
284 |
|
285 The directory in the ignore directories |
|
286 line edit is moved to the listbox above and the edit is cleared. |
|
287 """ |
|
288 self.ignoreDirsList.addItem(os.path.basename(self.ignoreDirEdit.text())) |
|
289 self.ignoreDirEdit.clear() |
|
290 |
|
291 @pyqtSlot() |
|
292 def on_deleteButton_clicked(self): |
|
293 """ |
|
294 Private slot to delete the currently selected directory of the listbox. |
|
295 """ |
|
296 itm = self.ignoreDirsList.takeItem(self.ignoreDirsList.currentRow()) |
|
297 del itm |
|
298 |
|
299 @pyqtSlot() |
|
300 def on_cssButton_clicked(self): |
|
301 """ |
|
302 Private slot to select a css style sheet. |
|
303 """ |
|
304 cssFile = QFileDialog.getOpenFileName(\ |
|
305 self, |
|
306 self.trUtf8("Select CSS style sheet"), |
|
307 getConfig('ericCSSDir'), |
|
308 self.trUtf8("Style sheet (*.css);;All files (*)")) |
|
309 |
|
310 if cssFile: |
|
311 # make it relative, if it is in a subdirectory of the project path |
|
312 cf = Utilities.toNativeSeparators(cssFile) |
|
313 cf = cf.replace(self.ppath + os.sep, '') |
|
314 self.cssEdit.setText(cf) |
|
315 |
|
316 def __selectColor(self, colorKey): |
|
317 """ |
|
318 Private method to select a color. |
|
319 |
|
320 @param colorKey key of the color to select (string) |
|
321 """ |
|
322 color = QColorDialog.getColor(QColor(self.colors[colorKey])) |
|
323 if color.isValid(): |
|
324 self.colors[colorKey] = color.name() |
|
325 self.sample.setHtml(self.sampleText % self.colors) |
|
326 |
|
327 @pyqtSlot() |
|
328 def on_bodyFgButton_clicked(self): |
|
329 """ |
|
330 Private slot to select the body foreground color. |
|
331 """ |
|
332 self.__selectColor('BodyColor') |
|
333 |
|
334 @pyqtSlot() |
|
335 def on_bodyBgButton_clicked(self): |
|
336 """ |
|
337 Private slot to select the body background color. |
|
338 """ |
|
339 self.__selectColor('BodyBgColor') |
|
340 |
|
341 @pyqtSlot() |
|
342 def on_l1FgButton_clicked(self): |
|
343 """ |
|
344 Private slot to select the level 1 header foreground color. |
|
345 """ |
|
346 self.__selectColor('Level1HeaderColor') |
|
347 |
|
348 @pyqtSlot() |
|
349 def on_l1BgButton_clicked(self): |
|
350 """ |
|
351 Private slot to select the level 1 header background color. |
|
352 """ |
|
353 self.__selectColor('Level1HeaderBgColor') |
|
354 |
|
355 @pyqtSlot() |
|
356 def on_l2FgButton_clicked(self): |
|
357 """ |
|
358 Private slot to select the level 2 header foreground color. |
|
359 """ |
|
360 self.__selectColor('Level2HeaderColor') |
|
361 |
|
362 @pyqtSlot() |
|
363 def on_l2BgButton_clicked(self): |
|
364 """ |
|
365 Private slot to select the level 2 header background color. |
|
366 """ |
|
367 self.__selectColor('Level2HeaderBgColor') |
|
368 |
|
369 @pyqtSlot() |
|
370 def on_cfFgButton_clicked(self): |
|
371 """ |
|
372 Private slot to select the class/function header foreground color. |
|
373 """ |
|
374 self.__selectColor('CFColor') |
|
375 |
|
376 @pyqtSlot() |
|
377 def on_cfBgButton_clicked(self): |
|
378 """ |
|
379 Private slot to select the class/function header background color. |
|
380 """ |
|
381 self.__selectColor('CFBgColor') |
|
382 |
|
383 @pyqtSlot() |
|
384 def on_linkFgButton_clicked(self): |
|
385 """ |
|
386 Private slot to select the foreground color of links. |
|
387 """ |
|
388 self.__selectColor('LinkColor') |
|
389 |
|
390 def __checkQtHelpOptions(self): |
|
391 """ |
|
392 Private slot to check the QtHelp options and set the ok button accordingly. |
|
393 """ |
|
394 setOn = True |
|
395 if self.qtHelpGroup.isChecked(): |
|
396 if not self.qtHelpNamespaceEdit.text(): |
|
397 setOn = False |
|
398 if not self.qtHelpFolderEdit.text(): |
|
399 setOn = False |
|
400 else: |
|
401 if '/' in self.qtHelpFolderEdit.text(): |
|
402 setOn = False |
|
403 if not self.qtHelpTitleEdit.text(): |
|
404 setOn = False |
|
405 |
|
406 self.__okButton.setEnabled(setOn) |
|
407 |
|
408 @pyqtSlot(bool) |
|
409 def on_qtHelpGroup_toggled(self, enabled): |
|
410 """ |
|
411 Private slot to toggle the generation of QtHelp files. |
|
412 |
|
413 @param enabled flag indicating the state (boolean) |
|
414 """ |
|
415 self.__checkQtHelpOptions() |
|
416 |
|
417 @pyqtSlot(str) |
|
418 def on_qtHelpNamespaceEdit_textChanged(self, txt): |
|
419 """ |
|
420 Private slot to check the namespace. |
|
421 |
|
422 @param txt text of the line edit (string) |
|
423 """ |
|
424 self.__checkQtHelpOptions() |
|
425 |
|
426 @pyqtSlot(str) |
|
427 def on_qtHelpFolderEdit_textChanged(self, txt): |
|
428 """ |
|
429 Private slot to check the virtual folder. |
|
430 |
|
431 @param txt text of the line edit (string) |
|
432 """ |
|
433 self.__checkQtHelpOptions() |
|
434 |
|
435 @pyqtSlot(str) |
|
436 def on_qtHelpTitleEdit_textChanged(self, p0): |
|
437 """ |
|
438 Private slot to check the title. |
|
439 |
|
440 @param txt text of the line edit (string) |
|
441 """ |
|
442 self.__checkQtHelpOptions() |
|
443 |
|
444 @pyqtSlot() |
|
445 def on_qtHelpDirButton_clicked(self): |
|
446 """ |
|
447 Private slot to select the output directory for the QtHelp files. |
|
448 |
|
449 It displays a directory selection dialog to |
|
450 select the directory the QtHelp files are written to. |
|
451 """ |
|
452 directory = QFileDialog.getExistingDirectory(\ |
|
453 self, |
|
454 self.trUtf8("Select output directory for QtHelp files"), |
|
455 self.qtHelpDirEdit.text(), |
|
456 QFileDialog.Options(QFileDialog.ShowDirsOnly)) |
|
457 |
|
458 if directory: |
|
459 # make it relative, if it is a subdirectory of the project path |
|
460 dn = Utilities.toNativeSeparators(directory) |
|
461 dn = dn.replace(self.ppath + os.sep, '') |
|
462 while dn.endswith(os.sep): |
|
463 dn = dn[:-1] |
|
464 self.qtHelpDirEdit.setText(dn) |
|
465 |
|
466 def accept(self): |
|
467 """ |
|
468 Protected slot called by the Ok button. |
|
469 |
|
470 It saves the values in the parameters dictionary. |
|
471 """ |
|
472 self.parameters['useRecursion'] = self.recursionCheckBox.isChecked() |
|
473 self.parameters['noindex'] = self.noindexCheckBox.isChecked() |
|
474 self.parameters['noempty'] = self.noemptyCheckBox.isChecked() |
|
475 outdir = self.outputDirEdit.text() |
|
476 if outdir != '': |
|
477 outdir = os.path.normpath(outdir) |
|
478 if outdir.endswith(os.sep): |
|
479 outdir = outdir[:-1] |
|
480 self.parameters['outputDirectory'] = outdir |
|
481 self.parameters['ignoreDirectories'] = [] |
|
482 for row in range(0, self.ignoreDirsList.count()): |
|
483 itm = self.ignoreDirsList.item(row) |
|
484 self.parameters['ignoreDirectories'].append(\ |
|
485 os.path.normpath(itm.text())) |
|
486 cssFile = self.cssEdit.text() |
|
487 if cssFile != '': |
|
488 cssFile = os.path.normpath(cssFile) |
|
489 self.parameters['cssFile'] = cssFile |
|
490 extensions = self.sourceExtEdit.text().split(',') |
|
491 self.parameters['sourceExtensions'] = \ |
|
492 [ext.strip() for ext in extensions] |
|
493 patterns = self.excludeFilesEdit.text().split(',') |
|
494 self.parameters['ignoreFilePatterns'] = \ |
|
495 [pattern.strip() for pattern in patterns] |
|
496 |
|
497 self.parameters['qtHelpEnabled'] = self.qtHelpGroup.isChecked() |
|
498 self.parameters['qtHelpOutputDirectory'] = self.qtHelpDirEdit.text() |
|
499 self.parameters['qtHelpNamespace'] = self.qtHelpNamespaceEdit.text() |
|
500 self.parameters['qtHelpVirtualFolder'] = self.qtHelpFolderEdit.text() |
|
501 self.parameters['qtHelpFilterName'] = self.qtHelpFilterNameEdit.text() |
|
502 self.parameters['qtHelpFilterAttributes'] = \ |
|
503 self.qtHelpFilterAttributesEdit.text() |
|
504 self.parameters['qtHelpTitle'] = self.qtHelpTitleEdit.text() |
|
505 self.parameters['qtHelpCreateCollection'] = \ |
|
506 self.qtHelpGenerateCollectionCheckBox.isChecked() |
|
507 |
|
508 # call the accept slot of the base class |
|
509 QDialog.accept(self) |