Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > c567edd4605b914c84d9dab4c41a8a5b > files > 692

python-enthought-apptools-3.3.0-2mdv2010.0.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Preferences &mdash; AppTools v3.3.0 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.3.0',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="AppTools v3.3.0 documentation" href="../index.html" />
    <link rel="next" title="Preferences in Envisage" href="PreferencesInEnvisage.html" />
    <link rel="prev" title="Default User Manager Data API" href="../permissions/DefaultUserManagerDataAPI.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="PreferencesInEnvisage.html" title="Preferences in Envisage"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="../permissions/DefaultUserManagerDataAPI.html" title="Default User Manager Data API"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">AppTools v3.3.0 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="preferences">
<h1>Preferences<a class="headerlink" href="#preferences" title="Permalink to this headline">¶</a></h1>
<p>The preferences package provides a simple API for managing application
preferences. The classes in the package are implemented using a layered
approach where the lowest layer provides access to the raw preferences
mechanism and each layer on top providing more convenient ways to get and set
preference values.</p>
</div>
<div class="section" id="the-basic-preferences-mechanism">
<h1>The Basic Preferences Mechanism<a class="headerlink" href="#the-basic-preferences-mechanism" title="Permalink to this headline">¶</a></h1>
<p>Lets start by taking a look at the lowest layer which consists of the
<a class="reference external" href="../../enthought/preferences/i_preferences.py">IPreferences</a> interface and its default implementation in the <a class="reference external" href="../../enthought/preferences/preferences.py">Preferences</a>
class. This layer implements the basic preferences system which is a
hierarchical arrangement of preferences &#8216;nodes&#8217; (where each node is simply an
object that implements the <a class="reference external" href="../../enthought/preferences/i_preferences.py">IPreferences</a> interface). Nodes in the hierarchy can
contain preference settings and/or child nodes. This layer also provides a
default way to read and write preferences from the filesystem using the
excellent <a class="reference external" href="http://www.voidspace.org.uk/python/configobj.html">ConfigObj</a> package.</p>
<p>This all sounds a bit complicated but, believe me, it isn&#8217;t! To prove it
(hopefully) lets look at an example. Say I have the following preferences in
a file &#8216;example.ini&#8217;:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">acme</span><span class="o">.</span><span class="n">ui</span><span class="p">]</span>
<span class="n">bgcolor</span> <span class="o">=</span> <span class="n">blue</span>
<span class="n">width</span> <span class="o">=</span> <span class="mf">50</span>
<span class="n">ratio</span> <span class="o">=</span> <span class="mf">1.0</span>
<span class="n">visible</span> <span class="o">=</span> <span class="bp">True</span>

<span class="p">[</span><span class="n">acme</span><span class="o">.</span><span class="n">ui</span><span class="o">.</span><span class="n">splash_screen</span><span class="p">]</span>
<span class="n">image</span> <span class="o">=</span> <span class="n">splash</span>
<span class="n">fgcolor</span> <span class="o">=</span> <span class="n">red</span>
</pre></div>
</div>
<p>I can create a preferences hierarchy from this file by:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">enthought.preferences.api</span> <span class="kn">import</span> <span class="n">Preferences</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span> <span class="o">=</span> <span class="n">Preferences</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="s">&#39;example.ini&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">dump</span><span class="p">()</span>

<span class="go"> Node() {}</span>
<span class="go">    Node(acme) {}</span>
<span class="go">      Node(ui) {&#39;bgcolor&#39;: &#39;blue&#39;, &#39;ratio&#39;: &#39;1.0&#39;, &#39;width&#39;: &#39;50&#39;, &#39;visible&#39;: &#39;True&#39;}</span>
<span class="go">        Node(splash_screen) {&#39;image&#39;: &#39;splash&#39;, &#39;fgcolor&#39;: &#39;red&#39;}</span>
</pre></div>
</div>
<p>The &#8216;dump&#8217; method (useful for debugging etc) simply &#8216;pretty prints&#8217; a
preferences hierarchy. The dictionary next to each node contains the node&#8217;s
actual preferences. In this case, the root node (the node with no name) is the
preferences object that we created. This node now has one child node &#8216;acme&#8217;,
which contains no preferences. The &#8216;acme&#8217; node has one child, &#8216;ui&#8217;, which
contains some preferences (e.g. &#8216;bgcolor&#8217;) and also a child node
&#8216;splash_screen&#8217; which also contains preferences (e.g. &#8216;image&#8217;).</p>
<p>To look up a preference we use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.bgcolor&#39;</span><span class="p">)</span>
<span class="go">&#39;blue&#39;</span>
</pre></div>
</div>
<p>If no such preferences exists then, by default, None is returned:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.bogus&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="bp">None</span>
<span class="go">True</span>
</pre></div>
</div>
<p>You can also specify an explicit default value:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.bogus&#39;</span><span class="p">,</span> <span class="s">&#39;fred&#39;</span><span class="p">)</span>
<span class="go">&#39;fred&#39;</span>
</pre></div>
</div>
<p>To set a preference we use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s">&#39;acme.ui.bgcolor&#39;</span><span class="p">,</span> <span class="s">&#39;red&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.bgcolor&#39;</span><span class="p">)</span>
<span class="go">&#39;red&#39;</span>
</pre></div>
</div>
<p>And to make sure the preferences are saved back to disk:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
</pre></div>
</div>
<p>To add a new preference value we simply set it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s">&#39;acme.ui.fgcolor&#39;</span><span class="p">,</span> <span class="s">&#39;black&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.fgcolor&#39;</span><span class="p">)</span>
<span class="go">&#39;black&#39;</span>
</pre></div>
</div>
<p>Any missing nodes in a call to &#8216;set&#8217; are created automatically, hence:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s">&#39;acme.ui.button.fgcolor&#39;</span><span class="p">,</span> <span class="s">&#39;white&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.button.fgcolor&#39;</span><span class="p">)</span>
<span class="go">&#39;white&#39;</span>
</pre></div>
</div>
<p>Preferences can also be &#8216;inherited&#8217;. e.g. Notice that the &#8216;splash_screen&#8217;
node does not contain a &#8216;bgcolor&#8217; preference, and hence:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.splash_screen.bgcolor&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="bp">None</span>
<span class="go">True</span>
</pre></div>
</div>
<p>But if we allow the &#8216;inheritance&#8217; of preference values then:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.splash_screen.bgcolor&#39;</span><span class="p">,</span> <span class="n">inherit</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="go">&#39;red&#39;</span>
</pre></div>
</div>
<p>By using &#8216;inheritance&#8217; here the preferences system will try the following
preferences:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="s">&#39;acme.ui.splash_screen.bgcolor&#39;</span>
<span class="s">&#39;acme.ui.bgcolor&#39;</span>
<span class="s">&#39;acme.bgcolor&#39;</span>
<span class="s">&#39;bgcolor&#39;</span>
</pre></div>
</div>
<div class="section" id="strings-glorious-strings">
<h2>Strings, Glorious Strings<a class="headerlink" href="#strings-glorious-strings" title="Permalink to this headline">¶</a></h2>
<p>At this point it is worth mentioning that preferences are <em>always</em> stored and
returned as strings. This is because of the limitations of the traditional
&#8216;.ini&#8217; file format i.e. they don&#8217;t contain any type information! Now before you
start panicking, this doesn&#8217;t mean that all of your preferences have to be
strings! Currently the preferences system allows, strings(!), booleans, ints,
longs, floats and complex numbers. When you store a non-string value it gets
converted to a string for you, but you <em>always</em> get a string back:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.width&#39;</span><span class="p">)</span>
<span class="go">&#39;50&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s">&#39;acme.ui.width&#39;</span><span class="p">,</span> <span class="mf">100</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.width&#39;</span><span class="p">)</span>
<span class="go">&#39;100&#39;</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.visible&#39;</span><span class="p">)</span>
<span class="go">&#39;True&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s">&#39;acme.ui.visible&#39;</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.visible&#39;</span><span class="p">)</span>
<span class="go">&#39;False&#39;</span>
</pre></div>
</div>
<p>This is obviously not terribly convenient, and so the following section
discusses how we associate type information with our preferences to make
getting and setting them more natural.</p>
</div>
</div>
<div class="section" id="preferences-and-types">
<h1>Preferences and Types<a class="headerlink" href="#preferences-and-types" title="Permalink to this headline">¶</a></h1>
<p>As mentioned previously, we would like to be able to get and set non-string
preferences in a more convenient way. This is where the <a class="reference external" href="../../enthought/preferences/preferences_helper.py">PreferencesHelper</a>
class comes in.</p>
<p>Let&#8217;s take another look at &#8216;example.ini&#8217;:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">acme</span><span class="o">.</span><span class="n">ui</span><span class="p">]</span>
<span class="n">bgcolor</span> <span class="o">=</span> <span class="n">blue</span>
<span class="n">width</span> <span class="o">=</span> <span class="mf">50</span>
<span class="n">ratio</span> <span class="o">=</span> <span class="mf">1.0</span>
<span class="n">visible</span> <span class="o">=</span> <span class="bp">True</span>

<span class="p">[</span><span class="n">acme</span><span class="o">.</span><span class="n">ui</span><span class="o">.</span><span class="n">splash_screen</span><span class="p">]</span>
<span class="n">image</span> <span class="o">=</span> <span class="n">splash</span>
<span class="n">fgcolor</span> <span class="o">=</span> <span class="n">red</span>
</pre></div>
</div>
<p>Say, I am interested in the preferences in the &#8216;acme.ui&#8217; section. I can use a
preferences helper as follows:</p>
<div class="highlight-python"><pre>from enthought.preferences.api import PreferencesHelper

class SplashScreenPreferences(PreferencesHelper):
    """ A preferences helper for the splash screen. """

    PREFERENCES_PATH = 'acme.ui'

    bgcolor = Str
    width   = Int
    ratio   = Float
    visible = Bool

&gt;&gt;&gt; preferences = Preferences(filename='example.ini')
&gt;&gt;&gt; helper = SplashScreenPreferences(preferences=preferences)
&gt;&gt;&gt; helper.bgcolor
'blue'
&gt;&gt;&gt; helper.width
100
&gt;&gt;&gt; helper.ratio
1.0
&gt;&gt;&gt; helper.visible
True</pre>
</div>
<p>And, obviously, I can set the value of the preferences via the helper too:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">helper</span><span class="o">.</span><span class="n">ratio</span> <span class="o">=</span> <span class="mf">0.5</span>
</pre></div>
</div>
<p>And if you want to prove to yourself it really did set the preference:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.ratio&#39;</span><span class="p">)</span>
<span class="go">&#39;0.5&#39;</span>
</pre></div>
</div>
<p>Using a preferences helper you also get notified via the usual trait
mechanism when the preferences are changed (either via the helper or via the
preferences node directly:</p>
<div class="highlight-python"><pre>def listener(obj, trait_name, old, new):
    print trait_name, old, new

&gt;&gt;&gt; helper.on_trait_change(listener)
&gt;&gt;&gt; helper.ratio = 0.75
ratio 0.5 0.75
&gt;&gt;&gt; preferences.set('acme.ui.ratio', 0.33)
ratio 0.75 0.33</pre>
</div>
<p>If you always use the same preference node as the root of your preferences you
can also set the class attribute &#8216;PreferencesHelper.preferences&#8217; to be that
node and from then on in, you don&#8217;t have to pass a preferences collection in
each time you create a helper:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">PreferencesHelper</span><span class="o">.</span><span class="n">preferences</span> <span class="o">=</span> <span class="n">Preferences</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="s">&#39;example.ini&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">helper</span> <span class="o">=</span> <span class="n">SplashScreenPreferences</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">helper</span><span class="o">.</span><span class="n">bgcolor</span>
<span class="go">&#39;blue&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">helper</span><span class="o">.</span><span class="n">width</span>
<span class="go">100</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">helper</span><span class="o">.</span><span class="n">ratio</span>
<span class="go">1.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">helper</span><span class="o">.</span><span class="n">visible</span>
<span class="go">True</span>
</pre></div>
</div>
</div>
<div class="section" id="scoped-preferences">
<h1>Scoped Preferences<a class="headerlink" href="#scoped-preferences" title="Permalink to this headline">¶</a></h1>
<p>In many applications the idea of preferences scopes is useful. In a scoped
system, an actual preference value can be stored in any scope and when a call
is made to the &#8216;get&#8217; method the scopes are searched in order of precedence.</p>
<p>The default implementation (in the <a class="reference external" href="../../enthought/preferences/scoped_preferences.py">ScopedPreferences</a> class) provides two
scopes by default:</p>
<ol class="arabic simple">
<li>The application scope</li>
</ol>
<p>This scope stores itself in the &#8216;ETSConfig.application_home&#8217; directory. This
scope is generally used when <em>setting</em> any user preferences.</p>
<ol class="arabic simple" start="2">
<li>The default scope</li>
</ol>
<p>This scope is transient (i.e. it does not store itself anywhere). This scope
is generally used to load any predefined default values into the preferences
system.</p>
<p>If you are happy with the default arrangement, then using the scoped
preferences is just like using the plain old non-scoped version:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">enthought.preferences.api</span> <span class="kn">import</span> <span class="n">ScopedPreferences</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span> <span class="o">=</span> <span class="n">ScopedPreferences</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="s">&#39;example.ini&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="s">&#39;example.ini&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">dump</span><span class="p">()</span>

<span class="go">  Node() {}</span>
<span class="go">    Node(application) {}</span>
<span class="go">      Node(acme) {}</span>
<span class="go">        Node(ui) {&#39;bgcolor&#39;: &#39;blue&#39;, &#39;ratio&#39;: &#39;1.0&#39;, &#39;width&#39;: &#39;50&#39;, &#39;visible&#39;: &#39;True&#39;}</span>
<span class="go">          Node(splash_screen) {&#39;image&#39;: &#39;splash&#39;, &#39;fgcolor&#39;: &#39;red&#39;}</span>
<span class="go">    Node(default) {}</span>
</pre></div>
</div>
<p>Here you can see that the root node now has a child node representing each
scope.</p>
<p>When we are getting and setting preferences using scopes we generally want the
following behaviour:</p>
<p>a) When we get a preference we want to look it up in each scope in order. The
first scope that contains a value &#8216;wins&#8217;.</p>
<p>b) When we set a preference, we want to set it in the first scope. By default
this means that when we set a preference it will be set in the application
scope. This is exactly what we want as the application scope is the scope that
is persistent.</p>
<p>So usually, we just use the scoped preferences as before:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;acme.ui.bgcolor&#39;</span><span class="p">)</span>
<span class="go">&#39;blue&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s">&#39;acme.ui.bgcolor&#39;</span><span class="p">,</span> <span class="s">&#39;red&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">dump</span><span class="p">()</span>

<span class="go">  Node() {}</span>
<span class="go">    Node(application) {}</span>
<span class="go">      Node(acme) {}</span>
<span class="go">        Node(ui) {&#39;bgcolor&#39;: &#39;red&#39;, &#39;ratio&#39;: &#39;1.0&#39;, &#39;width&#39;: &#39;50&#39;, &#39;visible&#39;: &#39;True&#39;}</span>
<span class="go">          Node(splash_screen) {&#39;image&#39;: &#39;splash&#39;, &#39;fgcolor&#39;: &#39;red&#39;}</span>
<span class="go">    Node(default) {}</span>
</pre></div>
</div>
<p>And, conveniently, preference helpers work just the same with scoped
preferences too:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">PreferencesHelper</span><span class="o">.</span><span class="n">preferences</span> <span class="o">=</span> <span class="n">ScopedPreferences</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="s">&#39;example.ini&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">helper</span> <span class="o">=</span> <span class="n">SplashScreenPreferences</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">helper</span><span class="o">.</span><span class="n">bgcolor</span>
<span class="go">&#39;blue&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">helper</span><span class="o">.</span><span class="n">width</span>
<span class="go">100</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">helper</span><span class="o">.</span><span class="n">ratio</span>
<span class="go">1.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">helper</span><span class="o">.</span><span class="n">visible</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="section" id="accessing-a-particular-scope">
<h2>Accessing a particular scope<a class="headerlink" href="#accessing-a-particular-scope" title="Permalink to this headline">¶</a></h2>
<p>Should you care about getting or setting a preference in a particular scope
then you use the following syntax:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s">&#39;default/acme.ui.bgcolor&#39;</span><span class="p">,</span> <span class="s">&#39;red&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;default/acme.ui.bgcolor&#39;</span><span class="p">)</span>
<span class="go">&#39;red&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preferences</span><span class="o">.</span><span class="n">dump</span><span class="p">()</span>

<span class="go">  Node() {}</span>
<span class="go">    Node(application) {}</span>
<span class="go">      Node(acme) {}</span>
<span class="go">        Node(ui) {&#39;bgcolor&#39;: &#39;red&#39;, &#39;ratio&#39;: &#39;1.0&#39;, &#39;width&#39;: &#39;50&#39;, &#39;visible&#39;: &#39;True&#39;}</span>
<span class="go">          Node(splash_screen) {&#39;image&#39;: &#39;splash&#39;, &#39;fgcolor&#39;: &#39;red&#39;}</span>
<span class="go">    Node(default) {}</span>
<span class="go">      Node(acme) {}</span>
<span class="go">        Node(ui) {&#39;bgcolor&#39;: &#39;red&#39;}</span>
</pre></div>
</div>
<p>You can also get hold of a scope via:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">default</span> <span class="o">=</span> <span class="n">preferences</span><span class="o">.</span><span class="n">get_scope</span><span class="p">(</span><span class="s">&#39;default&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>And then perform any of the usual operations on it.</p>
</div>
</div>
<div class="section" id="further-reading">
<h1>Further Reading<a class="headerlink" href="#further-reading" title="Permalink to this headline">¶</a></h1>
<p>So that&#8217;s a quick tour around the basic useage of the preferences API. For more
imformation about what is provided take a look at the <a class="reference external" href="api/index.html">API</a> documentation.</p>
<p>If you are using Envisage to build your applications then you might also be
interested in the <a class="reference external" href="PreferencesInEnvisage.html">Preferences in Envisage</a> section.</p>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">Preferences</a></li>
<li><a class="reference external" href="#the-basic-preferences-mechanism">The Basic Preferences Mechanism</a><ul>
<li><a class="reference external" href="#strings-glorious-strings">Strings, Glorious Strings</a></li>
</ul>
</li>
<li><a class="reference external" href="#preferences-and-types">Preferences and Types</a></li>
<li><a class="reference external" href="#scoped-preferences">Scoped Preferences</a><ul>
<li><a class="reference external" href="#accessing-a-particular-scope">Accessing a particular scope</a></li>
</ul>
</li>
<li><a class="reference external" href="#further-reading">Further Reading</a></li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="../permissions/DefaultUserManagerDataAPI.html"
                                  title="previous chapter">Default User Manager Data API</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="PreferencesInEnvisage.html"
                                  title="next chapter">Preferences in Envisage</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/preferences/Preferences.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="PreferencesInEnvisage.html" title="Preferences in Envisage"
             >next</a> |</li>
        <li class="right" >
          <a href="../permissions/DefaultUserManagerDataAPI.html" title="Default User Manager Data API"
             >previous</a> |</li>
        <li><a href="../index.html">AppTools v3.3.0 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2008, Enthought.
      Last updated on Aug 21, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.2.
    </div>
  </body>
</html>