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

« back to all changes in this revision

Viewing changes to eric/Preferences/__init__.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:
8
8
 
9
9
The preferences interface consists of a class, which defines the default
10
10
values for all configuration items and stores the actual values. These
11
 
values are read and written to the eric3 preferences file by module
 
11
values are read and written to the eric4 preferences file by module
12
12
functions. On Windows the data is located in the registry, everywhere 
13
13
else it is stored in a file in a subdirectory of the users home directory.
14
14
The individual configuration data is accessed by accessor functions defined
21
21
import os
22
22
import fnmatch
23
23
 
24
 
from qt import *
25
 
from qtext import QextScintilla
 
24
from PyQt4 import QtCore, QtGui
 
25
from PyQt4 import Qsci
 
26
 
 
27
import QScintilla.Lexers
26
28
 
27
29
from ViewManager.Config import ConfigViewManagers
 
30
from Globals import settingsNameOrganization, settingsNameGlobal, settingsNameRecent
28
31
 
29
 
class Prefs:
 
32
class Prefs(object):
30
33
    """
31
34
    A class to hold all configuration items for the application.
32
35
    """
35
38
        "LocalsFilter" : [],
36
39
        "GlobalsFilter" : []
37
40
    }
38
 
        
 
41
    
39
42
    # defaults for the debugger
40
43
    debuggerDefaults = {
41
44
        "RemoteDbgEnabled" : 0,
44
47
        "PassiveDbgEnabled" : 0,
45
48
        "PassiveDbgPort" : 42424,
46
49
        "AutomaticReset" : 0,
 
50
        "Autosave" : 0,
47
51
        "CustomPythonInterpreter" : 0,
48
52
        "PythonInterpreter" : "",
49
53
        "RubyInterpreter" : "/usr/bin/ruby",
50
 
        "DebugClientType" : 1,      # this coresponds with the radio button id
 
54
        "DebugClientType" : "standard",     # supported "standard", "threaded", "custom"
51
55
        "DebugClient" : "",
52
56
        "DebugEnvironmentReplace" : 0,
53
57
        "DebugEnvironment" : "",
59
63
        "PathTranslation" : 0,
60
64
        "PathTranslationRemote" : "",
61
65
        "PathTranslationLocal" : "",
 
66
        "NetworkInterface" : "127.0.0.1",
62
67
    }
 
68
    debuggerDefaults["AllowedHosts"] = QtCore.QStringList("127.0.0.1")
63
69
    
64
70
    uiDefaults = {
65
71
        "Language" : "System",
 
72
        "Style" : "System",
 
73
        "StyleSheet" : "",
66
74
        "ViewManager" : "tabview",
67
 
        "LayoutType" : 1,                   # 0 = splitters
68
 
                                            # 1 = dockable windows
69
 
                                            # 2 = floating windows
 
75
        "LayoutType" : "DockWindows",
 
76
        # allowed values are "DockWindows" and "FloatingWindows"
70
77
        "LayoutShellEmbedded" : 0,          # 0 = separate
71
78
                                            # 1 = embedded in debug browser
72
79
        "LayoutFileBrowserEmbedded" : 1,    # 0 = separate
76
83
        "BrowsersHideNonPublic" : 0,
77
84
        "SingleApplicationMode" : 0,
78
85
        "CaptionShowsFilename" : 1,
 
86
        "CaptionFilenameLength" : 100,
 
87
        "TabViewManagerFilenameLength" : 40,
79
88
        # the order in ViewProfiles is Project-Browser, File-Browser,
80
89
        # Debug-Browser, Python-Shell, Log-Viewer, Task-Viewer,
81
90
        # Templates-Viewer
82
91
        "ViewProfiles" : {
83
 
            "edit"  : [[1, 0, 0, 1, 1, 1, 1], "", 
84
 
                [[0,0,300,300], [620,0,300,300], [310,0,300,300],
85
 
                 [310,350,400,100], [0,350,300,100], 
86
 
                 [0,500,400,125], [405,500,200,200]]],
87
 
            "debug" : [[0, 0, 1, 1, 1, 1, 0], "",
88
 
                [[0,0,300,300], [620,0,300,300], [310,0,300,300],
89
 
                 [310,350,400,100], [0,350,300,100], 
90
 
                 [0,500,400,125], [405,500,200,200]]],
91
 
        }
 
92
            "edit"  : [
 
93
                        # visibility
 
94
                        [ 1,  0,  0,  1,  1,  1,  1],
 
95
                        # saved state main window with dock windows
 
96
                        "",
 
97
                        # saved states floating windows
 
98
                        ["", "", "", "", "", "", ""],
 
99
                        # saved state main window with floating windows
 
100
                        ""
 
101
                      ],
 
102
            "debug" : [
 
103
                        # visibility
 
104
                        [ 0,  0,  1,  1,  1,  1,  0], 
 
105
                        # saved state main window with dock windows
 
106
                        "",
 
107
                        # saved states floating windows
 
108
                        ["", "", "", "", "", "", ""],
 
109
                        # saved state main window with floating windows
 
110
                        ""
 
111
                      ],
 
112
        },
 
113
        "ShowSplash" : 1,
 
114
        
 
115
        "PerformVersionCheck" : 4,      # 0 = off
 
116
                                        # 1 = at startup
 
117
                                        # 2 = daily
 
118
                                        # 3 = weekly
 
119
                                        # 4 = monthly
 
120
        "UseProxy" : 0,
 
121
        "ProxyHost" : "",
 
122
        "ProxyPort" : 80,
 
123
        "ProxyUser" : "",
 
124
        "ProxyPassword" : "",
 
125
        "UseIconProvider" : 1,
92
126
    }
 
127
    if sys.platform == "win32" or sys.platform == "darwin":
 
128
        uiDefaults["UseKDEDialogs"] = 0
 
129
    else:
 
130
        uiDefaults["UseKDEDialogs"] = 1
93
131
    viewProfilesLength = len(uiDefaults["ViewProfiles"]["edit"][2])
94
132
    
95
133
    iconsDefaults = {
96
 
        "Path" : QStringList(),
 
134
        "Path" : QtCore.QStringList(),
97
135
    }
98
136
    
99
137
    # defaults for the editor settings
114
152
        "ShowEOL" : 0,
115
153
        "UseMonospacedFont" : 0,
116
154
        "WrapLongLines" : 1,
117
 
 
118
 
        "EdgeMode" : QextScintilla.EDGE_NONE,
 
155
        "WarnFilesize" : 512,
 
156
        "ClearBreaksOnClose" : 1,
 
157
        
 
158
        "EdgeMode" : Qsci.QsciScintilla.EdgeNone,
119
159
        "EdgeColumn" : 80,
120
160
        
 
161
        "AutoIndentation" : 1,
 
162
        "BraceHighlighting" : 1,
 
163
        "CreateBackupFile" : 0,
 
164
        "CaretLineVisible" : 0,
 
165
        "CaretWidth" : 1,
 
166
        "ColourizeSelText" : 0,
 
167
        "CustomSelectionColours" : 0,
 
168
        "ExtendSelectionToEol" : 0,
 
169
        
 
170
        "AutoPrepareAPIs" : 0,
 
171
        
 
172
        "AutoCompletionEnabled" : 0,
 
173
        "AutoCompletionCaseSensitivity" : 1,
 
174
        "AutoCompletionReplaceWord" : 0,
 
175
        "AutoCompletionShowSingle" : 0,
 
176
        "AutoCompletionSource" : Qsci.QsciScintilla.AcsDocument,
 
177
        "AutoCompletionThreshold" : 2,
 
178
        "AutoCompletionFillups" : 0,
 
179
        
 
180
        "CallTipsEnabled" : 0,
 
181
        "CallTipsVisible" : -1,
 
182
        "CallTipsStyle"   : Qsci.QsciScintilla.CallTipsNoContext,
 
183
        
 
184
        "AutoCheckSyntax" : 1,
 
185
        "AutoReopen" : 0,
 
186
        
 
187
        "MiniContextMenu" : 0,
 
188
        
 
189
        "DefaultEncoding" : "utf8",
 
190
        "DefaultOpenFilter" : "",
 
191
        "DefaultSaveFilter" : "",
 
192
        
121
193
        # All (most) lexers
122
194
        "AllFoldCompact" : 1,
123
195
        
128
200
        "PythonAutoIndent" : 0,
129
201
        
130
202
        # C++ specifics
 
203
        "CppCaseInsensitiveKeywords" : 0, 
131
204
        "CppFoldComment" : 1,
132
205
        "CppFoldPreprocessor" : 0,
133
206
        "CppFoldAtElse" : 0,
148
221
        # Bash specifics
149
222
        "BashFoldComment" : 1,
150
223
        
151
 
        # Ruby specifics
152
 
        "RubyBadIndentation" : 1,
153
 
        
154
224
        # CSS specifics
155
225
        "CssFoldComment" : 1,
156
226
        
157
 
        "AutoIndentation" : 1,
158
 
        "BraceHighlighting" : 1,
159
 
        "CreateBackupFile" : 0,
160
 
        "AutoCompletionEnabled" : 0,
161
 
        "AutoCompletionCaseSensitivity" : 1,
162
 
        "AutoCompletionReplaceWord" : 0,
163
 
        "AutoCompletionShowSingle" : 0,
164
 
        "AutoCompletionSource" : QextScintilla.AcsDocument,
165
 
        "AutoCompletionThreshold" : 2,
166
 
        "AutoCompletionFillups" : 0,
167
 
        "CallTipsEnabled" : 0,
168
 
        "CallTipsVisible" : -1,
169
 
        "CaretLineVisible" : 0,
170
 
        "CaretWidth" : 1,
171
 
        "ColourizeSelText" : 0,
172
 
        
173
 
        "AutoCheckSyntax" : 1,
174
 
        
175
 
        "DefaultEncoding" : "utf8"
 
227
        # D specifics
 
228
        "DFoldComment" : 1,
 
229
        "DFoldAtElse" : 0,
 
230
        "DIndentOpeningBrace" : 0,
 
231
        "DIndentClosingBrace" : 0,
 
232
        
 
233
        # Povray specifics
 
234
        "PovFoldComment" : 1,
 
235
        "PovFoldDirectives" : 0,
 
236
        
 
237
        # CMake specifics
 
238
        "CMakeFoldAtElse" : 0,
 
239
        
 
240
        # VHDL specifics
 
241
        "VHDLFoldComment" : 1,
 
242
        "VHDLFoldAtElse" : 1,
 
243
        "VHDLFoldAtBegin" : 1, 
 
244
        "VHDLFoldAtParenthesis" : 1, 
176
245
    }
 
246
    
177
247
    if sys.platform == "win32":
178
 
        editorDefaults["EOLMode"] = QextScintilla.EolWindows
 
248
        editorDefaults["EOLMode"] = Qsci.QsciScintilla.EolWindows
179
249
    else:
180
 
        editorDefaults["EOLMode"] = QextScintilla.EolUnix
 
250
        editorDefaults["EOLMode"] = Qsci.QsciScintilla.EolUnix
181
251
    
182
252
    editorColourDefaults = {
183
 
        "CurrentMarker" : Qt.yellow,
184
 
        "ErrorMarker" : Qt.red,
185
 
        "MatchingBrace" : Qt.blue,
186
 
        "MatchingBraceBack" : Qt.white,
187
 
        "NonmatchingBrace" : Qt.red,
188
 
        "NonmatchingBraceBack" : Qt.white,
189
 
        "CallTipsBackground" : Qt.white,
190
 
        "CaretForeground" : Qt.black,
191
 
        "CaretLineBackground" : Qt.white,
192
 
        "Edge" : Qt.lightGray,
 
253
        "CurrentMarker"        : QtGui.QColor(QtCore.Qt.yellow),
 
254
        "ErrorMarker"          : QtGui.QColor(QtCore.Qt.red),
 
255
        "MatchingBrace"        : QtGui.QColor(QtCore.Qt.green),
 
256
        "MatchingBraceBack"    : QtGui.QColor(QtCore.Qt.white),
 
257
        "NonmatchingBrace"     : QtGui.QColor(QtCore.Qt.red),
 
258
        "NonmatchingBraceBack" : QtGui.QColor(QtCore.Qt.white),
 
259
        "CallTipsBackground"   : QtGui.QColor(QtCore.Qt.white),
 
260
        "CaretForeground"      : QtGui.QColor(QtCore.Qt.black),
 
261
        "CaretLineBackground"  : QtGui.QColor(QtCore.Qt.white),
 
262
        "Edge"                 : QtGui.QColor(QtCore.Qt.lightGray),
 
263
        "SelectionBackground"  : QtGui.QColor(QtCore.Qt.black),
 
264
        "SelectionForeground"  : QtGui.QColor(QtCore.Qt.white),
193
265
    }
194
266
    
195
267
    editorOtherFontsDefaults = {
196
 
        "MarginsFont" : "Helvetica,12,-1,5,50,0,0,0,0,0",
197
 
        "MonospacedFont" : "Courier,12,-1,5,50,0,0,0,0,0"
198
 
    }
199
 
    
200
 
    editorAPIDefaults = {
201
 
        "Python" : QStringList(),
202
 
        "C++" : QStringList(),
203
 
        "C#" : QStringList(),
204
 
        "IDL" : QStringList(),
205
 
        "Java" : QStringList(),
206
 
        "JavaScript" : QStringList()
207
 
    }
208
 
    
209
 
    editorLexerAssocDefaults = {
210
 
        '*.py' : "Python",
211
 
        '*.pyw' : "Python",
212
 
        '*.pyx' : "Python",
213
 
        '*.ptl' : "Python",
214
 
        '*.cpp' : "C++",
215
 
        '*.cxx' : "C++",
216
 
        '*.cc' : "C++",
217
 
        '*.c' : "C++",
218
 
        '*.hpp' : "C++",
219
 
        '*.hh' : "C++",
220
 
        '*.h' : "C++",
221
 
        '*.cs' : "C#",
222
 
        '*.idl' : "IDL",
223
 
        '*.java' : "Java",
224
 
        '*.js' : "JavaScript",
225
 
    }
226
 
    
227
 
    editorDefaultPatterns = \
228
 
        ['*.h', '*.cpp', '*.cs', '*.idl', '*.java', '*.js', 
229
 
         '*.pyx', '*.py', '*.ptl', '*.pyw']
230
 
    
231
 
    # the following languages are only supported for QScintilla > 1.0
232
 
    try:
233
 
        from qtext import QextScintillaLexerHTML
234
 
        editorAPIDefaults["HTML"] = QStringList()
235
 
        editorLexerAssocDefaults.update({
236
 
            '*.html' : "HTML",
237
 
            '*.htm' : "HTML",
238
 
            '*.asp' : "HTML",
239
 
            '*.shtml' : "HTML",
240
 
            '*.css' : "HTML",
241
 
            '*.php' : "HTML",
242
 
            '*.php3' : "HTML",
243
 
            '*.php4' : "HTML",
244
 
            '*.php5' : "HTML",
245
 
            '*.phtml' : "HTML",
246
 
            '*.xml' : "HTML",
247
 
            '*.xsl' : "HTML",
248
 
            '*.svg' : "HTML",
249
 
            '*.xsd' : "HTML",
250
 
            '*.xslt' : "HTML",
251
 
            '*.dtd' : "HTML",
252
 
            '*.rdf' : "HTML",
253
 
            '*.docbook' : "HTML"
254
 
        })
255
 
        editorDefaultPatterns.extend(['*.html', '*.xml', '*.php', '*.dtd'])
256
 
    except ImportError:
257
 
        pass
258
 
    try:
259
 
        from qtext import QextScintillaLexerSQL
260
 
        editorAPIDefaults["SQL"] = QStringList()
261
 
        editorLexerAssocDefaults["*.sql"] = "SQL"
262
 
        editorDefaultPatterns.append('*.sql')
263
 
    except ImportError:
264
 
        pass
265
 
    
266
 
    # the following languages are only supported for QScintilla > 1.2
267
 
    try:
268
 
        from qtext import QextScintillaLexerPerl
269
 
        editorAPIDefaults["Perl"] = QStringList()
270
 
        editorLexerAssocDefaults.update({
271
 
            '*.pl' : "Perl",
272
 
            '*.pm' : "Perl",
273
 
            '*.ph' : "Perl"
274
 
        })
275
 
        editorDefaultPatterns.append('*.pl')
276
 
    except ImportError:
277
 
        pass
278
 
    
279
 
    # the following languages are only supported for QScintilla > 1.3
280
 
    try:
281
 
        from qtext import QextScintillaLexerBash
282
 
        editorAPIDefaults["Bash"] = QStringList()
283
 
        editorLexerAssocDefaults["*.sh"] = "Bash"
284
 
        editorDefaultPatterns.append('*.sh')
285
 
    except ImportError:
286
 
        pass
287
 
    
288
 
    # the following languages are only supported for QScintilla > 1.4
289
 
    try:
290
 
        from qtext import QextScintillaLexerRuby
291
 
        editorAPIDefaults["Ruby"] = QStringList()
292
 
        editorLexerAssocDefaults.update({
293
 
            '*.rb' : "Ruby",
294
 
            '*.rbw' : "Ruby"
295
 
        })
296
 
        editorDefaultPatterns.extend(['*.rb', '*.rbw'])
297
 
    except ImportError:
298
 
        pass
299
 
    try:
300
 
        from qtext import QextScintillaLexerLua
301
 
        editorAPIDefaults["Lua"] = QStringList()
302
 
        editorLexerAssocDefaults["*.lua"] = "Lua"
303
 
        editorDefaultPatterns.append('*.lua')
304
 
    except ImportError:
305
 
        pass
306
 
 
307
 
    # the following languages are only supported for QScintilla > 1.5
308
 
    try:
309
 
        from qtext import QextScintillaLexerCSS
310
 
        editorAPIDefaults["CSS"] = QStringList()
311
 
        editorLexerAssocDefaults["*.css"] = "CSS"
312
 
        editorDefaultPatterns.append('*.css')
313
 
    except ImportError:
314
 
        pass
315
 
    try:
316
 
        from qtext import QextScintillaLexerTeX
317
 
        editorAPIDefaults["TeX"] = QStringList()
318
 
        editorLexerAssocDefaults.update({
319
 
            "*.tex" : "TeX",
320
 
            "*.sty" : "TeX",
321
 
            "*.aux" : "TeX",
322
 
            "*.toc" : "TeX",
323
 
            "*.idx" : "TeX"
324
 
        })
325
 
        editorDefaultPatterns.extend(['*.tex', '*.sty', '*.aux', '*.toc', '*.idx'])
326
 
    except ImportError:
327
 
        pass
328
 
    try:
329
 
        from qtext import QextScintillaLexerDiff
330
 
        editorAPIDefaults["Diff"] = QStringList()
331
 
        editorLexerAssocDefaults.update({
332
 
            "*.diff" : "Diff",
333
 
            "*.patch" : "Diff"
334
 
        })
335
 
        editorDefaultPatterns.extend(['*.diff', '*.patch'])
336
 
    except ImportError:
337
 
        pass
338
 
    try:
339
 
        from qtext import QextScintillaLexerMakefile
340
 
        editorAPIDefaults["Makefile"] = QStringList()
341
 
        editorLexerAssocDefaults.update({
342
 
            "*makefile" : "Makefile",
343
 
            "Makefile*" : "Makefile",
344
 
            "*.mak" : "Makefile"
345
 
        })
346
 
        editorDefaultPatterns.extend(['*makefile', 'Makefile*', '*.mak'])
347
 
    except ImportError:
348
 
        pass
349
 
    try:
350
 
        from qtext import QextScintillaLexerProperties
351
 
        editorAPIDefaults["Properties"] = QStringList()
352
 
        editorLexerAssocDefaults.update({
353
 
            "*.properties" : "Properties",
354
 
            "*.ini" : "Properties",
355
 
            "*.inf" : "Properties",
356
 
            "*.reg" : "Properties",
357
 
            "*.cfg" : "Properties",
358
 
            "*.cnf" : "Properties",
359
 
            "*.rc"  : "Properties",
360
 
        })
361
 
        editorDefaultPatterns.extend(['*.ini', '*.inf', '*.reg', '*.cfg', '*.cnf', '*.rc'])
362
 
    except ImportError:
363
 
        pass
364
 
    try:
365
 
        from qtext import QextScintillaLexerBatch
366
 
        editorAPIDefaults["Batch"] = QStringList()
367
 
        editorLexerAssocDefaults.update({
368
 
            "*.bat" : "Batch",
369
 
            "*.cmd" : "Batch"
370
 
        })
371
 
        editorDefaultPatterns.extend(['*.bat', '*.cmd'])
372
 
    except ImportError:
373
 
        pass
374
 
 
375
 
 
 
268
        "MarginsFont"    : "Sans Serif,10,-1,5,50,0,0,0,0,0",
 
269
        "DefaultFont"    : "Sans Serif,10,-1,5,50,0,0,0,0,0",
 
270
        "MonospacedFont" : "Courier,10,-1,5,50,0,0,0,0,0"
 
271
    }
 
272
    
 
273
    editorAPIDefaults = {}
 
274
    for language in QScintilla.Lexers.getSupportedLanguages().keys():
 
275
        editorAPIDefaults[language] = QtCore.QStringList()
 
276
    
 
277
    editorLexerAssocDefaults = QScintilla.Lexers.getDefaultLexerAssociations()
 
278
    
 
279
    editorTypingDefaults = {
 
280
        "Python/EnabledTypingAids"  : 1, 
 
281
        "Python/InsertClosingBrace" : 1,
 
282
        "Python/IndentBrace"        : 1,
 
283
        "Python/SkipBrace"          : 1,
 
284
        "Python/InsertQuote"        : 1,
 
285
        "Python/DedentElse"         : 1,
 
286
        "Python/DedentExcept"       : 1,
 
287
        "Python/Py24StyleTry"       : 1, 
 
288
        "Python/InsertImport"       : 1,
 
289
        "Python/InsertSelf"         : 1,
 
290
        "Python/InsertBlank"        : 1,
 
291
        "Python/ColonDetection"     : 1,
 
292
        
 
293
        "Ruby/EnabledTypingAids"    : 1, 
 
294
        "Ruby/InsertClosingBrace"   : 1,
 
295
        "Ruby/IndentBrace"          : 1,
 
296
        "Ruby/SkipBrace"            : 1,
 
297
        "Ruby/InsertQuote"          : 1,
 
298
        "Ruby/InsertBlank"          : 1,
 
299
        "Ruby/InsertHereDoc"        : 1, 
 
300
        "Ruby/InsertInlineDoc"      : 1, 
 
301
    }
 
302
    
376
303
    # defaults for the printer settings
377
304
    printerDefaults = {
378
305
        "PrinterName" : "",
379
306
        "ColorMode" : 1,
380
307
        "FirstPageFirst" : 1,
381
 
        "Magnification" : 0,
 
308
        "Magnification" : -3,
382
309
        "Orientation" : 0,
383
310
        "PageSize": 0,
384
 
        "HeaderFont" : "Times,10,-1,5,50,0,0,0,0,0"
 
311
        "HeaderFont" : "Serif,10,-1,5,50,0,0,0,0,0"
385
312
    }
386
313
    
387
314
    # defaults for the project settings
394
321
        "CompressedProjectFiles" : 0,
395
322
        "XMLTimestamp" : 1,
396
323
        "AutoCompileForms" : 0,
 
324
        "AutoCompileResources" : 0,
397
325
        "AutoLoadDbgProperties" : 0,
398
326
        "AutoSaveDbgProperties" : 0,
 
327
        "HideGeneratedForms" : 0,
 
328
    }
 
329
    
 
330
    # defaults for the project browser colour settings
 
331
    projectBrowserColourDefaults = {
 
332
        "Highlighted"        : QtGui.QColor(QtCore.Qt.red),
 
333
        
 
334
        "VcsAdded"           : QtGui.QColor(QtCore.Qt.blue),
 
335
        "VcsConflict"        : QtGui.QColor(QtCore.Qt.red),
 
336
        "VcsModified"        : QtGui.QColor(QtCore.Qt.yellow),
 
337
        "VcsUpdate"          : QtGui.QColor(QtCore.Qt.green),
399
338
    }
400
339
    
401
340
    # defaults for the help settings
402
341
    helpDefaults = {
403
342
        "HelpViewerType" : 1,      # this coresponds with the radio button id
404
 
        "Webbrowser" : "",
405
 
        "Pdfviewer" : "",
406
343
        "CustomViewer" : "",
407
344
        "PythonDocDir" : "",
408
345
        "QtDocDir" : "",
409
346
        "Qt4DocDir" : "",
 
347
        "PyQt4DocDir" : "",
 
348
        "SingleHelpWindow" : 1,
 
349
        "SaveGeometry" : 1,
410
350
    }
411
351
    
412
352
    # defaults for system settings
413
353
    sysDefaults = {
414
 
        "StringEncoding" : "utf8"
 
354
        "StringEncoding" : "utf8",
 
355
        "IOEncoding"     : "utf8",
415
356
    }
416
357
    
417
358
    # defaults for the shell settings
422
363
        "CallTipsEnabled" : 1,
423
364
        "WrapEnabled" : 1,
424
365
        "MaxHistoryEntries" : 100,
 
366
        "SyntaxHighlightingEnabled" : 1,
425
367
    }
426
368
 
427
369
    # defaults for Qt related stuff
428
370
    qtDefaults = {
429
371
        "QtDir" : "",
430
372
        "ExportQtDir" : 0,
 
373
        "DisableQt3" : 0,
431
374
        "Qt4Dir" : "",
432
375
        "ExportQt4Dir" : 0,
 
376
        "Qt4TranslationsDir" : "",
 
377
        "QtToolsPrefix3" : "", 
 
378
        "QtToolsPostfix3" : "", 
 
379
        "QtToolsPrefix4" : "", 
 
380
        "QtToolsPostfix4" : "", 
433
381
    }
434
382
    
435
383
    # defaults for corba related stuff
457
405
        "AutoClose" : 0,
458
406
        "AutoSaveFiles" : 1,
459
407
        "AutoSaveProject" : 1,
 
408
        "StatusMonitorInterval" : 30,
 
409
        "SvnInterfaceGlobalOverride" : 0,
 
410
        # 0 = no override, 1 = use svn, 2 = use pysvn
460
411
    }
461
412
    
462
413
    # defaults for tasks related stuff
464
415
        "TasksMarkers"       : "TO" + "DO:", 
465
416
        "TasksMarkersBugfix" : "FIX" + "ME:",
466
417
        # needed to keep it from being recognized as a task
467
 
        "TasksColour"          : Qt.black,
468
 
        "TasksBugfixColour"    : Qt.red,
469
 
        "TasksBgColour"        : Qt.white,
470
 
        "TasksProjectBgColour" : Qt.lightGray,
 
418
        "TasksColour"          : QtGui.QColor(QtCore.Qt.black),
 
419
        "TasksBugfixColour"    : QtGui.QColor(QtCore.Qt.red),
 
420
        "TasksBgColour"        : QtGui.QColor(QtCore.Qt.white),
 
421
        "TasksProjectBgColour" : QtGui.QColor(QtCore.Qt.lightGray),
471
422
    }
472
423
    
473
424
    # defaults for templates related stuff
478
429
        "SeparatorChar"  : "$",
479
430
    }
480
431
    
 
432
    # defaults for the printer settings
 
433
    graphicsDefaults = {
 
434
        "Font" : "SansSerif,10,-1,5,50,0,0,0,0,0"
 
435
    }
 
436
    
481
437
    # defaults for geometry
482
438
    geometryDefaults = {
483
 
        "MainGeometry"   : [0,0,0,0],
484
 
        "MainSplitter0"  : [0,0,0,0,0],
485
 
        "MainSplitter1"  : [0,0,0,0,0,0,0],
486
 
        "ProjectBrowser" : [0,0,300,300,1],
487
 
        "SBV"            : [310,0,300,300,1],
488
 
        "LogViewer"      : [0,350,300,100,1],
489
 
        "Shell"          : [310,350,400,100,1],
490
 
        "FileBrowser"    : [620,0,300,300,1],
491
 
        "TaskViewer"     : [0,500,400,125,1],
492
 
        "TemplateViewer" : [405,500,200,200,1],
493
 
    }
494
 
 
495
 
    # defaults for dock windows
496
 
    dockDefaults = {
497
 
        "MainDockLayout0" : "",
498
 
        "MainDockLayout1" : "",
499
 
        "MainDockLayout2" : "",
500
 
        "MainDockLayout3" : "",
 
439
        "HelpViewerGeometry" : QtCore.QByteArray(),
 
440
        "MainGeometry"       : QtCore.QByteArray(),
501
441
    }
502
442
 
503
443
    # if true, revert layouts to factory defaults
504
 
    resetLayout = 0
 
444
    resetLayout = False
505
445
 
506
446
def readPreferences(prefClass = Prefs):
507
447
    """
509
449
    
510
450
    @param prefClass preferences class used as the storage area
511
451
    """
 
452
    # read the general entries
 
453
    prefClass.configured, ok = \
 
454
        prefClass.settings.value("General/Configured", QtCore.QVariant(0)).toInt()
 
455
    
512
456
    # read the entries for the variables display
513
457
    prefClass.varPrefs = {}
514
458
    for key in prefClass.varDefaults.keys():
515
 
        v, ok = prefClass.settings.readEntry("/eric3/Variables/" + key)
516
 
        if ok:
517
 
            prefClass.varPrefs[key] = eval(unicode(v))
518
 
        else:
519
 
            prefClass.varPrefs[key] = prefClass.varDefaults[key]
 
459
        v = prefClass.settings.value("Variables/" + key, 
 
460
            QtCore.QVariant(unicode(prefClass.varDefaults[key])))
 
461
        v=v.toString()
 
462
        prefClass.varPrefs[key] = eval(unicode(v))
520
463
 
521
464
    # read the entries for the debugger
522
465
    prefClass.debuggerPrefs = {}
523
 
    for key in "RemoteDbgEnabled", "PassiveDbgEnabled", \
 
466
    for key in ["RemoteDbgEnabled", "PassiveDbgEnabled", \
524
467
                "PassiveDbgPort", "CustomPythonInterpreter", \
525
 
                "DebugClientType", "AutomaticReset", "DebugEnvironmentReplace", \
 
468
                "AutomaticReset", "DebugEnvironmentReplace", \
526
469
                "PythonRedirect", "PythonNoEncoding", "RubyRedirect", \
527
 
                "ConsoleDbgEnabled", "PathTranslation":
528
 
        prefClass.debuggerPrefs[key], ok = \
529
 
            prefClass.settings.readNumEntry("/eric3/Debugger/" + key,
530
 
                prefClass.debuggerDefaults[key])
531
 
                
532
 
    for key in "RemoteHost", "RemoteExecution", "PythonInterpreter", \
533
 
                "RubyInterpreter", "DebugClient", "DebugEnvironment", \
534
 
                "ConsoleDbgCommand", "PathTranslationRemote", \
535
 
                "PathTranslationLocal":
536
 
        prefClass.debuggerPrefs[key], ok = \
537
 
            prefClass.settings.readEntry("/eric3/Debugger/" + key,
538
 
                prefClass.debuggerDefaults[key])
 
470
                "ConsoleDbgEnabled", "PathTranslation", "Autosave"]:
 
471
        prefClass.debuggerPrefs[key], ok = \
 
472
            prefClass.settings.value("Debugger/" + key,
 
473
                QtCore.QVariant(prefClass.debuggerDefaults[key])).toInt()
 
474
    
 
475
    for key in ["RemoteHost", "RemoteExecution", "PythonInterpreter", \
 
476
                "RubyInterpreter", "DebugClient", "DebugClientType", \
 
477
                "DebugEnvironment", "ConsoleDbgCommand", \
 
478
                "PathTranslationRemote", "PathTranslationLocal", \
 
479
                "NetworkInterface"]:
 
480
        prefClass.debuggerPrefs[key] = \
 
481
            prefClass.settings.value("Debugger/" + key,
 
482
                QtCore.QVariant(prefClass.debuggerDefaults[key])).toString()
 
483
    
 
484
    for key in ["AllowedHosts"]:
 
485
        prefClass.debuggerPrefs[key] = \
 
486
            prefClass.settings.value("Debugger/" + key,
 
487
                QtCore.QVariant(prefClass.debuggerDefaults[key])).toStringList()
539
488
    
540
489
    # read the entries for the general ui settings
541
490
    prefClass.uiPrefs = {}
542
 
    lang, ok = \
543
 
        prefClass.settings.readEntry("/eric3/UI/Language",
544
 
            prefClass.uiDefaults["Language"])
 
491
    lang = \
 
492
        prefClass.settings.value("UI/Language",
 
493
            QtCore.QVariant(prefClass.uiDefaults["Language"])).toString()
545
494
    if unicode(lang) == "None" or unicode(lang) == "" or lang is None:
546
495
        prefClass.uiPrefs["Language"] = None
547
496
    else:
548
497
        prefClass.uiPrefs["Language"] = unicode(lang)
549
 
        
550
 
    vm, ok = \
551
 
        prefClass.settings.readEntry("/eric3/UI/ViewManager",
552
 
            prefClass.uiDefaults["ViewManager"])
 
498
    
 
499
    vm = \
 
500
        prefClass.settings.value("UI/ViewManager",
 
501
            QtCore.QVariant(prefClass.uiDefaults["ViewManager"])).toString()
553
502
    if unicode(vm) in ConfigViewManagers:
554
503
        prefClass.uiPrefs["ViewManager"] = unicode(vm)
555
504
    else:
556
505
        prefClass.uiPrefs["ViewManager"] = prefClass.uiDefaults["ViewManager"]
557
506
 
558
 
    for key in ["LayoutType", "LayoutShellEmbedded", "LayoutFileBrowserEmbedded",
559
 
                "BrowsersListFoldersFirst", "BrowsersHideNonPublic", "SingleApplicationMode",
560
 
                "CaptionShowsFilename"]:
 
507
    for key in ["LayoutShellEmbedded", "LayoutFileBrowserEmbedded",
 
508
                "BrowsersListFoldersFirst", "BrowsersHideNonPublic",
 
509
                "SingleApplicationMode", "TabViewManagerFilenameLength",
 
510
                "CaptionShowsFilename", "CaptionFilenameLength",
 
511
                "UseKDEDialogs", "ShowSplash", "PerformVersionCheck",
 
512
                "UseProxy", "ProxyPort", "UseIconProvider"]:
561
513
        prefClass.uiPrefs[key], ok = \
562
 
            prefClass.settings.readNumEntry("/eric3/UI/" + key,
563
 
                prefClass.uiDefaults[key])
 
514
            prefClass.settings.value("UI/" + key,
 
515
                QtCore.QVariant(prefClass.uiDefaults[key])).toInt()
 
516
    for key in ["Style", "StyleSheet", "LayoutType", 
 
517
                "ProxyHost", "ProxyUser", "ProxyPassword"]:
 
518
        prefClass.uiPrefs[key] = \
 
519
            prefClass.settings.value("UI/" + key,
 
520
                QtCore.QVariant(prefClass.uiDefaults[key])).toString()
564
521
 
565
 
    v, ok = prefClass.settings.readEntry("/eric3/UI/ViewProfiles")
566
 
    if ok:
567
 
        prefClass.uiPrefs["ViewProfiles"] = eval(unicode(v))
 
522
    v = prefClass.settings.value("UI/ViewProfiles")
 
523
    if v.isValid():
 
524
        prefClass.uiPrefs["ViewProfiles"] = eval(unicode(v.toString()))
568
525
        for name in ["edit", "debug"]:
569
526
            vpLength = len(prefClass.uiPrefs["ViewProfiles"][name][0])
570
527
            if vpLength < prefClass.viewProfilesLength:
577
534
    else:
578
535
        prefClass.uiPrefs["ViewProfiles"] = prefClass.uiDefaults["ViewProfiles"]
579
536
    
580
 
    
581
537
    prefClass.iconsPrefs = {}
582
538
    for key in prefClass.iconsDefaults.keys():
583
 
        dirlist, ok = prefClass.settings.readListEntry("/eric3/UI/Icons/" + key)
584
 
        if ok:
585
 
            prefClass.iconsPrefs[key] = dirlist
 
539
        dirlist = prefClass.settings.value("UI/Icons/" + key)
 
540
        if dirlist.isValid():
 
541
            prefClass.iconsPrefs[key] = dirlist.toStringList()
586
542
        else:
587
543
            prefClass.iconsPrefs[key] = prefClass.iconsDefaults[key]
588
544
    
589
545
    # read the entries for the editor settings
590
546
    prefClass.editorPrefs = {}
591
547
    for key in prefClass.editorDefaults.keys():
592
 
        if key in ["DefaultEncoding"]:
593
 
            prefClass.editorPrefs[key], ok = \
594
 
                prefClass.settings.readEntry("/eric3/Editor/" + key,
595
 
                    prefClass.editorDefaults[key])
 
548
        if key in ["DefaultEncoding", "DefaultOpenFilter", "DefaultSaveFilter"]:
 
549
            prefClass.editorPrefs[key] = \
 
550
                prefClass.settings.value("Editor/" + key,
 
551
                    QtCore.QVariant(prefClass.editorDefaults[key])).toString()
596
552
        else:
597
553
            prefClass.editorPrefs[key], ok = \
598
 
                prefClass.settings.readNumEntry("/eric3/Editor/" + key,
599
 
                    prefClass.editorDefaults[key])
 
554
                prefClass.settings.value("Editor/" + key,
 
555
                    QtCore.QVariant(prefClass.editorDefaults[key])).toInt()
600
556
    
601
557
    prefClass.editorColourPrefs = {}
602
558
    for key in prefClass.editorColourDefaults.keys():
603
 
        col, ok = prefClass.settings.readEntry("/eric3/Editor/Colour/" + key)
604
 
        if ok:
605
 
            prefClass.editorColourPrefs[key] = QColor(col)
 
559
        col = prefClass.settings.value("Editor/Colour/" + key)
 
560
        if col.isValid():
 
561
            prefClass.editorColourPrefs[key] = QtGui.QColor(col.toString())
606
562
        else:
607
563
            prefClass.editorColourPrefs[key] = prefClass.editorColourDefaults[key]
608
 
            
 
564
    
609
565
    prefClass.editorOtherFontsPrefs = {}
610
566
    for key in prefClass.editorOtherFontsDefaults.keys():
611
 
        prefClass.editorOtherFontsPrefs[key], ok = \
612
 
            prefClass.settings.readEntry("/eric3/Editor/Other Fonts/" + key,
613
 
                prefClass.editorOtherFontsDefaults[key])
614
 
                
 
567
        prefClass.editorOtherFontsPrefs[key] = \
 
568
            prefClass.settings.value("Editor/Other Fonts/" + key,
 
569
                QtCore.QVariant(prefClass.editorOtherFontsDefaults[key])).toString()
 
570
    
615
571
    prefClass.editorAPI = {}
616
572
    for key in prefClass.editorAPIDefaults.keys():
617
 
        ap, ok = prefClass.settings.readListEntry("/eric3/Editor/APIs/" + key)
618
 
        if ok:
619
 
            prefClass.editorAPI[key] = ap
 
573
        ap = prefClass.settings.value("Editor/APIs/" + key)
 
574
        if ap.isValid():
 
575
            apis = ap.toStringList()
 
576
            if len(apis) and apis[0].isEmpty():
 
577
                prefClass.editorAPI[key] = prefClass.editorAPIDefaults[key]
 
578
            else:
 
579
                prefClass.editorAPI[key] = apis
620
580
        else:
621
581
            prefClass.editorAPI[key] = prefClass.editorAPIDefaults[key]
622
 
        
 
582
    
623
583
    prefClass.editorLexerAssoc = {}
624
 
    keyList = prefClass.settings.entryList("/eric3/Editor/LexerAssociations")
 
584
    prefClass.settings.beginGroup("Editor/LexerAssociations")
 
585
    keyList = prefClass.settings.childKeys()
 
586
    prefClass.settings.endGroup()
625
587
    if len(keyList) == 0:
626
 
        keyList2 = prefClass.settings.entryList("/eric3/Editor/Lexers")
627
 
        if len(keyList2) > 0:
628
 
            # code to migrate extension based assocs to pattern based ones
629
 
            for key in keyList2:
630
 
                key = unicode(key)
631
 
                language, ok = \
632
 
                    prefClass.settings.readEntry("/eric3/Editor/Lexers/" + key)
633
 
                if ok:
634
 
                    prefClass.editorLexerAssoc["*.%s" % key] = language
635
 
                prefClass.settings.removeEntry("/eric3/Editor/Lexers/" + key)
636
 
            prefClass.settings.removeEntry("/eric3/Editor/Lexers")
637
 
        else:
638
 
            # build from scratch
639
 
            for key in prefClass.editorLexerAssocDefaults.keys():
640
 
                prefClass.editorLexerAssoc[key] = \
641
 
                    QString(prefClass.editorLexerAssocDefaults[key])
 
588
        # build from scratch
 
589
        for key in prefClass.editorLexerAssocDefaults.keys():
 
590
            prefClass.editorLexerAssoc[key] = \
 
591
                QtCore.QString(prefClass.editorLexerAssocDefaults[key])
642
592
    else:
643
593
        for key in keyList:
644
594
            key = unicode(key)
645
595
            if prefClass.editorLexerAssocDefaults.has_key(key):
646
596
                defaultValue = prefClass.editorLexerAssocDefaults[key]
647
597
            else:
648
 
                defaultValue = QString.null
649
 
            prefClass.editorLexerAssoc[key], ok = \
650
 
                prefClass.settings.readEntry("/eric3/Editor/LexerAssociations/" + key,
651
 
                    defaultValue)
652
 
    for key in prefClass.editorDefaultPatterns:
 
598
                defaultValue = QtCore.QString()
 
599
            prefClass.editorLexerAssoc[key] = \
 
600
                prefClass.settings.value("Editor/LexerAssociations/" + key,
 
601
                    QtCore.QVariant(defaultValue)).toString()
 
602
    # new default lexer associations
 
603
    for key in prefClass.editorLexerAssocDefaults.keys():
653
604
        if not prefClass.editorLexerAssoc.has_key(key):
654
605
            prefClass.editorLexerAssoc[key] = \
655
 
                QString(prefClass.editorLexerAssocDefaults[key])
 
606
                QtCore.QString(prefClass.editorLexerAssocDefaults[key])
 
607
    
 
608
    prefClass.editorTypingPrefs = {}
 
609
    for key in prefClass.editorTypingDefaults.keys():
 
610
        prefClass.editorTypingPrefs[key], ok = \
 
611
            prefClass.settings.value("Editor/Typing/" + key,
 
612
                QtCore.QVariant(prefClass.editorTypingDefaults[key])).toInt()
656
613
    
657
614
    # read the entries for the project settings
658
615
    prefClass.projectPrefs = {}
659
616
    for key in prefClass.projectDefaults.keys():
660
617
        prefClass.projectPrefs[key], ok = \
661
 
            prefClass.settings.readNumEntry("/eric3/Project/" + key,
662
 
                prefClass.projectDefaults[key])
 
618
            prefClass.settings.value("Project/" + key,
 
619
                QtCore.QVariant(prefClass.projectDefaults[key])).toInt()
 
620
    
 
621
    # read the entries for the project browser settings
 
622
    prefClass.projectBrowserColourPrefs = {}
 
623
    for key in prefClass.projectBrowserColourDefaults.keys():
 
624
        col = prefClass.settings.value("Project/Colour/" + key)
 
625
        if col.isValid():
 
626
            prefClass.projectBrowserColourPrefs[key] = QtGui.QColor(col.toString())
 
627
        else:
 
628
            prefClass.projectBrowserColourPrefs[key] = \
 
629
                prefClass.projectBrowserColourDefaults[key]
663
630
    
664
631
    # read the entries for the help settings
665
632
    prefClass.helpPrefs = {}
666
 
    for key in ["HelpViewerType"]:
667
 
        prefClass.helpPrefs[key], ok = \
668
 
            prefClass.settings.readNumEntry("/eric3/Help/" + key,
669
 
                prefClass.helpDefaults[key])
670
 
    for key in ["Webbrowser", "Pdfviewer", "CustomViewer", \
671
 
                "PythonDocDir", "QtDocDir", "Qt4DocDir"]:
672
 
        prefClass.helpPrefs[key], ok = \
673
 
            prefClass.settings.readEntry("/eric3/Help/" + key,
674
 
                prefClass.helpDefaults[key])
 
633
    for key in ["HelpViewerType", "SingleHelpWindow", "SaveGeometry"]:
 
634
        prefClass.helpPrefs[key], ok = \
 
635
            prefClass.settings.value("Help/" + key,
 
636
                QtCore.QVariant(prefClass.helpDefaults[key])).toInt()
 
637
    for key in ["CustomViewer", \
 
638
                "PythonDocDir", "QtDocDir", "Qt4DocDir", "PyQt4DocDir"]:
 
639
        prefClass.helpPrefs[key] = \
 
640
            prefClass.settings.value("Help/" + key,
 
641
                QtCore.QVariant(prefClass.helpDefaults[key])).toString()
675
642
    
676
643
    # read the entries for system settings
677
644
    prefClass.sysPrefs = {}
678
 
    prefClass.sysPrefs["StringEncoding"], ok = \
679
 
        prefClass.settings.readEntry("/eric3/System/StringEncoding",
680
 
            prefClass.sysDefaults["StringEncoding"])
681
 
            
 
645
    for key in ["StringEncoding", "IOEncoding"]: 
 
646
        prefClass.sysPrefs[key] = \
 
647
            prefClass.settings.value("System/" + key, 
 
648
                QtCore.QVariant(prefClass.sysDefaults[key])).toString()
 
649
    
682
650
    # read the entries for Qt settings
683
651
    prefClass.qtPrefs = {}
684
 
    for key in ["QtDir", "Qt4Dir"]:
685
 
        prefClass.qtPrefs[key], ok = \
686
 
            prefClass.settings.readEntry("/eric3/Qt/" + key,
687
 
                prefClass.qtDefaults[key])
688
 
    for key in ["ExportQtDir", "ExportQt4Dir"]:
689
 
        prefClass.qtPrefs[key], ok = \
690
 
            prefClass.settings.readNumEntry("/eric3/Qt/" + key,
691
 
                prefClass.qtDefaults[key])
692
 
            
 
652
    for key in ["QtDir", "Qt4Dir", "Qt4TranslationsDir", "QtToolsPrefix3", 
 
653
                "QtToolsPostfix3", "QtToolsPrefix4", "QtToolsPostfix4"]: 
 
654
        prefClass.qtPrefs[key] = \
 
655
            prefClass.settings.value("Qt/" + key, 
 
656
                QtCore.QVariant(prefClass.qtDefaults[key])).toString()
 
657
    for key in ["DisableQt3", "ExportQtDir", "ExportQt4Dir"]: 
 
658
        prefClass.qtPrefs[key], ok = \
 
659
            prefClass.settings.value("Qt/" + key, 
 
660
                QtCore.QVariant(prefClass.qtDefaults[key])).toInt()
 
661
    
693
662
    # read the entries for the display geometry
694
663
    prefClass.geometryPrefs = {}
695
664
    for key in prefClass.geometryDefaults.keys():
696
 
        v, ok = prefClass.settings.readEntry("/eric3/Geometry/" + key)
697
 
        if ok:
698
 
            prefClass.geometryPrefs[key] = eval(unicode(v))
 
665
        v = prefClass.settings.value("Geometry/" + key)
 
666
        if v.isValid():
 
667
            prefClass.geometryPrefs[key] = v.toByteArray()
699
668
        else:
700
669
            prefClass.geometryPrefs[key] = prefClass.geometryDefaults[key]
701
670
 
702
 
    # read the entries for the dock window layout
703
 
    prefClass.dockPrefs = {}
704
 
    for key in prefClass.dockDefaults.keys():
705
 
        v, ok = prefClass.settings.readEntry("/eric3/Docks/" + key)
706
 
        if ok:
707
 
            prefClass.dockPrefs[key] = unicode(v)
708
 
        else:
709
 
            prefClass.dockPrefs[key] = prefClass.dockDefaults[key]
710
 
        
711
671
    # read the entries for the printer settings
712
672
    prefClass.printerPrefs = {}
713
673
    for key in ["ColorMode", "FirstPageFirst", "Magnification", 
714
674
                "Orientation", "PageSize"]:
715
675
        prefClass.printerPrefs[key], ok = \
716
 
            prefClass.settings.readNumEntry("/eric3/Printer/" + key,
717
 
                prefClass.printerDefaults[key])
 
676
            prefClass.settings.value("Printer/" + key,
 
677
                QtCore.QVariant(prefClass.printerDefaults[key])).toInt()
718
678
    for key in ["PrinterName", "HeaderFont"]:
719
 
        prefClass.printerPrefs[key], ok = \
720
 
            prefClass.settings.readEntry("/eric3/Printer/" + key,
721
 
                prefClass.printerDefaults[key])
722
 
                
 
679
        prefClass.printerPrefs[key] = \
 
680
            prefClass.settings.value("Printer/" + key,
 
681
                QtCore.QVariant(prefClass.printerDefaults[key])).toString()
 
682
    
723
683
    # read the entries for the shell settings
724
684
    prefClass.shellPrefs = {}
725
685
    for key in prefClass.shellDefaults.keys():
726
686
        prefClass.shellPrefs[key], ok = \
727
 
            prefClass.settings.readNumEntry("/eric3/Shell/" + key,
728
 
                prefClass.shellDefaults[key])
729
 
                
 
687
            prefClass.settings.value("Shell/" + key,
 
688
                QtCore.QVariant(prefClass.shellDefaults[key])).toInt()
 
689
    
730
690
    # read the entries for the corba settings
731
691
    prefClass.corbaPrefs = {}
732
692
    for key in ["omniidl"]:
733
 
        prefClass.corbaPrefs[key], ok = \
734
 
            prefClass.settings.readEntry("/eric3/Corba/" + key,
735
 
                prefClass.corbaDefaults[key])
736
 
                
 
693
        prefClass.corbaPrefs[key] = \
 
694
            prefClass.settings.value("Corba/" + key,
 
695
                QtCore.QVariant(prefClass.corbaDefaults[key])).toString()
 
696
    
737
697
    # read the entries for the refactoring settings
738
698
    prefClass.refactoringPrefs = {}
739
699
    for key in prefClass.refactoringDefaults.keys():
740
700
        prefClass.refactoringPrefs[key], ok = \
741
 
            prefClass.settings.readNumEntry("/eric3/Refactoring/" + key,
742
 
                prefClass.refactoringDefaults[key])
743
 
                
 
701
            prefClass.settings.value("Refactoring/" + key,
 
702
                QtCore.QVariant(prefClass.refactoringDefaults[key])).toInt()
 
703
    
744
704
    # read the entries for the user settings
745
705
    prefClass.userPrefs = {}
746
706
    for key in prefClass.userDefaults.keys():
747
707
        if key in ["MailServerAuthentication"]:
748
708
            prefClass.userPrefs[key], ok = \
749
 
                prefClass.settings.readNumEntry("/eric3/User/" + key,
750
 
                    prefClass.userDefaults[key])
 
709
                prefClass.settings.value("User/" + key,
 
710
                    QtCore.QVariant(prefClass.userDefaults[key])).toInt()
751
711
        else:
752
 
            prefClass.userPrefs[key], ok = \
753
 
                prefClass.settings.readEntry("/eric3/User/" + key,
754
 
                    prefClass.userDefaults[key])
755
 
                    
 
712
            prefClass.userPrefs[key] = \
 
713
                prefClass.settings.value("User/" + key,
 
714
                    QtCore.QVariant(prefClass.userDefaults[key])).toString()
 
715
    
756
716
    # read the entries for the VCS settings
757
717
    prefClass.vcsPrefs = {}
758
718
    for key in prefClass.vcsDefaults.keys():
759
719
        prefClass.vcsPrefs[key], ok = \
760
 
            prefClass.settings.readNumEntry("/eric3/VCS/" + key,
761
 
                prefClass.vcsDefaults[key])
 
720
            prefClass.settings.value("VCS/" + key,
 
721
                QtCore.QVariant(prefClass.vcsDefaults[key])).toInt()
762
722
    
763
723
    # read the entries for the tasks settings
764
724
    prefClass.tasksPrefs = {}
765
725
    for key in prefClass.tasksDefaults.keys():
766
726
        if key in ["TasksColour", "TasksBugfixColour", 
767
727
                   "TasksBgColour", "TasksProjectBgColour"]:
768
 
            col, ok = prefClass.settings.readEntry("/eric3/Tasks/" + key)
769
 
            if ok:
770
 
                prefClass.tasksPrefs[key] = QColor(col)
 
728
            col = prefClass.settings.value("Tasks/" + key)
 
729
            if col.isValid():
 
730
                prefClass.tasksPrefs[key] = QtGui.QColor(col.toString())
771
731
            else:
772
732
                prefClass.tasksPrefs[key] = prefClass.tasksDefaults[key]
773
733
        else:
774
 
            prefClass.tasksPrefs[key], ok = \
775
 
                prefClass.settings.readEntry("/eric3/Tasks/" + key,
776
 
                    prefClass.tasksDefaults[key])
 
734
            prefClass.tasksPrefs[key] = \
 
735
                prefClass.settings.value("Tasks/" + key,
 
736
                    QtCore.QVariant(prefClass.tasksDefaults[key])).toString()
777
737
 
778
738
    # read the entries for templates settings
779
739
    prefClass.templatesPrefs = {}
780
740
    for key in prefClass.templatesDefaults.keys():
781
741
        if key in ["SeparatorChar"]:
782
 
            prefClass.templatesPrefs[key], ok = \
783
 
                prefClass.settings.readEntry("/eric3/Templates/" + key,
784
 
                    prefClass.templatesDefaults[key])
 
742
            prefClass.templatesPrefs[key] = \
 
743
                prefClass.settings.value("Templates/" + key,
 
744
                    QtCore.QVariant(prefClass.templatesDefaults[key])).toString()
785
745
        else:
786
746
            prefClass.templatesPrefs[key], ok = \
787
 
                prefClass.settings.readNumEntry("/eric3/Templates/" + key,
788
 
                    prefClass.templatesDefaults[key])    
 
747
                prefClass.settings.value("Templates/" + key,
 
748
                    QtCore.QVariant(prefClass.templatesDefaults[key])).toInt()
 
749
    
 
750
    # read the entries for the graphics settings
 
751
    prefClass.graphicsPrefs = {}
 
752
    for key in ["Font"]:
 
753
        prefClass.graphicsPrefs[key] = \
 
754
            prefClass.settings.value("Graphics/" + key,
 
755
                QtCore.QVariant(prefClass.graphicsDefaults[key])).toString()
789
756
    
790
757
def savePreferences(prefClass = Prefs):
791
758
    """
793
760
    
794
761
    @param prefClass preferences class used as the storage area
795
762
    """
 
763
    # write the general entries
 
764
    prefClass.settings.setValue("General/Configured", 
 
765
        QtCore.QVariant(int(prefClass.configured)))
 
766
    
796
767
    # write the entries for the variables display
797
768
    for key in prefClass.varPrefs.keys():
798
 
        prefClass.settings.writeEntry("/eric3/Variables/" + key,
799
 
            unicode(prefClass.varPrefs[key]))
 
769
        prefClass.settings.setValue("Variables/" + key,
 
770
            QtCore.QVariant(unicode(prefClass.varPrefs[key])))
800
771
 
801
772
    # write the entries for the debugger
802
773
    for key in prefClass.debuggerPrefs.keys():
803
 
        prefClass.settings.writeEntry("/eric3/Debugger/" + key,
804
 
            prefClass.debuggerPrefs[key])
 
774
        prefClass.settings.setValue("Debugger/" + key,
 
775
            QtCore.QVariant(prefClass.debuggerPrefs[key]))
805
776
 
806
777
    # write the entries for the general ui settings
807
 
    if prefClass.uiPrefs["Language"] is None:
808
 
        prefClass.settings.writeEntry("/eric3/UI/Language", "None")
809
 
    else:
810
 
        prefClass.settings.writeEntry("/eric3/UI/Language", prefClass.uiPrefs["Language"])
811
 
    prefClass.settings.writeEntry("/eric3/UI/ViewManager", prefClass.uiPrefs["ViewManager"])
812
 
    prefClass.settings.writeEntry("/eric3/UI/LayoutType",
813
 
        prefClass.uiPrefs["LayoutType"])
814
 
    prefClass.settings.writeEntry("/eric3/UI/LayoutShellEmbedded",
815
 
        prefClass.uiPrefs["LayoutShellEmbedded"])
816
 
    prefClass.settings.writeEntry("/eric3/UI/LayoutFileBrowserEmbedded",
817
 
        prefClass.uiPrefs["LayoutFileBrowserEmbedded"])
818
 
    prefClass.settings.writeEntry("/eric3/UI/BrowsersListFoldersFirst", 
819
 
        prefClass.uiPrefs["BrowsersListFoldersFirst"])
820
 
    prefClass.settings.writeEntry("/eric3/UI/BrowsersHideNonPublic",
821
 
        prefClass.uiPrefs["BrowsersHideNonPublic"])
822
 
    prefClass.settings.writeEntry("/eric3/UI/SingleApplicationMode", 
823
 
        prefClass.uiPrefs["SingleApplicationMode"])
824
 
    prefClass.settings.writeEntry("/eric3/UI/CaptionShowsFilename", 
825
 
        prefClass.uiPrefs["CaptionShowsFilename"])
826
 
    prefClass.settings.writeEntry("/eric3/UI/ViewProfiles",
827
 
        unicode(prefClass.uiPrefs["ViewProfiles"]))
 
778
    for key in prefClass.uiPrefs.keys():
 
779
        if key == "Language":
 
780
            if prefClass.uiPrefs["Language"] is None:
 
781
                prefClass.settings.setValue("UI/Language", QtCore.QVariant("None"))
 
782
            else:
 
783
                prefClass.settings.setValue("UI/Language", 
 
784
                    QtCore.QVariant(prefClass.uiPrefs["Language"]))
 
785
        elif key == "ViewProfiles":
 
786
            prefClass.settings.setValue("UI/" + key,
 
787
                QtCore.QVariant(unicode(prefClass.uiPrefs[key])))
 
788
        else:
 
789
            prefClass.settings.setValue("UI/" + key,
 
790
                QtCore.QVariant(prefClass.uiPrefs[key]))
828
791
 
829
792
    # write the entries for the icon settings
830
793
    for key in prefClass.iconsPrefs.keys():
831
 
        prefClass.settings.writeEntry("/eric3/UI/Icons/" + key,
832
 
            prefClass.iconsPrefs[key])
833
 
            
 
794
        prefClass.settings.setValue("UI/Icons/" + key,
 
795
            QtCore.QVariant(prefClass.iconsPrefs[key]))
 
796
    
834
797
    # write the entries for the editor settings
835
798
    for key in prefClass.editorPrefs.keys():
836
 
        prefClass.settings.writeEntry("/eric3/Editor/" + key,
837
 
            prefClass.editorPrefs[key])
838
 
            
839
 
    for key in prefClass.editorColourDefaults.keys():
840
 
        prefClass.settings.writeEntry("/eric3/Editor/Colour/" + key,
841
 
            prefClass.editorColourPrefs[key].name())
 
799
        prefClass.settings.setValue("Editor/" + key,
 
800
            QtCore.QVariant(prefClass.editorPrefs[key]))
 
801
    
 
802
    for key in prefClass.editorColourPrefs.keys():
 
803
        prefClass.settings.setValue("Editor/Colour/" + key,
 
804
            QtCore.QVariant(prefClass.editorColourPrefs[key].name()))
842
805
 
843
 
    for key in prefClass.editorOtherFontsDefaults.keys():
844
 
        prefClass.settings.writeEntry("/eric3/Editor/Other Fonts/" + key,
845
 
            prefClass.editorOtherFontsPrefs[key])
 
806
    for key in prefClass.editorOtherFontsPrefs.keys():
 
807
        prefClass.settings.setValue("Editor/Other Fonts/" + key,
 
808
            QtCore.QVariant(prefClass.editorOtherFontsPrefs[key]))
846
809
 
847
810
    for key in prefClass.editorAPI.keys():
848
 
        prefClass.settings.writeEntry("/eric3/Editor/APIs/" + key,
849
 
            prefClass.editorAPI[key])
 
811
        prefClass.settings.setValue("Editor/APIs/" + key,
 
812
            QtCore.QVariant(prefClass.editorAPI[key]))
850
813
    
851
814
    # first remove lexer associations that no longer exist, than save the rest
852
 
    keyList = prefClass.settings.entryList("/eric3/Editor/LexerAssociations")
 
815
    prefClass.settings.beginGroup("Editor/LexerAssociations")
 
816
    keyList = prefClass.settings.childKeys()
 
817
    prefClass.settings.endGroup()
853
818
    for key in keyList:
854
819
        key = unicode(key)
855
820
        if not prefClass.editorLexerAssoc.has_key(key):
856
 
            prefClass.settings.removeEntry("/eric3/Editor/LexerAssociations/" + key)
 
821
            prefClass.settings.remove("Editor/LexerAssociations/" + key)
857
822
    for key in prefClass.editorLexerAssoc.keys():
858
 
        prefClass.settings.writeEntry("/eric3/Editor/LexerAssociations/" + key,
859
 
            prefClass.editorLexerAssoc[key])
 
823
        prefClass.settings.setValue("Editor/LexerAssociations/" + key,
 
824
            QtCore.QVariant(prefClass.editorLexerAssoc[key]))
 
825
    
 
826
    for key in prefClass.editorTypingPrefs.keys():
 
827
        prefClass.settings.setValue("Editor/Typing/" + key,
 
828
            QtCore.QVariant(prefClass.editorTypingPrefs[key]))
860
829
    
861
830
    # write the entries for the project settings
862
831
    for key in prefClass.projectPrefs.keys():
863
 
        prefClass.settings.writeEntry("/eric3/Project/" + key,
864
 
            prefClass.projectPrefs[key])
865
 
            
 
832
        prefClass.settings.setValue("Project/" + key,
 
833
            QtCore.QVariant(prefClass.projectPrefs[key]))
 
834
    
 
835
    # write the entries for the project browser settings
 
836
    for key in prefClass.projectBrowserColourPrefs.keys():
 
837
        prefClass.settings.setValue("Project/Colour/" + key,
 
838
            QtCore.QVariant(prefClass.projectBrowserColourPrefs[key].name()))
 
839
 
866
840
    # write the entries for the help settings
867
841
    for key in prefClass.helpPrefs.keys():
868
 
        prefClass.settings.writeEntry("/eric3/Help/" + key,
869
 
            prefClass.helpPrefs[key])
870
 
            
 
842
        prefClass.settings.setValue("Help/" + key,
 
843
            QtCore.QVariant(prefClass.helpPrefs[key]))
 
844
    
871
845
    # write the entries for the system settings
872
 
    prefClass.settings.writeEntry("/eric3/System/StringEncoding",
873
 
        prefClass.sysPrefs["StringEncoding"])
874
 
        
 
846
    for key in prefClass.sysPrefs.keys():
 
847
        prefClass.settings.setValue("System/" + key,
 
848
            QtCore.QVariant(prefClass.sysPrefs[key]))
 
849
    
875
850
    # write the entries for the Qt settings
876
851
    for key in prefClass.qtPrefs.keys():
877
 
        prefClass.settings.writeEntry("/eric3/Qt/" + key,
878
 
            prefClass.qtPrefs[key])
879
 
        
 
852
        prefClass.settings.setValue("Qt/" + key,
 
853
            QtCore.QVariant(prefClass.qtPrefs[key]))
 
854
    
880
855
    # write the entries for the display geometry
881
856
    for key in prefClass.geometryPrefs.keys():
882
 
        prefClass.settings.writeEntry("/eric3/Geometry/" + key,
883
 
            unicode(prefClass.geometryPrefs[key]))
884
 
        
885
 
    # write the entries for the dock layout
886
 
    for key in prefClass.dockPrefs.keys():
887
 
        prefClass.settings.writeEntry("/eric3/Docks/" + key,
888
 
            unicode(prefClass.dockPrefs[key]))
889
 
        
 
857
        prefClass.settings.setValue("Geometry/" + key,
 
858
            QtCore.QVariant(prefClass.geometryPrefs[key]))
 
859
    
890
860
    # write the entries for the printer settings
891
861
    for key in prefClass.printerPrefs.keys():
892
 
        prefClass.settings.writeEntry("/eric3/Printer/" + key,
893
 
                prefClass.printerPrefs[key])
894
 
        
 
862
        prefClass.settings.setValue("Printer/" + key,
 
863
            QtCore.QVariant(prefClass.printerPrefs[key]))
 
864
    
895
865
    # write the entries for the shell settings
896
866
    for key in prefClass.shellPrefs.keys():
897
 
        prefClass.settings.writeEntry("/eric3/Shell/" + key,
898
 
                prefClass.shellPrefs[key])
899
 
                
 
867
        prefClass.settings.setValue("Shell/" + key,
 
868
            QtCore.QVariant(prefClass.shellPrefs[key]))
 
869
    
900
870
    # write the entries for the corba settings
901
871
    for key in prefClass.corbaPrefs.keys():
902
 
        prefClass.settings.writeEntry("/eric3/Corba/" + key,
903
 
                prefClass.corbaPrefs[key])
904
 
        
 
872
        prefClass.settings.setValue("Corba/" + key,
 
873
            QtCore.QVariant(prefClass.corbaPrefs[key]))
 
874
    
905
875
    # write the entries for the refactoring settings
906
876
    for key in prefClass.refactoringPrefs.keys():
907
 
        prefClass.settings.writeEntry("/eric3/Refactoring/" + key,
908
 
                prefClass.refactoringPrefs[key])
909
 
                
 
877
        prefClass.settings.setValue("Refactoring/" + key,
 
878
            QtCore.QVariant(prefClass.refactoringPrefs[key]))
 
879
    
910
880
    # write the entries for the user settings
911
881
    for key in prefClass.userPrefs.keys():
912
 
        prefClass.settings.writeEntry("/eric3/User/" + key,
913
 
                prefClass.userPrefs[key])
914
 
                
 
882
        prefClass.settings.setValue("User/" + key,
 
883
            QtCore.QVariant(prefClass.userPrefs[key]))
 
884
    
915
885
    # write the entries for the VCS settings
916
886
    for key in prefClass.vcsPrefs.keys():
917
 
        prefClass.settings.writeEntry("/eric3/VCS/" + key,
918
 
                prefClass.vcsPrefs[key])
919
 
                
 
887
        prefClass.settings.setValue("VCS/" + key,
 
888
            QtCore.QVariant(prefClass.vcsPrefs[key]))
 
889
    
920
890
    # write the entries for the tasks settings
921
891
    for key in prefClass.tasksPrefs.keys():
922
892
        if key in ["TasksColour", "TasksBugfixColour",
923
893
                   "TasksBgColour", "TasksProjectBgColour"]:
924
 
            prefClass.settings.writeEntry("/eric3/Tasks/" + key,
925
 
                    prefClass.tasksPrefs[key].name())
 
894
            prefClass.settings.setValue("Tasks/" + key,
 
895
                QtCore.QVariant(prefClass.tasksPrefs[key].name()))
926
896
        else:
927
 
            prefClass.settings.writeEntry("/eric3/Tasks/" + key,
928
 
                    prefClass.tasksPrefs[key])
 
897
            prefClass.settings.setValue("Tasks/" + key,
 
898
                QtCore.QVariant(prefClass.tasksPrefs[key]))
929
899
    
930
900
    # write the entries for the templates settings
931
901
    for key in prefClass.templatesPrefs.keys():
932
 
        prefClass.settings.writeEntry("/eric3/Templates/" + key,
933
 
                prefClass.templatesPrefs[key])
934
 
    
935
 
def readToolbarSettings(mw, tbs, prefClass = Prefs):
936
 
    """
937
 
    Module function to read the toolbar settings from the central store.
938
 
    
939
 
    In addition to reading and storing the values, the toolbars are
940
 
    set accordingly.
941
 
    
942
 
    @param mw reference to the main window (QMainWindow)
943
 
    @param tbs list of tuples defining the different toolbars
944
 
    @param prefClass preferences class used as the storage area
945
 
    """
946
 
    tbList = []
947
 
    for ind, (dummy, tb) in tbs.items():
948
 
        hidden, ok = prefClass.settings.readNumEntry("/eric3/Toolbars/%d/hidden" % ind, 0)
949
 
        dock, ok = prefClass.settings.readNumEntry("/eric3/Toolbars/%d/dockarea" % ind, Qt.DockTop)
950
 
        index, ok = prefClass.settings.readNumEntry("/eric3/Toolbars/%d/index" % ind, ind)
951
 
        nl, ok = prefClass.settings.readNumEntry("/eric3/Toolbars/%d/nl" % ind, 0)
952
 
        eo, ok = prefClass.settings.readNumEntry("/eric3/Toolbars/%d/extraOffset" % ind, 0)
953
 
        tbList.append((index, dock, nl, eo, hidden, tb))
954
 
 
955
 
    tbList.sort()
956
 
    
957
 
    for index, dock, nl, eo, hidden, tb in tbList:
958
 
        try:
959
 
            dock = Qt.Dock(dock)
960
 
        except AttributeError:
961
 
            pass
962
 
        mw.moveDockWindow(tb, dock, nl, index, eo)
963
 
        if hidden:
964
 
            tb.hide()
965
 
        else:
966
 
            tb.show()
967
 
        
968
 
def saveToolbarSettings(mw, tbs, prefClass = Prefs):
969
 
    """
970
 
    Module function to write the toolbar settings to the central store.
971
 
    
972
 
    @param prefClass preferences class used as the storage area
973
 
    """
974
 
    for ind, (text, tb) in tbs.items():
975
 
        ok, dock, index, nl, eo = mw.getLocation(tb)
976
 
        prefClass.settings.writeEntry("/eric3/Toolbars/%d/hidden" % ind, tb.isHidden())
977
 
        prefClass.settings.writeEntry("/eric3/Toolbars/%d/text" % ind, text)
978
 
        if ok:
979
 
            prefClass.settings.writeEntry("/eric3/Toolbars/%d/dockarea" % ind, dock)
980
 
            prefClass.settings.writeEntry("/eric3/Toolbars/%d/index" % ind, index)
981
 
            prefClass.settings.writeEntry("/eric3/Toolbars/%d/nl" % ind, nl)
982
 
            prefClass.settings.writeEntry("/eric3/Toolbars/%d/extraOffset" % ind, eo)
983
 
        
984
 
def readToolsMenu(prefClass = Prefs):
985
 
    """
986
 
    Module function to read the tools menu configuration.
987
 
    
988
 
    @param prefClass preferences class used as the storage area
989
 
    @return list of tuples defing the tools menu entries
990
 
    """
991
 
    toollist = []
992
 
    items, ok = prefClass.settings.readNumEntry("/eric3/Toolsmenu/Items", 0)
993
 
    for ind in range(items):
994
 
        menutext, ok1 = prefClass.settings.readEntry("/eric3/Toolsmenu/%d/Menutext" % ind)
995
 
        executable, ok2 = prefClass.settings.readEntry("/eric3/Toolsmenu/%d/Executable" % ind)
996
 
        arguments, ok3 = prefClass.settings.readEntry("/eric3/Toolsmenu/%d/Arguments" % ind)
997
 
        redirect, ok4 = prefClass.settings.readNumEntry("/eric3/Toolsmenu/%d/Redirect" % ind, 0)
998
 
        
999
 
        if ok1 and ok2 and ok3:
1000
 
            tool = (unicode(menutext), unicode(executable), unicode(arguments), redirect)
1001
 
            toollist.append(tool)
 
902
        prefClass.settings.setValue("Templates/" + key,
 
903
            QtCore.QVariant(prefClass.templatesPrefs[key]))
 
904
    
 
905
    # write the entries for the graphics settings
 
906
    for key in prefClass.graphicsPrefs.keys():
 
907
        prefClass.settings.setValue("Graphics/" + key,
 
908
            QtCore.QVariant(prefClass.graphicsPrefs[key]))
 
909
    
 
910
def readToolGroups(prefClass = Prefs):
 
911
    """
 
912
    Module function to read the tool groups configuration.
 
913
    
 
914
    @param prefClass preferences class used as the storage area
 
915
    @return list of tuples defing the tool groups
 
916
    """
 
917
    toolGroups = []
 
918
    groups, ok = prefClass.settings.value("Toolgroups/Groups", 
 
919
        QtCore.QVariant(0)).toInt()
 
920
    for groupIndex in range(groups):
 
921
        groupName = \
 
922
            prefClass.settings.value("Toolgroups/%02d/Name" % groupIndex).toString()
 
923
        group = [unicode(groupName), []]
 
924
        items, ok = prefClass.settings.value("Toolgroups/%02d/Items" % groupIndex, 
 
925
            QtCore.QVariant(0)).toInt()
 
926
        for ind in range(items):
 
927
            menutext = prefClass.settings.value(\
 
928
                "Toolgroups/%02d/%02d/Menutext" % (groupIndex, ind)).toString()
 
929
            icon = prefClass.settings.value(\
 
930
                "Toolgroups/%02d/%02d/Icon" % (groupIndex, ind)).toString()
 
931
            executable = prefClass.settings.value(\
 
932
                "Toolgroups/%02d/%02d/Executable" % (groupIndex, ind)).toString()
 
933
            arguments = prefClass.settings.value(\
 
934
                "Toolgroups/%02d/%02d/Arguments" % (groupIndex, ind)).toString()
 
935
            redirect = prefClass.settings.value(\
 
936
                "Toolgroups/%02d/%02d/Redirect" % (groupIndex, ind)).toString()
1002
937
            
1003
 
    return toollist
 
938
            if not menutext.isEmpty():
 
939
                if unicode(menutext) == '--':
 
940
                    tool = {
 
941
                        'menutext' : '--',
 
942
                        'icon' : '',
 
943
                        'executable' : '',
 
944
                        'arguments' : '',
 
945
                        'redirect' : 'no',
 
946
                    }
 
947
                    group[1].append(tool)
 
948
                elif not executable.isEmpty():
 
949
                    tool = {
 
950
                        'menutext' : unicode(menutext),
 
951
                        'icon' : unicode(icon),
 
952
                        'executable' : unicode(executable),
 
953
                        'arguments' : unicode(arguments),
 
954
                        'redirect' : unicode(redirect),
 
955
                    }
 
956
                    group[1].append(tool)
 
957
        toolGroups.append(group)
 
958
    currentGroup, ok = prefClass.settings.value("Toolgroups/Current Group", 
 
959
        QtCore.QVariant(-1)).toInt()
 
960
    return toolGroups, currentGroup
1004
961
    
1005
 
def saveToolsMenu(toollist, prefClass = Prefs):
 
962
def saveToolGroups(toolGroups, currentGroup, prefClass = Prefs):
1006
963
    """
1007
 
    Module function to write the tools menu configuration.
 
964
    Module function to write the tool groups configuration.
1008
965
    
 
966
    @param toolGroups reference to the list of tool groups
 
967
    @param currentGroup index of the currently selected tool group (integer)
1009
968
    @param prefClass preferences class used as the storage area
1010
969
    """
1011
 
    # first step, remove all tool menu entries
1012
 
    items, ok = prefClass.settings.readNumEntry("/eric3/Toolsmenu/Items", 0)
1013
 
    for ind in range(items):
1014
 
        prefClass.settings.removeEntry("/eric3/Toolsmenu/%d/Menutext" % ind)
1015
 
        prefClass.settings.removeEntry("/eric3/Toolsmenu/%d/Executable" % ind)
1016
 
        prefClass.settings.removeEntry("/eric3/Toolsmenu/%d/Arguments" % ind)
1017
 
        prefClass.settings.removeEntry("/eric3/Toolsmenu/%d/Redirect" % ind)
1018
 
        
1019
 
    # second step, write the menu entries
1020
 
    prefClass.settings.writeEntry("/eric3/Toolsmenu/Items", len(toollist))
1021
 
    ind = 0
1022
 
    for tool in toollist:
1023
 
        prefClass.settings.writeEntry("/eric3/Toolsmenu/%d/Menutext" % ind, tool[0])
1024
 
        prefClass.settings.writeEntry("/eric3/Toolsmenu/%d/Executable" % ind, tool[1])
1025
 
        prefClass.settings.writeEntry("/eric3/Toolsmenu/%d/Arguments" % ind, tool[2])
1026
 
        prefClass.settings.writeEntry("/eric3/Toolsmenu/%d/Redirect" % ind, tool[3])
1027
 
        ind += 1
 
970
    # first step, remove all tool group entries
 
971
    prefClass.settings.remove("Toolgroups")
 
972
    
 
973
    # second step, write the tool group entries
 
974
    prefClass.settings.setValue("Toolgroups/Groups", QtCore.QVariant(len(toolGroups)))
 
975
    groupIndex = 0
 
976
    for group in toolGroups:
 
977
        prefClass.settings.setValue("Toolgroups/%02d/Name" % groupIndex,
 
978
            QtCore.QVariant(group[0]))
 
979
        prefClass.settings.setValue("Toolgroups/%02d/Items" % groupIndex,
 
980
            QtCore.QVariant(len(group[1])))
 
981
        ind = 0
 
982
        for tool in group[1]:
 
983
            prefClass.settings.setValue(\
 
984
                "Toolgroups/%02d/%02d/Menutext" % (groupIndex, ind), 
 
985
                QtCore.QVariant(tool['menutext']))
 
986
            prefClass.settings.setValue(\
 
987
                "Toolgroups/%02d/%02d/Icon" % (groupIndex, ind), 
 
988
                QtCore.QVariant(tool['icon']))
 
989
            prefClass.settings.setValue(\
 
990
                "Toolgroups/%02d/%02d/Executable" % (groupIndex, ind), 
 
991
                QtCore.QVariant(tool['executable']))
 
992
            prefClass.settings.setValue(\
 
993
                "Toolgroups/%02d/%02d/Arguments" % (groupIndex, ind), 
 
994
                QtCore.QVariant(tool['arguments']))
 
995
            prefClass.settings.setValue(\
 
996
                "Toolgroups/%02d/%02d/Redirect" % (groupIndex, ind), 
 
997
                QtCore.QVariant(tool['redirect']))
 
998
            ind += 1
 
999
        groupIndex += 1
 
1000
    prefClass.settings.setValue(\
 
1001
        "Toolgroups/Current Group", QtCore.QVariant(currentGroup))
1028
1002
    
1029
1003
def initPreferences():
1030
1004
    """
1031
1005
    Module function to initialize the central configuration store. 
1032
 
    
1033
 
    This function is called once upon import of the module.
1034
1006
    """
1035
 
    Prefs.settings = QSettings()
1036
 
    if sys.platform == "win32":
1037
 
        Prefs.settings.setPath("Eric", "", QSettings.User)
1038
 
    else:
1039
 
        hp = QDir.homeDirPath()
1040
 
        dn = QDir(hp)
1041
 
        dn.mkdir(".eric3")
1042
 
        eric3rcPath = os.path.join(unicode(hp), ".eric3", "eric3rc")
1043
 
        if os.path.exists(eric3rcPath):
1044
 
            os.rename(eric3rcPath, os.path.join(unicode(hp), ".qt", "eric3rc"))
 
1007
    Prefs.settings = QtCore.QSettings(QtCore.QSettings.UserScope, 
 
1008
        settingsNameOrganization, settingsNameGlobal)
 
1009
    if sys.platform != "win32":
 
1010
        hp = QtCore.QDir.homePath()
 
1011
        dn = QtCore.QDir(hp)
 
1012
        dn.mkdir(".eric4")
1045
1013
    readPreferences(Prefs)
1046
1014
    
1047
 
def syncPreferences():
 
1015
def syncPreferences(prefClass = Prefs):
1048
1016
    """
1049
1017
    Module function to sync the preferences to disk.
1050
1018
    
1051
 
    In addition to synching, the central configuration store is reinitialized as well.
 
1019
    In addition to syncing, the central configuration store is reinitialized as well.
 
1020
    
 
1021
    @param prefClass preferences class used as the storage area
1052
1022
    """
1053
 
    savePreferences(Prefs)
 
1023
    prefClass.configured = 1
 
1024
    savePreferences(prefClass)
1054
1025
    initPreferences()
1055
1026
    
 
1027
def isConfigured(prefClass = Prefs):
 
1028
    """
 
1029
    Module function to check, if the the application has been configured.
 
1030
    
 
1031
    @param prefClass preferences class used as the storage area
 
1032
    @return flag indicating the configured status (boolean)
 
1033
    """
 
1034
    return prefClass.configured
 
1035
    
 
1036
def initRecentSettings():
 
1037
    """
 
1038
    Module function to initialize the central configuration store for recently
 
1039
    opened files and projects. 
 
1040
    
 
1041
    This function is called once upon import of the module.
 
1042
    """
 
1043
    Prefs.rsettings = QtCore.QSettings(QtCore.QSettings.UserScope, 
 
1044
        settingsNameOrganization, settingsNameRecent)
 
1045
    
1056
1046
def getVarFilters(prefClass = Prefs):
1057
1047
    """
1058
1048
    Module function to retrieve the variables filter settings.
1238
1228
    @param prefClass preferences class used as the storage area
1239
1229
    @return the requested editor font (QFont)
1240
1230
    """
1241
 
    f = QFont()
 
1231
    f = QtGui.QFont()
1242
1232
    f.fromString(prefClass.editorOtherFontsPrefs[key])
1243
1233
    return f
1244
1234
    
1302
1292
    for pattern, language in prefClass.editorLexerAssoc.items():
1303
1293
        if fnmatch.fnmatch(filename, pattern):
1304
1294
            return unicode(language)
1305
 
        
 
1295
    
1306
1296
    return ""
1307
1297
    
 
1298
def getEditorTyping(key, prefClass = Prefs):
 
1299
    """
 
1300
    Module function to retrieve the various editor typing settings.
 
1301
    
 
1302
    @param key the key of the value to get
 
1303
    @param prefClass preferences class used as the storage area
 
1304
    @return the requested editor setting
 
1305
    """
 
1306
    return prefClass.editorTypingPrefs[key]
 
1307
    
 
1308
def setEditorTyping(key, value, prefClass = Prefs):
 
1309
    """
 
1310
    Module function to store the various editor typing settings.
 
1311
    
 
1312
    @param key the key of the setting to be set
 
1313
    @param value the value to be set
 
1314
    @param prefClass preferences class used as the storage area
 
1315
    """
 
1316
    prefClass.editorTypingPrefs[key] = value
 
1317
    
1308
1318
def getPrinter(key, prefClass = Prefs):
1309
1319
    """
1310
1320
    Module function to retrieve the various printer settings.
1314
1324
    @return the requested printer setting
1315
1325
    """
1316
1326
    if key in ["HeaderFont"]:
1317
 
        f = QFont()
 
1327
        f = QtGui.QFont()
1318
1328
        f.fromString(prefClass.printerPrefs[key])
1319
1329
        return f
1320
1330
    else:
1373
1383
    """
1374
1384
    prefClass.projectPrefs[key] = value
1375
1385
    
 
1386
def getProjectBrowserColour(key, prefClass = Prefs):
 
1387
    """
 
1388
    Module function to retrieve the various project browser colours.
 
1389
    
 
1390
    @param key the key of the value to get
 
1391
    @param prefClass preferences class used as the storage area
 
1392
    @return the requested project browser colour
 
1393
    """
 
1394
    return prefClass.projectBrowserColourPrefs[key]
 
1395
    
 
1396
def setProjectBrowserColour(key, value, prefClass = Prefs):
 
1397
    """
 
1398
    Module function to store the various project browser colours.
 
1399
    
 
1400
    @param key the key of the colour to be set
 
1401
    @param value the colour to be set
 
1402
    @param prefClass preferences class used as the storage area
 
1403
    """
 
1404
    prefClass.projectBrowserColourPrefs[key] = value
 
1405
    
 
1406
def getQt4DocDir(prefClass = Prefs):
 
1407
    """
 
1408
    Module function to retrieve the Qt4DocDir setting.
 
1409
    
 
1410
    @param prefClass preferences class used as the storage area
 
1411
    @return the requested Qt4DocDir setting (string)
 
1412
    """
 
1413
    if prefClass.helpPrefs["Qt4DocDir"].isEmpty():
 
1414
        return os.getenv("QT4DOCDIR", "")
 
1415
    else:
 
1416
        return unicode(prefClass.helpPrefs["Qt4DocDir"])
 
1417
    
1376
1418
def getHelp(key, prefClass = Prefs):
1377
1419
    """
1378
1420
    Module function to retrieve the various help settings.
1427
1469
    
1428
1470
def getQt4Dir(prefClass = Prefs):
1429
1471
    """
1430
 
    Module function to retrieve the QtDir setting.
 
1472
    Module function to retrieve the Qt4Dir setting.
1431
1473
    
1432
1474
    @param prefClass preferences class used as the storage area
1433
 
    @return the requested QtDir setting (string)
 
1475
    @return the requested Qt4Dir setting (string)
1434
1476
    """
1435
1477
    if prefClass.qtPrefs["Qt4Dir"].isEmpty():
1436
1478
        return os.getenv("QT4DIR", "")
1437
1479
    else:
1438
1480
        return unicode(prefClass.qtPrefs["Qt4Dir"])
1439
1481
    
 
1482
def getQt4TranslationsDir(prefClass = Prefs):
 
1483
    """
 
1484
    Module function to retrieve the Qt4TranslationsDir setting.
 
1485
    
 
1486
    @param prefClass preferences class used as the storage area
 
1487
    @return the requested Qt4TranslationsDir setting (string)
 
1488
    """
 
1489
    if prefClass.qtPrefs["Qt4TranslationsDir"].isEmpty():
 
1490
        return os.getenv("QT4TRANSLATIONSDIR", "")
 
1491
    else:
 
1492
        return unicode(prefClass.qtPrefs["Qt4TranslationsDir"])
 
1493
    
1440
1494
def getQt(key, prefClass = Prefs):
1441
1495
    """
1442
1496
    Module function to retrieve the various Qt settings.
1447
1501
    """
1448
1502
    if key == "QtDir":
1449
1503
        return getQtDir(prefClass)
 
1504
    elif key == "Qt4Dir":
 
1505
        return getQt4Dir(prefClass)
1450
1506
    else:
1451
1507
        return prefClass.qtPrefs[key]
1452
1508
    
1580
1636
    """
1581
1637
    prefClass.templatesPrefs[key] = value
1582
1638
    
 
1639
def getGraphics(key, prefClass = Prefs):
 
1640
    """
 
1641
    Module function to retrieve the Graphics related settings.
 
1642
    
 
1643
    @param key the key of the value to get
 
1644
    @param prefClass preferences class used as the storage area
 
1645
    @return the requested user setting
 
1646
    """
 
1647
    if key in ["Font"]:
 
1648
        f = QtGui.QFont()
 
1649
        f.fromString(prefClass.graphicsPrefs[key])
 
1650
        return f
 
1651
    else:
 
1652
        return prefClass.graphicsPrefs[key]
 
1653
    
 
1654
def setGraphics(key, value, prefClass = Prefs):
 
1655
    """
 
1656
    Module function to store the Graphics related settings.
 
1657
    
 
1658
    @param key the key of the setting to be set
 
1659
    @param value the value to be set
 
1660
    @param prefClass preferences class used as the storage area
 
1661
    """
 
1662
    prefClass.graphicsPrefs[key] = value
 
1663
    
1583
1664
def getGeometry(key, prefClass = Prefs):
1584
1665
    """
1585
1666
    Module function to retrieve the display geometry.
1603
1684
    else:
1604
1685
        prefClass.geometryPrefs[key] = value
1605
1686
 
1606
 
def getMainDockLayout(mw, which, prefClass = Prefs):
1607
 
    """
1608
 
    Module function to retrieve the layout of the dock windows.
1609
 
    
1610
 
    @param mw reference to the main window (QMainWindow)
1611
 
    @param which basic type of the dock layout (0 to 3)
1612
 
    @param prefClass preferences class used as the storage area
1613
 
    @return flag indicating success
1614
 
    """
1615
 
    s = QString(prefClass.dockPrefs["MainDockLayout%d" % which])
1616
 
    if s.isEmpty():
1617
 
        return 0
1618
 
    ts = QTextStream(s, IO_ReadOnly)
1619
 
    ts >> mw
1620
 
    return 1
1621
 
 
1622
 
def setMainDockLayout(mw, which, prefClass = Prefs):
1623
 
    """
1624
 
    Module function to store the layout of the dock windows.
1625
 
    
1626
 
    @param mw reference to the main window (QMainWindow)
1627
 
    @param which basic type of the dock layout (0 or 1)
1628
 
    @param prefClass preferences class used as the storage area
1629
 
    """
1630
 
    key = "MainDockLayout%d" % which
1631
 
    if prefClass.resetLayout:
1632
 
        s = QString(prefClass.dockDefaults[key])
1633
 
    else:
1634
 
        s = QString()
1635
 
        ts = QTextStream(s, IO_WriteOnly)
1636
 
        ts << mw
1637
 
    prefClass.dockPrefs[key] = unicode(s)
1638
 
 
1639
 
def resetLayout(which, prefClass = Prefs):
 
1687
def resetLayout(prefClass = Prefs):
1640
1688
    """
1641
1689
    Module function to set a flag not storing the current layout.
1642
1690
    
1643
 
    @param which flag indicating a reset of the layout. (ignored)
1644
1691
    @param prefClass preferences class used as the storage area
1645
1692
    """
1646
 
    prefClass.resetLayout = 1
 
1693
    prefClass.resetLayout = True
1647
1694
 
 
1695
def shouldResetLayout(prefClass = Prefs):
 
1696
    """
 
1697
    Module function to indicate a reset of the layout.
 
1698
    
 
1699
    @param prefClass preferences class used as the storage area
 
1700
    @return flag indicating a reset of the layout (boolean)
 
1701
    """
 
1702
    return prefClass.resetLayout
 
1703
    
 
1704
def saveResetLayout(prefClass = Prefs):
 
1705
    """
 
1706
    Module function to save the reset layout.
 
1707
    """
 
1708
    if prefClass.resetLayout:
 
1709
        for key in prefClass.geometryDefaults.keys():
 
1710
            prefClass.geometryPrefs[key] = prefClass.geometryDefaults[key]
 
1711
    
1648
1712
from Shortcuts import readShortcuts, saveShortcuts, exportShortcuts, importShortcuts
1649
1713
 
1650
1714
initPreferences()
 
1715
initRecentSettings()