root/branches/mbutscher/work/lib/pwiki/Configuration.py @ 288

Revision 288, 41.8 kB (checked in by mbutscher, 3 years ago)

branches/mbutscher/work:
* Option to open link in new window (Ross' rep.:

517346f7e238022217c982b5c71ed92880e40249 and
7698dcedf92b4a7fedfe16cc5138c2b5ab99f437)

Line 
1import ConfigParser
2import traceback
3import cStringIO as StringIO
4
5# from os.path import *
6
7import codecs
8import wx
9
10from MiscEvent import MiscEventSourceMixin
11from WikiExceptions import *
12
13from .SystemInfo import isUnicode
14
15# For compatibility TODO: remove in 2.2
16from .SystemInfo import isOSX, isLinux, isWin9x, isWinNT, isWindows
17
18# from WikiExceptions import *
19
20from StringOps import utf8Enc, utf8Dec, mbcsDec, strToBool
21
22Error = ConfigParser.Error
23
24
25class UnknownOptionException(Exception): pass
26
27
28
29def _setValue(section, option, value, config):
30    """
31    if value is of type str, it is assumed to be mbcs-coded
32    if section or option are of type str, they are assumed to be utf8 coded
33        (it is recommended to use only ascii characters for section/option
34        names)
35    """
36    if type(section) is unicode:
37        section = utf8Enc(section)[0]
38
39    if type(option) is unicode:
40        option = utf8Enc(option)[0]
41       
42    if type(value) is str:
43        value = utf8Enc(mbcsDec(value)[0])[0]
44    elif type(value) is unicode:
45        value = utf8Enc(value)[0]
46    else:
47        value = utf8Enc(unicode(value))[0]
48       
49    if not config.has_section(section):
50        config.add_section(section)
51       
52    config.set(section, option, value)
53
54
55def _fillWithDefaults(config, defaults):
56    for s, o in defaults.keys():
57        if not config.has_option(s, o) and defaults[(s, o)] is not None:
58            _setValue(s, o, defaults[(s, o)], config)
59
60
61
62class _AbstractConfiguration:
63    def get(self, section, option, default=None):
64        raise NotImplementedError   # abstract
65
66    def getint(self, section, option, default=None):
67        result = self.get(section, option)
68        if result is None:
69            return default
70
71        try:
72            return int(result)
73        except ValueError:
74            # Can't convert result string to integer
75            return default
76
77
78    def getfloat(self, section, option, default=None):
79        result = self.get(section, option)
80        if result is None:
81            return default
82       
83        try:
84            return float(result)
85        except ValueError:
86            # Can't convert result string to float
87            return default
88
89
90    def getboolean(self, section, option, default=None):
91        result = self.get(section, option)
92        if result is None:
93            return default
94       
95        return strToBool(result, False)
96
97    def isUnicode(unself):
98        """
99        Return if GUI is in unicode mode
100        """
101        return isUnicode()
102
103
104
105class SingleConfiguration(_AbstractConfiguration, MiscEventSourceMixin):
106    """
107    Wraps a single ConfigParser object
108    """
109
110    def __init__(self, configdef, fallthroughDict=None):
111        """
112        configdef -- Dictionary with defaults for configuration file
113        fallthroughDict -- Dictionary with settings for fallthrough mode
114                (only stored here, but processed by CombinedConfiguration)
115        """
116        MiscEventSourceMixin.__init__(self)
117       
118        self.configParserObject = None
119        self.configPath = None
120       
121        self.configDefaults = configdef
122       
123        if fallthroughDict is None:
124            self.fallthroughDict = {}
125        else:
126            self.fallthroughDict = fallthroughDict
127        self.writeAccessDenied = False
128
129
130    def get(self, section, option, default=None):
131        """
132        Return a configuration value returned as string/unicode which
133        is entered in given section and has specified option key.
134        """
135        if type(section) is unicode:
136            section = utf8Enc(section)[0]
137
138        if type(option) is unicode:
139            option = utf8Enc(option)[0]
140           
141        result = None
142
143        if self.isOptionAllowed(section, option):
144            if self.configParserObject.has_option(section, option):
145                result = self.configParserObject.get(section, option)
146            else:
147                result = self.configDefaults[(section, option)]
148        else:
149            raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)
150
151        if result is None:
152            return default
153
154        try:
155            result = utf8Dec(result)[0]
156        except UnicodeError:
157            # Result is not Utf-8 -> try mbcs
158            try:
159                result = mbcsDec(result)[0]
160            except UnicodeError:
161                # Result can't be converted
162                result = default
163
164        return result
165       
166    def setWriteAccessDenied(self, flag):
167        self.writeAccessDenied = flag
168       
169    def getWriteAccessDenied(self):
170        return self.writeAccessDenied
171       
172    def isReadOnlyEffect(self):
173        return self.writeAccessDenied
174
175
176    def isOptionAllowed(self, section, option):
177        """
178        The function test if an option is valid.
179        Only options can be set/retrieved which have an entry in the
180        defaults and if the configParserObject is valid.
181        """
182        return self.configParserObject is not None and \
183                self.configDefaults.has_key((section, option))
184
185    # TODO Allow in read-only mode?
186    def set(self, section, option, value):
187        if type(section) is unicode:
188            section = utf8Enc(section)[0]
189
190        if type(option) is unicode:
191            option = utf8Enc(option)[0]
192           
193        if self.isOptionAllowed(section, option):
194            _setValue(section, option, value, self.configParserObject)
195        else:
196            raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)
197
198
199    def fillWithDefaults(self):
200        _fillWithDefaults(self.configParserObject, self.configDefaults)
201
202
203    def setConfigParserObject(self, config, fn):
204        self.configParserObject = config
205        self.configPath = fn
206
207    def getConfigParserObject(self):
208        return self.configParserObject
209
210    def getConfigPath(self):
211        return self.configPath
212
213    def loadConfig(self, fn):
214        if fn is None:
215            self.setConfigParserObject(None, None)
216            return
217
218        config = ConfigParser.ConfigParser()
219        readFiles = config.read(fn)
220        if len(readFiles) > 0:
221            self.setConfigParserObject(config, fn)
222        else:
223            raise MissingConfigurationFileException(_(u"Config file not found"))
224
225
226    def createEmptyConfig(self, fn):
227        config = ConfigParser.ConfigParser()
228        self.setConfigParserObject(config, fn)
229       
230    def getFallthroughDict(self):
231        return self.fallthroughDict
232
233
234    def save(self):
235        """
236        Save all configurations
237        """
238        if self.isReadOnlyEffect():
239            return
240
241        if self.configParserObject:
242            sfile = StringIO.StringIO()
243            self.configParserObject.write(sfile)
244            configFile = open(self.configPath, 'w')
245            try:
246                self.configParserObject.write(configFile)
247            finally:
248                configFile.close()
249
250    def informChanged(self, oldSettings):
251        """
252        This should be called after configuration was changed to let
253        the object send out an event.
254        The set method does not send events automatically to prevent
255        the creation of many events (one per each set call) instead
256        of one at the end of changes
257        """
258        self.fireMiscEventProps({"changed configuration": True,
259                "old config settings": oldSettings})
260
261
262
263class CombinedConfiguration(_AbstractConfiguration):
264    """
265    Manages global and wiki specific configuration options.
266    Mainly wraps two SingleConfiguration instances
267    """
268   
269    def __init__(self, globalconfig, wikiconfig):
270        """
271        globalconfig -- SingleConfiguration object for global settings
272        wikiconfig -- Same for wiki settings
273        """
274        self.globalConfig = globalconfig
275        self.wikiConfig = wikiconfig
276
277    def get(self, section, option, default=None):
278        """
279        Return a configuration value returned as string/unicode which
280        is entered in given section and has specified option key.
281        """
282        if type(section) is unicode:
283            section = utf8Enc(section)[0]
284
285        if type(option) is unicode:
286            option = utf8Enc(option)[0]
287           
288        result = None
289       
290        checkWiki = True
291        checkGlobal = True
292       
293        if option.startswith("option/wiki/"):
294            option = option[12:]
295            checkGlobal = False
296        elif option.startswith("option/user/"):
297            option = option[12:]
298            checkWiki = False
299
300        if checkWiki:
301            if self.wikiConfig is not None and \
302                    self.wikiConfig.isOptionAllowed(section, option):
303                result = self.wikiConfig.get(section, option, default)
304                ftDict = self.wikiConfig.getFallthroughDict()
305                if not ftDict.has_key((section, option)) or \
306                        ftDict[(section, option)] != result:
307                    checkGlobal = False
308               
309            # TODO more elegantly
310            elif WIKIDEFAULTS.has_key((section, option)):
311                result = default
312                checkGlobal = False
313            elif not checkGlobal:
314                raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)
315
316        if checkGlobal:
317            if self.globalConfig is not None:
318                result = self.globalConfig.get(section, option, default)
319            else:
320                raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)
321
322
323#         if self.wikiConfig is not None and \
324#                 self.wikiConfig.isOptionAllowed(section, option):
325#             result = self.wikiConfig.get(section, option, default)
326#         # TODO more elegantly
327#         elif WIKIDEFAULTS.has_key((section, option)):
328#             result = default
329#         elif self.globalConfig is not None and \
330#                 self.globalConfig.isOptionAllowed(section, option):
331#             result = self.globalConfig.get(section, option, default)
332#         else:
333#             raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)
334
335        if result is None:
336            return default
337
338        return result
339       
340       
341
342    def set(self, section, option, value):
343        if type(section) is unicode:
344            section = utf8Enc(section)[0]
345
346        if type(option) is unicode:
347            option = utf8Enc(option)[0]
348           
349        if option.startswith("option/wiki/"):
350            option = option[12:]
351            self.wikiConfig.set(section, option, value)
352        elif option.startswith("option/user/"):
353            option = option[12:]
354            self.globalConfig.set(section, option, value)
355        elif self.wikiConfig is not None and \
356                self.wikiConfig.getFallthroughDict().has_key((section, option)):
357            raise UnknownOptionException, _(u"Ambiguos option set %s:%s") % (section, option)
358        else:
359            if self.wikiConfig is not None and \
360                    self.wikiConfig.isOptionAllowed(section, option):
361                self.wikiConfig.set(section, option, value)
362            elif self.globalConfig is not None:
363                self.globalConfig.set(section, option, value)
364            else:
365                raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)
366
367
368#         if self.wikiConfig is not None and \
369#                 self.wikiConfig.isOptionAllowed(section, option):
370#             self.wikiConfig.set(section, option, value)
371#         elif self.globalConfig is not None and \
372#                 self.globalConfig.isOptionAllowed(section, option):
373#             self.globalConfig.set(section, option, value)
374#         else:
375#             raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)
376
377
378    def fillGlobalWithDefaults(self):
379        self.globalConfig.fillWithDefaults()
380
381
382    def fillWikiWithDefaults(self):
383        self.wikiConfig.fillWithDefaults()
384
385    def loadWikiConfig(self, fn):
386        self.wikiConfig.loadConfig(fn)
387
388    def createEmptyWikiConfig(self, fn):
389        self.wikiConfig.createEmptyConfig(fn)
390
391    def getWikiConfig(self):
392        return self.wikiConfig
393
394    def setWikiConfig(self, config):
395        self.wikiConfig = config
396
397
398    def loadGlobalConfig(self, fn):
399        self.globalConfig.loadConfig(fn)
400
401    def createEmptyGlobalConfig(self, fn):
402        self.globalConfig.createEmptyConfig(fn)
403
404    def getGlobalConfig(self):
405        return self.globalConfig
406
407    def setGlobalConfig(self, config):
408        self.globalConfig = config
409
410    def saveGlobalConfig(self):
411        if self.globalConfig is not None:
412            self.globalConfig.save()
413
414
415    def save(self):
416        """
417        Save all configurations
418        """
419        self.saveGlobalConfig()
420
421        try:
422            if self.wikiConfig is not None:
423                self.wikiConfig.save()
424        except:
425            traceback.print_exc()
426
427
428    def informChanged(self, oldSettings):
429        """
430        This should be called after configuration was changed. It is called
431        for its SingleConfiguration objects in turn to let them send events
432        """
433        if self.globalConfig is not None:
434            self.globalConfig.informChanged(oldSettings)
435
436        if self.wikiConfig is not None:
437            self.wikiConfig.informChanged(oldSettings)
438
439
440
441GLOBALDEFAULTS = {
442    ("main", "wiki_history"): None,   # Should be overwritten with concrete value
443    ("main", "last_wiki"): "WikidPadHelp/WikidPadHelp.wiki",
444    ("main", "size_x"): "500",
445    ("main", "size_y"): "300",
446
447    ("main", "pos_x"): "10",
448    ("main", "pos_y"): "10",
449    ("main", "splitter_pos"): '170',
450    ("main", "log_window_autoshow"): "True", # Automatically show log window if messages added
451    ("main", "log_window_autohide"): "True", # Automatically hide log window if empty
452    ("main", "log_window_sashPos"): "1",  # Real splitter pos (obsolete, contained in windowLayout)
453    ("main", "log_window_effectiveSashPos"): "120",  # Splitter pos when calling showEffWindow (obsolete, contained in windowLayout)
454    ("main", "docStructure_position"): "0",  # Mode where to place the document structure window,
455            # 0: Hidden, 1:Left, 2:Right, 3:Above, 4:Below
456    ("main", "docStructure_depth"): "15",  # Maximum number of heading which is shown in document structure window
457            # (between 1 and 15)
458    ("main", "docStructure_autohide"): "False", # Automatically hide doc structure after something was activated in it.
459    ("main", "docStructure_autofollow"): "True", # Selection in document structure follows text cursor position
460
461    ("main", "toolbar_show"): "True",  # Show the toolbar?
462    ("main", "zoom"): '0',  # Zoom factor for editor
463    ("main", "preview_zoom"): '0',  # Zoom factor for preview
464    ("main", "last_active_dir"): None,   # Should be overwritten with concrete value
465    ## ("main", "font"): "Courier New",
466    ("main", "gui_language"): u"",   # Language (as locale code) to use in GUI. Empty string means system default language
467    ("main", "recentWikisList_length"): u"5",   # Length of recent wikis list
468    ("main", "font"): None,
469    ("main", "wrap_mode"): "True",
470    ("main", "indentation_guides"): "True",
471    ("main", "auto_bullets"): "True",  # Show bullet/number after newline if current line has bullet
472    ("main", "auto_indent"): "True",
473    ("main", "editor_tabsToSpaces"): "True",  # Write spaces when hitting TAB key
474    ("main", "show_lineNumbers"): "False",
475    ("main", "editor_useFolding"): u"False",
476    ("main", "editor_useImeWorkaround"): u"False",  # Special workaround by handling input by WikidPad instead of Scintilla.
477            # Seems to help against some problems with Vietnamese input programs
478#     ("main", "wikiWord_rename_wikiLinks"): u"0", # When renaming wiki word, should it try to rename links to the word, too?
479#             # 0:No, 1:Yes, 2:Ask for each renaming
480    ("main", "wikiWord_renameDefault_modifyWikiLinks"): u"False", # When renaming wiki word, should it try to rename links to the word, too?
481            # This is the default setting but can be modified for each rename operation.
482    ("main", "wikiWord_renameDefault_renameSubPages"): u"True", # When renaming wiki word, should sub pages also be renamed
483            # This is the default setting but can be modified for each rename operation
484    ("main", "mainTree_position"): u"0",  # Mode where to place the main tree,
485            # 0:Left, 1:Right, 2:Above, 3:Below
486    ("main", "viewsTree_position"): u"0",  # Mode how to show the "Views" tree relative to main tree,
487            # 0: Not at all, 1:Above, 2:Below, 3:Left, 4:Right
488    ("main", "windowLayout"): "name:main area panel;"\
489            "layout relation:left&layout relative to:main area panel&name:maintree&"\
490                "layout sash position:170&layout sash effective position:170;"\
491            "layout relation:below&layout relative to:main area panel&name:log&"\
492                "layout sash position:1&layout sash effective position:120",
493            # !!!
494#     ("main", "windowLayout"): "name:main area panel;"\
495#             "layout relation:left&layout relative to:main area panel&name:maintree&"\
496#                 "layout sash position:170&layout sash effective position:170;"\
497#             "layout relation:below&layout relative to:maintree&name:viewstree;"\
498#             "layout relation:below&layout relative to:main area panel&name:log&"\
499#                 "layout sash position:1&layout sash effective position:120",
500#             # !!!
501
502
503    ("main", "chooseWikiWordDialog_sortOrder"): u"None",  # How to sort wiki words shown as
504            # parents, children, ... in the ChooseWikiWordDialog? "None": No particular order
505            # "AlphaAsc": Alphabetically ascending
506
507    ("main", "hotKey_showHide_byApp"): "", # System-wide hotkey to show/hide program. It is described
508            # in the usual shortcut syntax e.g. "Ctrl-Alt-A".
509            # This key is bound to the application. A second key can be bound to a particular
510            # wiki
511    ("main", "hotKey_showHide_byApp_isActive"): u"True", # Separate switch to deactivate hotkey
512            # without deleting the hotkey setting itself
513           
514    ("main", "wikiOpenNew_defaultDir"): u"",   # Default directory to show when opening
515            # or creating a wiki. If entry is empty, a built-in default is used.
516
517    ("main", "wikiLockFile_ignore"): u"False",  # Ignore the lock file created by another instance
518            # when opening a wiki?
519    ("main", "wikiLockFile_create"): u"True",  # Create a lock file when opening a wiki?
520
521    ("main", "auto_save"): "True",  # Boolean field, if auto save should be active
522    ("main", "auto_save_delay_key_pressed"): "5",  # Seconds to wait after last key pressed and ...
523    ("main", "auto_save_delay_dirty"): "60",  # secs. to wait after page became dirty before auto save
524     
525    ("main", "hideundefined"): "False", # hide undefined wikiwords in tree
526    ("main", "tree_auto_follow"): "True", # The tree selection follows when opening a wiki word
527    ("main", "tree_update_after_save"): "True", # The tree is updated after a save
528    ("main", "tree_no_cycles"): "False", # Cycles in tree like NodeA -> NodeB -> NodeA are not shown
529    ("main", "tree_autohide"): "False", # Automatically hide tree(s) after something was selected in it.
530    ("main", "tree_bg_color"): "",  # Background color of the trees
531
532    ("main", "tree_font_nativeDesc"): u"",  # Data about tree font. If empty, default font is used
533
534    ("main", "tree_updateGenerator_minDelay"): u"0.1",  # Minimum delay (in secs) between calls to
535            # the update generator
536
537#     ("main", "tree_font_pointSize"): u"",  # Data about tree font. If pointSize is empty, default fonts is used
538#     ("main", "tree_font_family"): u"",  # Data about tree font.
539#     ("main", "tree_font_style"): u"",  # Data about tree font.
540#     ("main", "tree_font_weight"): u"",  # Data about tree font.
541#     ("main", "tree_font_underline"): u"",  # Data about tree font.
542#     ("main", "tree_font_faceName"): u"",  # Data about tree font.
543#     ("main", "tree_font_encoding"): u"",  # Data about tree font.
544
545
546    # Security options
547    ("main", "process_autogenerated_areas"): "False", # process auto-generated areas ?
548    ("main", "insertions_allow_eval"): "False",  # Evaluate :eval: and possible other script insertions?
549#     ("main", "tempFiles_inWikiDir"): "False",  # Store temp. files in wiki dir instead of normal temp dir.?
550    ("main", "script_security_level"): "0",  # Allow the use of scripts and
551            # import_scripts attribute? 0: No scripts at all; 1: No import_scripts;
552            # 2: allow local import_scripts; 3: allow also global.import_scripts
553    ("main", "script_search_reverse"): "False", # Normally when searching for a script first the local page
554            # is searched, then local import_scripts, then global.import_scripts. If this is set to
555            # True the search order is reversed
556
557
558    # HTML options
559    ("main", "new_window_on_follow_wiki_url"): u"1", # Open new window when following a "wiki:" URL 0:No, 1:Yes, new process
560    ("main", "start_browser_after_export"): u"True",
561    ("main", "facename_html_preview"): u"", # Facename(s) for the internal HTML preview
562    ("main", "html_preview_proppattern"): u"",  # RE pattern for attributes in HTML preview
563    ("main", "html_preview_proppattern_is_excluding"): u"False", # Should these pattern be excluded instead of included?
564    ("main", "html_export_proppattern"): u"",  # Same for HTML exporting
565    ("main", "html_export_proppattern_is_excluding"): u"False",  # Same for HTML exporting
566    ("main", "html_preview_pics_as_links"): u"False",  # Show only links to pictures in HTML preview
567    ("main", "html_export_pics_as_links"): u"False",  # Same for HTML exporting
568    ("main", "export_table_of_contents"): u"0",  # Show table of contents when exporting
569            # 0:None, 1:formatted as tree, 2:as list
570    ("main", "html_toc_title"): u"Table of Contents",  # title of table of contents
571    ("main", "html_export_singlePage_sepLineCount"): u"10",  # How many empty lines to separate
572            # two wiki pages in a single HTML page
573    ("main", "html_preview_renderer"): u"0",  # 0: Internal wxWidgets; 1: IE; 2: Mozilla; 3: Webkit
574    ("main", "html_preview_ieShowIframes"): u"False",  # Show iframes with external sources inside IE preview?
575    ("main", "html_preview_webkitViKeys"): u"False",  # Allow shortcut keys of vi editor to move around in Webkit preview
576
577    ("main", "html_body_link"): u"",  # for HTML preview/export, color for link or "" for default
578    ("main", "html_body_alink"): u"",  # for HTML preview/export, color for active link or "" for default
579    ("main", "html_body_vlink"): u"",  # for HTML preview/export, color for visited link or "" for default
580    ("main", "html_body_text"): u"",  # for HTML preview/export, color for text or "" for default
581    ("main", "html_body_bgcolor"): u"",  # for HTML preview/export, color for background or "" for default
582    ("main", "html_body_background"): u"",  # for HTML preview/export, URL for background image or "" for none
583    ("main", "html_header_doctype"): u'DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"',
584
585
586    # Editor options
587    ("main", "sync_highlight_byte_limit"): "400",  # Size limit when to start asyn. highlighting in editor
588    ("main", "async_highlight_delay"): "0.2",  # Delay after keypress before starting async. highlighting
589    ("main", "editor_shortHint_delay"): "500",  # Delay in milliseconds until the short hint defined for a wikiword is displayed
590            # 0 deactivates short hints
591    ("main", "editor_autoUnbullets"): "True",  # When pressing return on line with lonely bullet, remove bullet?
592    ("main", "editor_autoComplete_closingBracket"): "False",  # Append closing bracket to suggested wiki words
593            # for autocompletion ("[Two" -> "[Two words]" instead of -> "[Two words")
594    ("main", "editor_sync_byPreviewSelection"): "False", # If True, the selection in preview will be searched in editor
595            # for synchronization of both.
596    ("main", "editor_colorizeSearchFragments"): "False", # Search fragments (part after # in wiki link) are colored
597            # separately in syntax coloring (by default blue if present, black if not). May slow down highlighting.
598    ("main", "editor_tabWidth"): "4",  # How many spaces should a tab be wide?
599    ("main", "editor_onlineSpellChecker_active"): "False",  # Online-spellchecker (check as you type)?
600    ("main", "editor_imageTooltips_localUrls"): "True",  # Show image preview as tooltip for local image URL
601    ("main", "editor_imageTooltips_maxWidth"): "200",  # Maximum width for image tooltip
602    ("main", "editor_imageTooltips_maxHeight"): "200",  # Maximum height for image tooltip
603
604    ("main", "editor_imagePaste_filenamePrefix"): "",  # Prefix to put before the filename.
605    ("main", "editor_imagePaste_fileType"): "1",  # When pasting images into WikidPad, which file type
606            # should be used. 0: Deactivate image-paste; 1: PNG format; 2: JPEG
607    ("main", "editor_imagePaste_quality"): "75",  # Which quality should the (JPEG-)image have?
608            # 0 zero means very bad, 100 means very good
609    ("main", "editor_imagePaste_askOnEachPaste"): "True",  # When pasting image, ask each time for settings?
610    ("main", "editor_filePaste_prefix"): "",  # When dropping files into editor, how to prefix, join(middle) and suffix them?
611    ("main", "editor_filePaste_middle"): "\\x20",  # These three values are escaped with StringOps.escapeForIni to preserve spaces
612    ("main", "editor_filePaste_suffix"): "", 
613    ("main", "editor_filePaste_bracketedUrl"): "True", # Should the URL be inserted in brackets (and with
614            # spaces in it preserved unquoted)?
615
616    ("main", "editor_compatibility_ViKeys"): "False", # Use vi emulation keys in editor?
617
618
619    # Editor color options
620    ("main", "editor_plaintext_color"): "", # Color of plain text (and non-exist. wikiwords) in editor
621    ("main", "editor_link_color"): "", # Color of links (URL and wikiwords)
622    ("main", "editor_attribute_color"): "", # Color of attributes (=properties) and scripts
623    ("main", "editor_bg_color"): "",  # Background color of the editor
624    ("main", "editor_selection_fg_color"): "",  # Foreground color of the selection in the editor
625    ("main", "editor_selection_bg_color"): "",  # Background color of the selection in the editor
626    ("main", "editor_margin_bg_color"): "",  # Background color of margins in the editor except fold margin
627    ("main", "editor_caret_color"): "",  # Color of caret in the editor
628
629    # Clipboard catcher (Windows only)
630    ("main", "clipboardCatcher_prefix"): ur"",  # Prefix to prepend before each caught clipboard snippet
631    ("main", "clipboardCatcher_suffix"): ur"\n",  # Suffix to append after each caught clipboard snippet
632    ("main", "clipboardCatcher_filterDouble"): "True",  # If same text shall be inserted twice (or more often)
633            # do not react
634    ("main", "clipboardCatcher_userNotification"): "0",  # Type of notification when new clipboard snippet is caught, 0: None; 1: Sound
635    ("main", "clipboardCatcher_soundFile"): "",  # Filepath of sound to play if notification type is 1. Empty path plays bell
636
637
638    # File Launcher (for non-Windows OS)
639    ("main", "fileLauncher_path"): u"", # Path to an external program taking a path or URL to start appropriate application
640            # depending on file type. For Windows, the console command "start" does this.
641
642
643    # Mouse options
644    ("main", "mouse_middleButton_withoutCtrl"): "1", # If middle mouse button is pressed on a link in editor or preview, without
645            # Ctrl pressed, should it then open link in  0: a new tab in foreground, 1: new tab background, 2: same tab
646    ("main", "mouse_middleButton_withCtrl"): "0", # Same, but if Ctrl is pressed
647
648    ("main", "mouse_scrollUnderPointer"): "False", # Windows only, experimental, incomplete: Scroll window under pointer instead
649            # of focused window
650
651
652    ("main", "userEvent_mouse/leftdoubleclick/preview/body"): u"action/none", # How to react when user double-clicks somewhere into body of preview?
653            # "action/none": Do nothing; "action/presenter/this/subcontrol/textedit": Switch current subcontrol to textedit mode;
654            # "action/presenter/new/foreground/end/page/this/subcontrol/textedit": New tab with same wikiword in edit mode
655
656    ("main", "userEvent_mouse/middleclick/pagetab"): u"action/none",  # How to react on middle click on tab?
657            # "action/none": Do nothing; "action/presenter/this/close" close this tab
658
659    ("main", "userEvent_mouse/leftdrop/editor/files"): u"action/editor/this/paste/files/insert/url/absolute",  # How to react on dropping files to editor?
660            # "action/none": Do nothing; "action/editor/this/paste/files/insert/url/absolute" insert absolute urls,
661            # ".../relative": relative URLs, ".../tostorage": copy to files storage and create relative URL
662
663    ("main", "userEvent_mouse/leftdrop/editor/files/modkeys/shift"): u"action/editor/this/paste/files/insert/url/relative",
664            # How to react on dropping files to editor if shift key is pressed?
665
666    ("main", "userEvent_mouse/leftdrop/editor/files/modkeys/ctrl"): u"action/editor/this/paste/files/insert/url/tostorage",
667            # How to react on dropping files to editor if ctrl key is pressed?
668
669    # Time view/time line/calendar options
670    ("main", "timeView_position"): "0",  # Mode where to place the time view window,
671            # 0: Hidden, 1:Left, 2:Right, 3:Above, 4:Below
672    ("main", "timeView_dateFormat"): u"%Y %m %d",  # Time format to show and enter dates in the time view,
673            # especially in the timeline   
674    ("main", "timeView_autohide"): "False", # Automatically hide time view after something was selected in it.
675    ("main", "timeView_showWordListOnHovering"): u"True", # If True the wordlist of a date is shown when hovering
676            # over the entry
677    ("main", "timeView_showWordListOnSelect"): u"False", # If True the wordlist of a date is shown when
678            # entry is selected
679    ("main", "timeView_lastSelectedTab"): u"modified", # Which tab was selected last when closing WikidPad?
680            # "modified": Modified time, "version": Versioning tab
681
682    ("main", "timeline_showEmptyDays"): u"True", # Show days for which no wikiword is associated?
683    ("main", "timeline_sortDateAscending"): u"True", # If True the newer days are downward in the list, otherwise upward
684
685    ("main", "versioning_dateFormat"): u"%Y %m %d",  # Time format to show dates in the versioning view
686
687
688
689    # Search options
690    ("main", "search_wiki_searchType"): "0",  # Default search type for wiki-wide search
691            # 0: Regex; 1: "Anded" regex; 2: Text as is
692    ("main", "search_wiki_caseSensitive"): "False",  # Wiki-wide search case sensitive?
693    ("main", "search_wiki_wholeWord"): "False",  # Wiki-wide search for whole words only?
694    ("main", "search_wiki_context_before"): "20", # No. of context characters before
695    ("main", "search_wiki_context_after"): "30",  # and after a found pattern
696    ("main", "search_wiki_count_occurrences"): "True", # Show for each page the number of found matches
697    ("main", "search_wiki_max_count_occurrences"): "100", # Stop after how many occurrences on a page
698
699    ("main", "fastSearch_sizeX"): "200",  # Size of the fastsearch popup frame
700    ("main", "fastSearch_sizeY"): "400",
701    ("main", "incSearch_autoOffDelay"): "0", # Secs. of inactivity until stopping incremental
702            # search automatically, 0 means no auto. stop
703    ("main", "fastSearch_searchType"): "0",  # Default search type for fast search
704            # (little text field in toolbar). 0: Regex; 1: "Anded" regex; 2: Text as is
705    ("main", "fastSearch_caseSensitive"): "False",  # Fast search case sensitive?
706    ("main", "fastSearch_wholeWord"): "False",  # Fast search for whole words only
707
708    ("main", "search_dontAllowCancel"): "False", # Iff true a running search can't be canceled
709            # (advanced option to cure a problem on Mac OS)
710
711
712    # Miscellaneous
713    ("main", "print_margins"): "0,0,0,0", # Left, upper, right, lower page margins on printing
714    ("main", "print_plaintext_font"): "", # Font description for printing in plain text mode
715    ("main", "print_plaintext_wpseparator"): "\\n\\n\\n\\n", # How to separate wikiword pages (uses re escaping)
716
717    ("main", "windowmode"): "0",
718    ("main", "frame_stayOnTop"): "False",  # Should frame stay on top of all other windows?
719    ("main", "showontray"): "0",
720    ("main", "minimize_on_closeButton"): "False", # Minimize if the close button ("X") is pressed 
721    ("main", "mainTabs_switchMruOrder"): "True", # Switch between tabs in most-recently used order
722    ("main", "startup_splashScreen_show"): "True", # Show splash screen on startup
723    ("main", "strftime"): u"%x %I:%M %p",  # time format when inserting time in a page
724    ("main", "pagestatus_timeformat"): u"%x %I:%M %p",  # time format for the page status field in status bar
725    ("main", "recent_time_formats"): u"%x %I:%M %p;%m/%d/%y;%d.%m.%y;%d.%m.%Y;%a %Y-%m-%d",
726            # semicolon-separated list of recently used time formats
727    ("main", "single_process"): "True", # Ensure that only a single process runs per user
728    ("main", "menu_accels_kbdTranslate"): "False", # Translate menu accelerators to match keyboard layout
729            # this is only necessary for special layouts where ctrl-level uses fundamentally different layout
730            # than base and shift level
731    ("main", "zombieCheck"): "True", # Check for alread running processes? Only active if "single_process" is True
732
733    ("main", "tempHandling_preferMemory"): "False", # Prefer to store temporary data in memory where this is possible?
734    ("main", "tempHandling_tempMode"): u"system", # Mode for storing of temporary data.
735            # system: use system default temp dir; config: use config subdirectory; given: use directory given
736            # in option "sqlite_tempDir"; (( auto: use "config" if configuration directory is equal installation dir.,
737            # use "system" otherwise ))
738    ("main", "tempHandling_tempDir"): u"", # Path to directory for temporary files. Only valid if
739            # "tempHandling_tempMode" is set to "given".
740    ("main", "wikiPathes_relative"): "False", # If True, pathes to last recently used wikis
741            # are stored relative to application dir.
742    ("main", "openWikiWordDialog_sortOrder"): "0", # Sort order in "Open Wiki Word" dialog
743            # 0:Alphabetically; 1:By last visit, newest first; 2:By last visit, oldest first; 3:Alphabetically reverse
744   
745    ("main", "collation_order"): "Default", # Set collation order, Default: system default order, C: ASCII byte value
746    ("main", "collation_uppercaseFirst"): "False" # Sort uppercase first (ABCabc) or normal inorder (AaBbCc)
747
748    }
749
750
751
752WIKIDEFAULTS = {
753    ("wiki_db", "data_dir"): u"data",
754    ("main", "wiki_name"): None,
755    ("main", "wiki_wikiLanguage"): "wikidpad_default_2_0", # Internal name of wiki language of the wiki
756    ("main", "last_wiki_word"): None, # Show this wiki word as leftmost wiki word on startup if first_wiki_word is empty
757    ("main", "tree_last_root_wiki_word"): None, # Last root word of wiki tree
758    ("main", "tree_expandedNodes_rememberDuration"): u"2", # How long should open nodes in tree be remembered?
759            # 0: Not at all; 1: During session; 2: Between sessions in wiki config file
760    ("main", "indexSearch_enabled"): u"False", # should the index search be enabled?
761    ("main", "indexSearch_formatNo"): u"1", # internal: Number of format of search index (only valid if index enabled)
762            # if it doesn't match format number of this WikidPad version, index rebuild is needed
763    ("main", "tabs_maxCharacters"): u"0", # Maximum number of characters to show on a tab (0: inifinite)
764    ("main", "template_pageNamesRE"): u"^template/",  # Regular expression pattern for pages which should be seen as templates
765            # Especially they will be listed in text editor context menu on new pages
766
767    ("main", "trashcan_maxNoOfBags"): u"200",   # Maximum number of trashbags. If more are present
768            # oldest are removed
769    ("main", "trashcan_askOnDelete"): u"True",   # When deleting an element ask before it is
770            # put to trashbag
771    ("main", "trashcan_storageLocation"): "0",  # Where to store trashcan data? 0: Intern in database;
772            # 1: extern in files (not supported for Compact Sqlite DB)
773
774   
775    ("main", "tree_expandedNodes_descriptorPathes_main"): u"", # ";"-delimited sequence of node descriptor pathes of expanded nodes in tree.
776            # Descriptors of a path are delimited by ','. This config. entry applies to main tree
777    ("main", "tree_expandedNodes_descriptorPathes_views"): u"", # Same as above but applies to "Views" tree if present
778
779    ("main", "tree_force_scratchpad_visibility"): u"True",  # Always show scratchpad below wiki root even
780            # if it is not a child of it
781
782    ("main", "further_wiki_words"): u"", # Semicolon separated list of further wiki words to show in addit. tabs
783            # after last wiki word
784
785    ("main", "wiki_lastTabsSubCtrls"): u"", # Semicolon separated list of the subcontrols active in each presenter, normally "textedit" or "preview"
786    ("main", "wiki_lastActiveTabNo"): u"-1", # Number of the tab which was last active. Non-wikiwords are ignored
787            # for this index
788
789    ("main", "first_wiki_word"): "", # Start with a special wiki word (If empty, use last word)
790    ("main", "wiki_database_type"): u"",  # Type of database "original_gadfly" for WikidPad,
791                                         # "compact_sqlite" for WikidPadCompact
792                                         # or "original_sqlite"
793#     ("main", "footnotes_as_wikiwords"): "False",  # Interpret footnotes (e.g. [42]) as wiki words?
794    ("main", "db_pagefile_suffix"): ".wiki",  # Suffix of the page files for "Original ..."
795                                             # db types
796    ("main", "export_default_dir"): u"",  # Default directory for exports, u"" means fill in last active directory
797   
798    ("main", "wiki_readOnly"): "False",   # Should wiki be read only?
799
800    ("main", "log_window_autoshow"): "Gray", # Automatically show log window if messages added? "Gray" means to look at
801            # global configuration for same setting
802
803    ("main", "wikiPageFiles_asciiOnly"): "False", # Use only ASCII characters in filenames of wiki page files.
804    ("main", "wikiPageFiles_gracefulOutsideAddAndRemove"): "True",   # Handle missing wiki page files gracefully and try
805            # to find existing files even if they are not in database.
806
807    ("main", "headingsAsAliases_depth"): "0",  # Maximum heading depth for which aliases should be generated for
808            # each heading up to and including this depth.
809
810    ("main", "versioning_storageLocation"): "0",  # Where to store versioning data? 0: Intern in database;
811            # 1: extern in files (not supported for Compact Sqlite DB)
812
813    ("main", "versioning_completeSteps"): u"10",  # How many versions before next version is saved complete
814            # instead of reverse differential? 0: Always revdiff, 1: Always complete, 2: Every second v. is complete ...
815
816    # For file storage (esp. identity check)
817    ("main", "fileStorage_identity_modDateMustMatch"): "False",  # Modification date must match for file to be identical
818    ("main", "fileStorage_identity_filenameMustMatch"): "False",  # Filename must match for file
819    ("main", "fileStorage_identity_modDateIsEnough"): "False",
820            # Same modification date is enough to claim files identical (no content compare)
821
822    ("main", "wikiPageTitlePrefix"): "++",   # Prefix for main title of new pages
823    ("main", "wikiPageTitle_creationMode"): "1",   # How to create title from name of a new wiki word:
824            # 0: Use wiki word as title as it is ("NewWikiWord" -> "NewWikiWord")
825            # 1: Add spaces before uppercase letter ("NewWikiWord" -> "New Wiki Word")
826            # 2: No title at all
827    ("main", "wikiPageTitle_fromLinkTitle"): "False",   # If clicking on a title link, e.g. [wiki word|interesting title]
828            # of a non-existing page use that title as title of the page.
829
830    ("main", "wiki_icon"): "",   # Name of the wiki icon. Empty if default icon should be used
831
832    ("main", "hotKey_showHide_byWiki"): ""   # System-wide hotkey to show/hide program. It is described
833            # in the usual shortcut syntax e.g. "Ctrl-Alt-A".
834            # This key is bound to the wiki. Another key above can be bound to the whole app
835    }
836
837
838
839# If the fallthrough value is set in the wiki-bound config. then
840# the global config. value is used instead
841WIKIFALLTHROUGH ={
842    ("main", "log_window_autoshow"): "Gray"
843
844    }
845
846
847
848# Maps configuration setting "mouse_middleButton_withoutCtrl" number to a
849# tabMode number for WikiTxtCtrl._activateLink or WikiHtmlView._activateLink
850MIDDLE_MOUSE_CONFIG_TO_TABMODE = {
851                                    0: 2, # New tab in background
852                                    1: 3, # New tab in foreground
853                                    2: 0, # Same Tab
854                                    3: 6, # New Window
855                                 }
856
857
858
859# def createCombinedConfiguration():
860#     return CombinedConfiguration(createGlobalConfiguration(),
861#             createWikiConfiguration())
862#             
863#
864# def createWikiConfiguration():
865#     return SingleConfiguration(WIKIDEFAULTS)
866#
867#
868# def createGlobalConfiguration():
869#     return SingleConfiguration(GLOBALDEFAULTS)
870
871
Note: See TracBrowser for help on using the browser.