Ignore:
Timestamp:
11/05/12 13:48:23 (18 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Added user settings/preferences dialog.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/config.py

    r11168 r11250  
    66import os 
    77import logging 
    8 import cPickle 
     8import cPickle as pickle 
    99 
    1010log = logging.getLogger(__name__) 
     
    1212from PyQt4.QtGui import QDesktopServices 
    1313from PyQt4.QtCore import QCoreApplication, QSettings 
     14 
     15from .utils.settings import Settings, config_slot 
    1416 
    1517 
     
    3436rc = {} 
    3537 
    36 default_config = \ 
    37 { 
    38     "startup.show-splash-screen": True, 
    39     "startup.show-welcome-dialog": True, 
    40     "startup.style": None, 
    41     "startup.stylesheet": "orange", 
    42     "mainwindow.shop-properties-on-new-scheme": True, 
    43     "mainwindow.use-native-theme": False, 
    44     "mainwindow.qt-style": "default", 
    45     "mainwindow.show-document-margins": False, 
    46     "mainwindow.document-margins": 20, 
    47     "mainwindow.document-shadow": True, 
    48     "mainwindow.toolbox-dock-type": "toolbox", 
    49     "mainwindow.toolbox-toolbar-position": "bottom", 
    50     "mainwindow.toolbox-dock-floatable": False, 
    51     "mainwindow.show-status-bar": False, 
    52     "mainwindow.single-document-mode": True, 
    53     "logging.level": "error", 
    54 } 
     38 
     39spec = \ 
     40    [("startup/show-splash-screen", bool, True, 
     41      "Show splash screen at startup"), 
     42 
     43     ("startup/show-welcome-screen", bool, True, 
     44      "Show Welcome screen at startup"), 
     45 
     46     ("stylesheet", unicode, "orange", 
     47      "QSS stylesheet to use"), 
     48 
     49     ("schemeinfo/show-at-new-scheme", bool, True, 
     50      "Show Scheme Properties when creating a new Scheme"), 
     51 
     52     ("mainwindow/scheme-margins-enabled", bool, True, 
     53      "Show margins around the scheme view"), 
     54 
     55     ("mainwindow/show-scheme-shadow", bool, True, 
     56      "Show shadow around the scheme view"), 
     57 
     58     ("mainwindow/toolbox-dock-exclusive", bool, False, 
     59      "Should the toolbox show only one expanded category at the time"), 
     60 
     61     ("mainwindow/toolbox-dock-floatable", bool, False, 
     62      "Is the canvas toolbox floatable (detachable from the main window)"), 
     63 
     64     ("mainwindow/toolbox-dock-movable", bool, True, 
     65      "Is the canvas toolbox movable (between left and right edge)"), 
     66 
     67     ("mainwindow/number-of-recent-schemes", int, 7, 
     68      "Number of recent schemes to keep in history"), 
     69 
     70     ("schemeedit/show-channel-names", bool, True, 
     71      "Show channel names"), 
     72 
     73     ("schemeedit/show-link-state", bool, True, 
     74      "Show link state hints."), 
     75 
     76     ("schemeedit/freeze-on-load", bool, False, 
     77      "Freeze signal propagation when loading a scheme."), 
     78 
     79     ("quickmenu/trigger-on-double-click", bool, True, 
     80      "Show quick menu on double click."), 
     81 
     82     ("quickmenu/trigger-on-left-click", bool, False, 
     83      "Show quick menu on left click."), 
     84 
     85     ("quickmenu/trigger-on-space-key", bool, True, 
     86      "Show quick menu on space key press."), 
     87 
     88     ("quickmenu/trigger-on-any-key", bool, False, 
     89      "Show quick menu on double click."), 
     90 
     91     ("logging/level", int, 1, "Logging level"), 
     92 
     93     ("logging/show-on-error", bool, True, "Show log window on error"), 
     94 
     95     ("logging/dockable", bool, True, "Allow log window to be docked"), 
     96 
     97     ("output/redirect-stderr", bool, True, 
     98      "Redirect and display standard error output"), 
     99 
     100     ("output/redirect-stdout", bool, True, 
     101      "Redirect and display standard output"), 
     102 
     103     ("output/stay-on-top", bool, True, ""), 
     104 
     105     ("output/show-on-error", bool, True, "Show output window on error"), 
     106 
     107     ("output/dockable", bool, True, "Allow output window to be docked"), 
     108 
     109     ("help/stay-on-top", bool, True, ""), 
     110 
     111     ("help/dockable", bool, True, "Allow help window to be docked"), 
     112 
     113     ("help/open-in-external-browser", bool, False, 
     114      "Open help in an external browser") 
     115     ] 
     116 
     117spec = [config_slot(*t) for t in spec] 
     118 
     119 
     120def settings(): 
     121    init() 
     122    store = QSettings() 
     123    settings = Settings(defaults=spec, store=store) 
     124    return settings 
    55125 
    56126 
    57127def data_dir(): 
    58     """Return the application data directory. 
     128    """Return the application data directory. If the directory path 
     129    does not yet exists then create it. 
     130 
    59131    """ 
    60132    init() 
     
    67139 
    68140def cache_dir(): 
    69     """Return the application cache directory. 
     141    """Return the application cache directory. If the directory path 
     142    does not yet exists then create it. 
     143 
    70144    """ 
    71145    init() 
     
    83157    if os.path.exists(filename): 
    84158        with open(os.path.join(app_dir, "canvas-rc.pck"), "rb") as f: 
    85             rc.update(cPickle.load(f)) 
     159            rc.update(pickle.load(f)) 
    86160 
    87161 
     
    89163    app_dir = data_dir() 
    90164    with open(os.path.join(app_dir, "canvas-rc.pck"), "wb") as f: 
    91         cPickle.dump(rc, f) 
     165        pickle.dump(rc, f) 
    92166 
    93167 
     
    100174    if os.path.isdir(app_dir) and os.path.isfile(recent_filename): 
    101175        with open(recent_filename, "rb") as f: 
    102             recent = cPickle.load(f) 
     176            recent = pickle.load(f) 
    103177 
    104178    # Filter out files not found on the file system 
     
    116190    if os.path.isdir(app_dir): 
    117191        with open(recent_filename, "wb") as f: 
    118             cPickle.dump(scheme_list, f) 
     192            pickle.dump(scheme_list, f) 
Note: See TracChangeset for help on using the changeset viewer.