source: orange/Orange/OrangeCanvas/config.py @ 11168:66793f8e1739

Revision 11168:66793f8e1739, 3.2 KB checked in by Ales Erjavec <ales.erjavec@…>, 18 months ago (diff)

Fixed Qt's plugin search path on Windows.

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    .. note:: This should not be run before QApplication has been initialized.
21              Otherwise it can brake Qt's plugin search paths.
22
23    """
24    # Set application name, version and org. domain
25    QCoreApplication.setOrganizationDomain("biolab.si")
26    QCoreApplication.setApplicationName("Orange Canvas")
27    QCoreApplication.setApplicationVersion("2.6")
28    QSettings.setDefaultFormat(QSettings.IniFormat)
29
30    # Make it a null op.
31    global init
32    init = lambda: None
33
34rc = {}
35
36default_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}
55
56
57def data_dir():
58    """Return the application data directory.
59    """
60    init()
61    datadir = QDesktopServices.storageLocation(QDesktopServices.DataLocation)
62    datadir = unicode(datadir)
63    if not os.path.exists(datadir):
64        os.makedirs(datadir)
65    return datadir
66
67
68def cache_dir():
69    """Return the application cache directory.
70    """
71    init()
72    datadir = QDesktopServices.storageLocation(QDesktopServices.DataLocation)
73    datadir = unicode(datadir)
74    if not os.path.exists(datadir):
75        os.makedirs(datadir)
76    return datadir
77
78
79def open_config():
80    global rc
81    app_dir = data_dir()
82    filename = os.path.join(app_dir, "canvas-rc.pck")
83    if os.path.exists(filename):
84        with open(os.path.join(app_dir, "canvas-rc.pck"), "rb") as f:
85            rc.update(cPickle.load(f))
86
87
88def save_config():
89    app_dir = data_dir()
90    with open(os.path.join(app_dir, "canvas-rc.pck"), "wb") as f:
91        cPickle.dump(rc, f)
92
93
94def recent_schemes():
95    """Return a list of recently accessed schemes.
96    """
97    app_dir = data_dir()
98    recent_filename = os.path.join(app_dir, "recent.pck")
99    recent = []
100    if os.path.isdir(app_dir) and os.path.isfile(recent_filename):
101        with open(recent_filename, "rb") as f:
102            recent = cPickle.load(f)
103
104    # Filter out files not found on the file system
105    recent = [(title, path) for title, path in recent \
106              if os.path.exists(path)]
107    return recent
108
109
110def save_recent_scheme_list(scheme_list):
111    """Save the list of recently accessed schemes
112    """
113    app_dir = data_dir()
114    recent_filename = os.path.join(app_dir, "recent.pck")
115
116    if os.path.isdir(app_dir):
117        with open(recent_filename, "wb") as f:
118            cPickle.dump(scheme_list, f)
Note: See TracBrowser for help on using the repository browser.