source: orange/Orange/OrangeCanvas/config.py @ 11097:16be8cc3a7c4

Revision 11097:16be8cc3a7c4, 3.1 KB checked in by Ales Erjavec <ales.erjavec@…>, 19 months ago (diff)

Added a new config module for the Orange Canvas application.

Line 
1"""
2Orange Canvas Configuration
3
4"""
5
6import os
7import logging
8import cPickle
9
10log = logging.getLogger(__name__)
11
12from PyQt4.QtGui import QDesktopServices
13from PyQt4.QtCore import QCoreApplication, QSettings
14
15
16def init():
17    """Initialize the QCoreApplication.organizationDomain, applicationName,
18    applicationVersion and the default settings format. Will only run once.
19
20    """
21    # Set application name, version and org. domain
22    QCoreApplication.setOrganizationDomain("biolab.si")
23    QCoreApplication.setApplicationName("Orange Canvas")
24    QCoreApplication.setApplicationVersion("2.6")
25    QSettings.setDefaultFormat(QSettings.IniFormat)
26    # Make it a null op.
27    global init
28    init = lambda: None
29
30rc = {}
31
32default_config = \
33{
34    "startup.show-splash-screen": True,
35    "startup.show-welcome-dialog": True,
36    "startup.style": None,
37    "startup.stylesheet": "orange",
38    "mainwindow.shop-properties-on-new-scheme": True,
39    "mainwindow.use-native-theme": False,
40    "mainwindow.qt-style": "default",
41    "mainwindow.show-document-margins": False,
42    "mainwindow.document-margins": 20,
43    "mainwindow.document-shadow": True,
44    "mainwindow.toolbox-dock-type": "toolbox",
45    "mainwindow.toolbox-toolbar-position": "bottom",
46    "mainwindow.toolbox-dock-floatable": False,
47    "mainwindow.show-status-bar": False,
48    "mainwindow.single-document-mode": True,
49    "logging.level": "error",
50}
51
52
53def data_dir():
54    """Return the application data directory.
55    """
56    init()
57    datadir = QDesktopServices.storageLocation(QDesktopServices.DataLocation)
58    datadir = unicode(datadir)
59    if not os.path.exists(datadir):
60        os.makedirs(datadir)
61    return datadir
62
63
64def cache_dir():
65    """Return the application cache directory.
66    """
67    init()
68    datadir = QDesktopServices.storageLocation(QDesktopServices.DataLocation)
69    datadir = unicode(datadir)
70    if not os.path.exists(datadir):
71        os.makedirs(datadir)
72    return datadir
73
74
75def open_config():
76    global rc
77    app_dir = data_dir()
78    filename = os.path.join(app_dir, "canvas-rc.pck")
79    if os.path.exists(filename):
80        with open(os.path.join(app_dir, "canvas-rc.pck"), "rb") as f:
81            rc.update(cPickle.load(f))
82
83
84def save_config():
85    app_dir = data_dir()
86    with open(os.path.join(app_dir, "canvas-rc.pck"), "wb") as f:
87        cPickle.dump(rc, f)
88
89
90def recent_schemes():
91    """Return a list of recently accessed schemes.
92    """
93    app_dir = data_dir()
94    recent_filename = os.path.join(app_dir, "recent.pck")
95    recent = []
96    if os.path.isdir(app_dir) and os.path.isfile(recent_filename):
97        with open(recent_filename, "rb") as f:
98            recent = cPickle.load(f)
99
100    # Filter out files not found on the file system
101    recent = [(title, path) for title, path in recent \
102              if os.path.exists(path)]
103    return recent
104
105
106def save_recent_scheme_list(scheme_list):
107    """Save the list of recently accessed schemes
108    """
109    app_dir = data_dir()
110    recent_filename = os.path.join(app_dir, "recent.pck")
111
112    if os.path.isdir(app_dir):
113        with open(recent_filename, "wb") as f:
114            cPickle.dump(scheme_list, f)
Note: See TracBrowser for help on using the repository browser.