~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/DocumentationTools/EricdocConfigDialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#
5
5
 
6
6
"""
7
 
Module implementing a dialog to enter the parameters for eric3-doc.
 
7
Module implementing a dialog to enter the parameters for eric4-doc.
8
8
"""
9
9
 
10
10
import sys
11
11
import os
12
12
import copy
13
13
 
14
 
from qt import *
 
14
from PyQt4.QtCore import *
 
15
from PyQt4.QtGui import *
15
16
 
16
17
from KdeQt import KQFileDialog
17
18
 
18
 
from EricdocConfigForm import EricdocConfigForm
 
19
from E4Gui.E4Completers import E4DirCompleter
 
20
 
 
21
from Ui_EricdocConfigDialog import Ui_EricdocConfigDialog
 
22
from DocumentationTools.Config import eric4docDefaultColors, eric4docColorParameterNames
19
23
import Utilities
20
24
 
21
 
from eric3config import getConfig
 
25
from eric4config import getConfig
22
26
 
23
 
class EricdocConfigDialog(EricdocConfigForm):
24
 
    """
25
 
    Class implementing a dialog to enter the parameters for eric3-doc.
26
 
    """
27
 
    def __init__(self,ppath,parms = None,parent = None):
 
27
class EricdocConfigDialog(QDialog, Ui_EricdocConfigDialog):
 
28
    """
 
29
    Class implementing a dialog to enter the parameters for eric4-doc.
 
30
    """
 
31
    def __init__(self, ppath, parms = None, parent = None):
28
32
        """
29
33
        Constructor
30
34
        
32
36
        @param parms parameters to set in the dialog
33
37
        @param parent parent widget of this dialog
34
38
        """
35
 
        EricdocConfigForm.__init__(self,parent)
36
 
        
37
 
        self.initializeDefaults()
 
39
        QDialog.__init__(self,parent)
 
40
        self.setupUi(self)
 
41
        
 
42
        self.__initializeDefaults()
 
43
        
 
44
        self.sampleText = unicode(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
        ))
38
62
        
39
63
        # get a copy of the defaults to store the user settings
40
64
        self.parameters = copy.deepcopy(self.defaults)
 
65
        self.colors = eric4docDefaultColors.copy()
41
66
        
42
67
        # combine it with the values of parms
43
68
        if parms is not None:
44
69
            for key, value in parms.items():
45
 
                self.parameters[key] = parms[key]
 
70
                if key.endswith("Color"):
 
71
                    self.colors[key] = parms[key]
 
72
                else:
 
73
                    self.parameters[key] = parms[key]
46
74
        
47
75
        self.ppath = ppath
48
76
        
49
 
        self.prefixEdit.setText(self.parameters['filenamePrefix'])
 
77
        self.outputDirCompleter = E4DirCompleter(self.outputDirEdit)
 
78
        self.ignoreDirCompleter = E4DirCompleter(self.ignoreDirEdit)
 
79
        
50
80
        self.recursionCheckBox.setChecked(self.parameters['useRecursion'])
51
81
        self.noindexCheckBox.setChecked(self.parameters['noindex'])
52
82
        self.noemptyCheckBox.setChecked(self.parameters['noempty'])
53
83
        self.outputDirEdit.setText(self.parameters['outputDirectory'])
54
 
        self.ignoreDirsListBox.clear()
 
84
        self.ignoreDirsList.clear()
55
85
        for d in self.parameters['ignoreDirectories']:
56
 
            self.ignoreDirsListBox.insertItem(d)
 
86
            self.ignoreDirsList.addItem(d)
57
87
        self.cssEdit.setText(self.parameters['cssFile'])
58
88
        self.sourceExtEdit.setText(", ".join(self.parameters['sourceExtensions']))
59
 
 
60
 
    def initializeDefaults(self):
 
89
        self.excludeFilesEdit.setText(", ".join(self.parameters['ignoreFilePatterns']))
 
90
        self.sample.setHtml(self.sampleText % self.colors)
 
91
        
 
92
    def __initializeDefaults(self):
61
93
        """
62
94
        Private method to set the default values. 
63
95
        
65
97
        parameters.
66
98
        """
67
99
        self.defaults = {
68
 
            'filenamePrefix' : '',
69
100
            'useRecursion' : 0,
70
101
            'noindex' : 0,
71
102
            'noempty' : 0,
72
103
            'outputDirectory' : '',
73
104
            'ignoreDirectories' : [],
 
105
            'ignoreFilePatterns' : [],
74
106
            'cssFile' : '',
75
107
            'sourceExtensions' : [],
76
108
        }
93
125
        
94
126
        # 1. the program name
95
127
        args.append(sys.executable)
96
 
        args.append(Utilities.normabsjoinpath(getConfig('ericDir'), "eric3-doc.py"))
 
128
        args.append(Utilities.normabsjoinpath(getConfig('ericDir'), "eric4-doc.py"))
97
129
        
98
130
        # 2. the commandline options
 
131
        # 2a. general commandline options
99
132
        if self.parameters['outputDirectory'] != self.defaults['outputDirectory']:
100
133
            parms['outputDirectory'] = self.parameters['outputDirectory']
101
134
            args.append('-o')
108
141
            for d in self.parameters['ignoreDirectories']:
109
142
                args.append('-x')
110
143
                args.append(d)
111
 
        if self.parameters['filenamePrefix'] != self.defaults['filenamePrefix']:
112
 
            parms['filenamePrefix'] = self.parameters['filenamePrefix']
113
 
            args.append('-p')
114
 
            args.append(self.parameters['filenamePrefix'])
 
144
        if self.parameters['ignoreFilePatterns'] != self.defaults['ignoreFilePatterns']:
 
145
            parms['ignoreFilePatterns'] = self.parameters['ignoreFilePatterns'][:]
 
146
            for pattern in self.parameters['ignoreFilePatterns']:
 
147
                args.append("--exclude-file=%s" % pattern)
115
148
        if self.parameters['useRecursion'] != self.defaults['useRecursion']:
116
149
            parms['useRecursion'] = self.parameters['useRecursion']
117
150
            args.append('-r')
121
154
        if self.parameters['noempty'] != self.defaults['noempty']:
122
155
            parms['noempty'] = self.parameters['noempty']
123
156
            args.append('-e')
 
157
        if self.parameters['sourceExtensions'] != self.defaults['sourceExtensions']:
 
158
            parms['sourceExtensions'] = self.parameters['sourceExtensions'][:]
 
159
            for ext in self.parameters['sourceExtensions']:
 
160
                args.append('-t')
 
161
                args.append(ext)
 
162
        
 
163
        # 2b. style commandline options
124
164
        if self.parameters['cssFile'] != self.defaults['cssFile']:
125
165
            parms['cssFile'] = self.parameters['cssFile']
126
166
            args.append('-c')
128
168
                args.append(self.parameters['cssFile'])
129
169
            else:
130
170
                args.append(os.path.join(self.ppath, self.parameters['cssFile']))
131
 
        if self.parameters['sourceExtensions'] != self.defaults['sourceExtensions']:
132
 
            parms['sourceExtensions'] = self.parameters['sourceExtensions'][:]
133
 
            for ext in self.parameters['sourceExtensions']:
134
 
                args.append('-t')
135
 
                args.append(ext)
 
171
        for key, value in self.colors.items():
 
172
            if self.colors[key] != eric4docDefaultColors[key]:
 
173
                parms[key] = self.colors[key]
 
174
                args.append("--%s=%s" % \
 
175
                            (eric4docColorParameterNames[key], self.colors[key]))
136
176
        
137
177
        return (args, parms)
138
178
 
139
 
    def handleOutputDir(self):
 
179
    @pyqtSignature("")
 
180
    def on_outputDirButton_clicked(self):
140
181
        """
141
182
        Private slot to select the output directory.
142
183
        
143
184
        It displays a directory selection dialog to
144
185
        select the directory the documentations is written to.
145
186
        """
146
 
        directory = KQFileDialog.getExistingDirectory(self.outputDirEdit.text(),
147
 
            self, None, self.trUtf8("Select output directory"))
 
187
        directory = KQFileDialog.getExistingDirectory(\
 
188
            self,
 
189
            self.trUtf8("Select output directory"),
 
190
            self.outputDirEdit.text(),
 
191
            QFileDialog.Options(QFileDialog.ShowDirsOnly))
148
192
            
149
193
        if not directory.isNull():
150
194
            # make it relative, if it is a subdirectory of the project path 
151
 
            dn = unicode(QDir.convertSeparators(directory))
 
195
            dn = unicode(Utilities.toNativeSeparators(directory))
152
196
            dn = dn.replace(self.ppath+os.sep, '')
153
197
            while dn.endswith(os.sep):
154
198
                dn = dn[:-1]
155
199
            self.outputDirEdit.setText(dn)
156
200
 
157
 
    def handleIgnoreDir(self):
 
201
    @pyqtSignature("")
 
202
    def on_ignoreDirButton_clicked(self):
158
203
        """
159
204
        Private slot to select a directory to be ignored.
160
205
        
161
206
        It displays a directory selection dialog to
162
207
        select a directory to be ignored.
163
208
        """
164
 
        directory = KQFileDialog.getExistingDirectory(self.ignoreDirEdit.text(),
165
 
            self, None, self.trUtf8("Select directory to exclude"), 1, 0)
 
209
        directory = KQFileDialog.getExistingDirectory(\
 
210
            self,
 
211
            self.trUtf8("Select directory to exclude"),
 
212
            self.ignoreDirEdit.text(),
 
213
            QFileDialog.Options(QFileDialog.ShowDirsOnly))
166
214
            
167
215
        if not directory.isNull():
168
216
            # make it relative, if it is a subdirectory of the project path 
169
 
            dn = unicode(QDir.convertSeparators(directory))
 
217
            dn = unicode(Utilities.toNativeSeparators(directory))
170
218
            dn = dn.replace(self.ppath+os.sep, '')
171
219
            while dn.endswith(os.sep):
172
220
                dn = dn[:-1]
173
221
            self.ignoreDirEdit.setText(dn)
174
222
 
175
 
    def handleIgnoreDirAdd(self):
 
223
    @pyqtSignature("")
 
224
    def on_addButton_clicked(self):
176
225
        """
177
226
        Private slot to add the directory displayed to the listview.
178
227
        
179
228
        The directory in the ignore directories
180
229
        line edit is moved to the listbox above and the edit is cleared.
181
230
        """
182
 
        self.ignoreDirsListBox.insertItem(os.path.basename(unicode(self.ignoreDirEdit.text())))
 
231
        self.ignoreDirsList.addItem(os.path.basename(unicode(self.ignoreDirEdit.text())))
183
232
        self.ignoreDirEdit.clear()
184
233
 
185
 
    def handleIgnoreDirDelete(self):
 
234
    @pyqtSignature("")
 
235
    def on_deleteButton_clicked(self):
186
236
        """
187
237
        Private slot to delete the currently selected directory of the listbox.
188
238
        """
189
 
        self.ignoreDirsListBox.removeItem(self.ignoreDirsListBox.currentItem())
 
239
        itm = self.ignoreDirsList.takeItem(self.ignoreDirsList.currentRow())
 
240
        del itm
190
241
 
191
 
    def handleCSSFile(self):
 
242
    @pyqtSignature("")
 
243
    def on_cssButton_clicked(self):
192
244
        """
193
245
        Private slot to select a css style sheet.
194
246
        """
195
247
        cssFile = KQFileDialog.getOpenFileName(\
 
248
            self,
 
249
            self.trUtf8("Select CSS style sheet"),
196
250
            getConfig('ericCSSDir'),
197
 
            self.trUtf8("Style sheet (*.css);;All files (*)"),
198
 
            None, None,
199
 
            self.trUtf8("Select CSS style sheet"),
200
 
            None, 1)
 
251
            self.trUtf8("Style sheet (*.css);;All files (*)"))
201
252
            
202
253
        if not cssFile.isEmpty():
203
254
            # make it relative, if it is in a subdirectory of the project path 
204
 
            cf = unicode(QDir.convertSeparators(cssFile))
 
255
            cf = unicode(Utilities.toNativeSeparators(cssFile))
205
256
            cf = cf.replace(self.ppath+os.sep, '')
206
257
            self.cssEdit.setText(cf)
207
258
 
 
259
    def __selectColor(self, colorKey):
 
260
        """
 
261
        Private method to select a color.
 
262
        
 
263
        @param colorKey key of the color to select (string)
 
264
        """
 
265
        color = QColorDialog.getColor(QColor(self.colors[colorKey]))
 
266
        if color.isValid():
 
267
            self.colors[colorKey] = unicode(color.name())
 
268
            self.sample.setHtml(self.sampleText % self.colors)
 
269
 
 
270
    @pyqtSignature("")
 
271
    def on_bodyFgButton_clicked(self):
 
272
        """
 
273
        Private slot to select the body foreground color.
 
274
        """
 
275
        self.__selectColor('BodyColor')
 
276
    
 
277
    @pyqtSignature("")
 
278
    def on_bodyBgButton_clicked(self):
 
279
        """
 
280
        Private slot to select the body background color.
 
281
        """
 
282
        self.__selectColor('BodyBgColor')
 
283
    
 
284
    @pyqtSignature("")
 
285
    def on_l1FgButton_clicked(self):
 
286
        """
 
287
        Private slot to select the level 1 header foreground color.
 
288
        """
 
289
        self.__selectColor('Level1HeaderColor')
 
290
    
 
291
    @pyqtSignature("")
 
292
    def on_l1BgButton_clicked(self):
 
293
        """
 
294
        Private slot to select the level 1 header background color.
 
295
        """
 
296
        self.__selectColor('Level1HeaderBgColor')
 
297
    
 
298
    @pyqtSignature("")
 
299
    def on_l2FgButton_clicked(self):
 
300
        """
 
301
        Private slot to select the level 2 header foreground color.
 
302
        """
 
303
        self.__selectColor('Level2HeaderColor')
 
304
    
 
305
    @pyqtSignature("")
 
306
    def on_l2BgButton_clicked(self):
 
307
        """
 
308
        Private slot to select the level 2 header background color.
 
309
        """
 
310
        self.__selectColor('Level2HeaderBgColor')
 
311
    
 
312
    @pyqtSignature("")
 
313
    def on_cfFgButton_clicked(self):
 
314
        """
 
315
        Private slot to select the class/function header foreground color.
 
316
        """
 
317
        self.__selectColor('CFColor')
 
318
    
 
319
    @pyqtSignature("")
 
320
    def on_cfBgButton_clicked(self):
 
321
        """
 
322
        Private slot to select the class/function header background color.
 
323
        """
 
324
        self.__selectColor('CFBgColor')
 
325
    
 
326
    @pyqtSignature("")
 
327
    def on_linkFgButton_clicked(self):
 
328
        """
 
329
        Private slot to select the foreground color of links.
 
330
        """
 
331
        self.__selectColor('LinkColor')
 
332
    
208
333
    def accept(self):
209
334
        """
210
335
        Protected slot called by the Ok button. 
211
336
        
212
337
        It saves the values in the parameters dictionary.
213
338
        """
214
 
        self.parameters['filenamePrefix'] = unicode(self.prefixEdit.text())
215
339
        self.parameters['useRecursion'] = self.recursionCheckBox.isChecked()
216
340
        self.parameters['noindex'] = self.noindexCheckBox.isChecked()
217
341
        self.parameters['noempty'] = self.noemptyCheckBox.isChecked()
221
345
            if outdir.endswith(os.sep):
222
346
                outdir = outdir[:-1]
223
347
        self.parameters['outputDirectory'] = outdir
224
 
        itm = self.ignoreDirsListBox.firstItem()
225
348
        self.parameters['ignoreDirectories'] = []
226
 
        while itm is not None:
 
349
        for row in range(0, self.ignoreDirsList.count()):
 
350
            itm = self.ignoreDirsList.item(row)
227
351
            self.parameters['ignoreDirectories'].append(\
228
352
                os.path.normpath(unicode(itm.text())))
229
 
            itm = itm.next()
230
353
        cssFile = unicode(self.cssEdit.text())
231
354
        if cssFile != '':
232
355
            cssFile = os.path.normpath(cssFile)
233
356
        self.parameters['cssFile'] = cssFile
234
357
        extensions = unicode(self.sourceExtEdit.text()).split(',')
235
 
        self.parameters['sourceExtensions'] = []
236
 
        for ext in extensions:
237
 
            self.parameters['sourceExtensions'].append(ext.strip())
 
358
        self.parameters['sourceExtensions'] = \
 
359
            [ext.strip() for ext in extensions]
 
360
        patterns = unicode(self.excludeFilesEdit.text()).split(',')
 
361
        self.parameters['ignoreFilePatterns'] = \
 
362
            [pattern.strip() for pattern in patterns]
238
363
        
239
364
        # call the accept slot of the base class
240
 
        EricdocConfigForm.accept(self)
 
365
        QDialog.accept(self)