source: orange/Orange/OrangeCanvas/config.py @ 11476:08516677bd02

Revision 11476:08516677bd02, 6.4 KB checked in by markotoplak, 12 months ago (diff)

The toolbox shows only one expanded category at the time by default.

Line 
1"""
2Orange Canvas Configuration
3
4"""
5
6import os
7import logging
8import cPickle as pickle
9import itertools
10
11import pkg_resources
12
13from PyQt4.QtGui import QDesktopServices
14from PyQt4.QtCore import QCoreApplication
15
16from .utils.settings import Settings, config_slot
17
18# Import QSettings from qtcompat module (compatibility with PyQt < 4.8.3
19from .utils.qtcompat import QSettings
20
21log = logging.getLogger(__name__)
22
23
24def init():
25    """Initialize the QCoreApplication.organizationDomain, applicationName,
26    applicationVersion and the default settings format. Will only run once.
27
28    .. note:: This should not be run before QApplication has been initialized.
29              Otherwise it can break Qt's plugin search paths.
30
31    """
32    # Set application name, version and org. domain
33    QCoreApplication.setOrganizationDomain("biolab.si")
34    QCoreApplication.setApplicationName("Orange Canvas")
35    QCoreApplication.setApplicationVersion("2.6")
36    QSettings.setDefaultFormat(QSettings.IniFormat)
37
38    # Make it a null op.
39    global init
40    init = lambda: None
41
42rc = {}
43
44
45spec = \
46    [("startup/show-splash-screen", bool, True,
47      "Show splash screen at startup"),
48
49     ("startup/show-welcome-screen", bool, True,
50      "Show Welcome screen at startup"),
51
52     ("stylesheet", unicode, "orange",
53      "QSS stylesheet to use"),
54
55     ("schemeinfo/show-at-new-scheme", bool, True,
56      "Show Scheme Properties when creating a new Scheme"),
57
58     ("mainwindow/scheme-margins-enabled", bool, True,
59      "Show margins around the scheme view"),
60
61     ("mainwindow/show-scheme-shadow", bool, True,
62      "Show shadow around the scheme view"),
63
64     ("mainwindow/toolbox-dock-exclusive", bool, True,
65      "Should the toolbox show only one expanded category at the time"),
66
67     ("mainwindow/toolbox-dock-floatable", bool, False,
68      "Is the canvas toolbox floatable (detachable from the main window)"),
69
70     ("mainwindow/toolbox-dock-movable", bool, True,
71      "Is the canvas toolbox movable (between left and right edge)"),
72
73     ("mainwindow/number-of-recent-schemes", int, 7,
74      "Number of recent schemes to keep in history"),
75
76     ("schemeedit/show-channel-names", bool, True,
77      "Show channel names"),
78
79     ("schemeedit/show-link-state", bool, True,
80      "Show link state hints."),
81
82     ("schemeedit/enable-node-animations", bool, True,
83      "Enable node animations."),
84
85     ("schemeedit/freeze-on-load", bool, False,
86      "Freeze signal propagation when loading a scheme."),
87
88     ("quickmenu/trigger-on-double-click", bool, True,
89      "Show quick menu on double click."),
90
91     ("quickmenu/trigger-on-left-click", bool, False,
92      "Show quick menu on left click."),
93
94     ("quickmenu/trigger-on-space-key", bool, True,
95      "Show quick menu on space key press."),
96
97     ("quickmenu/trigger-on-any-key", bool, False,
98      "Show quick menu on double click."),
99
100     ("logging/level", int, 1, "Logging level"),
101
102     ("logging/show-on-error", bool, True, "Show log window on error"),
103
104     ("logging/dockable", bool, True, "Allow log window to be docked"),
105
106     ("output/redirect-stderr", bool, True,
107      "Redirect and display standard error output"),
108
109     ("output/redirect-stdout", bool, True,
110      "Redirect and display standard output"),
111
112     ("output/stay-on-top", bool, True, ""),
113
114     ("output/show-on-error", bool, True, "Show output window on error"),
115
116     ("output/dockable", bool, True, "Allow output window to be docked"),
117
118     ("help/stay-on-top", bool, True, ""),
119
120     ("help/dockable", bool, True, "Allow help window to be docked"),
121
122     ("help/open-in-external-browser", bool, False,
123      "Open help in an external browser")
124     ]
125
126spec = [config_slot(*t) for t in spec]
127
128
129def settings():
130    init()
131    store = QSettings()
132    settings = Settings(defaults=spec, store=store)
133    return settings
134
135
136def data_dir():
137    """Return the application data directory. If the directory path
138    does not yet exists then create it.
139
140    """
141    init()
142    datadir = QDesktopServices.storageLocation(QDesktopServices.DataLocation)
143    datadir = unicode(datadir)
144    if not os.path.exists(datadir):
145        os.makedirs(datadir)
146    return datadir
147
148
149def cache_dir():
150    """Return the application cache directory. If the directory path
151    does not yet exists then create it.
152
153    """
154    init()
155    cachedir = QDesktopServices.storageLocation(QDesktopServices.CacheLocation)
156    cachedir = unicode(cachedir)
157    if not os.path.exists(cachedir):
158        os.makedirs(cachedir)
159    return cachedir
160
161
162def open_config():
163    global rc
164    app_dir = data_dir()
165    filename = os.path.join(app_dir, "canvas-rc.pck")
166    if os.path.exists(filename):
167        with open(os.path.join(app_dir, "canvas-rc.pck"), "rb") as f:
168            rc.update(pickle.load(f))
169
170
171def save_config():
172    app_dir = data_dir()
173    with open(os.path.join(app_dir, "canvas-rc.pck"), "wb") as f:
174        pickle.dump(rc, f)
175
176
177def recent_schemes():
178    """Return a list of recently accessed schemes.
179    """
180    app_dir = data_dir()
181    recent_filename = os.path.join(app_dir, "recent.pck")
182    recent = []
183    if os.path.isdir(app_dir) and os.path.isfile(recent_filename):
184        with open(recent_filename, "rb") as f:
185            recent = pickle.load(f)
186
187    # Filter out files not found on the file system
188    recent = [(title, path) for title, path in recent \
189              if os.path.exists(path)]
190    return recent
191
192
193def save_recent_scheme_list(scheme_list):
194    """Save the list of recently accessed schemes
195    """
196    app_dir = data_dir()
197    recent_filename = os.path.join(app_dir, "recent.pck")
198
199    if os.path.isdir(app_dir):
200        with open(recent_filename, "wb") as f:
201            pickle.dump(scheme_list, f)
202
203
204WIDGETS_ENTRY = "orange.widgets"
205
206
207# This could also be achieved by declaring the entry point in
208# Orange's setup.py, but that would not guaranty this entry point
209# is the first in a list.
210
211def default_entry_point():
212    """
213    Return a default orange.widgets entry point for loading
214    default Orange Widgets.
215
216    """
217    dist = pkg_resources.get_distribution("Orange")
218    ep = pkg_resources.EntryPoint("Orange Widgets", "Orange.OrangeWidgets",
219                                  dist=dist)
220    return ep
221
222
223def widgets_entry_points():
224    """
225    Return an `EntryPoint` iterator for all 'orange.widget' entry
226    points plus the default Orange Widgets.
227
228    """
229    ep_iter = pkg_resources.iter_entry_points(WIDGETS_ENTRY)
230    chain = [[default_entry_point()],
231             ep_iter
232             ]
233    return itertools.chain(*chain)
Note: See TracBrowser for help on using the repository browser.