Sophie

Sophie

distrib > Fedora > 13 > x86_64 > by-pkgid > 0abf02bb2abda94c2db99ef2a28c8a2c > files > 860

python-AppTools-3.3.2-1.fc13.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 in Envisage &mdash; AppTools v3.1.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.1.0',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: '.html'
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="contents" title="Global table of contents" href="../contents.html" />
    <link rel="index" title="Global index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="top" title="AppTools v3.1.0 documentation" href="../index.html" />
    <link rel="next" title="Automatic script recording" href="../scripting/introduction.html" />
    <link rel="prev" title="Preferences" href="Preferences.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="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="../scripting/introduction.html" title="Automatic script recording"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="Preferences.html" title="Preferences"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">AppTools v3.1.0 documentation</a> &raquo;</li>
      </ul>
    </div>
    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  
  <div class="section" id="preferences-in-envisage">
<h1>Preferences in Envisage<a class="headerlink" href="#preferences-in-envisage" title="Permalink to this headline">ΒΆ</a></h1>
<p>This section discusses how an Envisage application uses the preferences
mechanism. Envisage tries not to dictate too much, and so this describes the
default behaviour, but you are free to override it as desired.</p>
<p>Envisage uses the default implementation of the <a class="reference external" href="../../enthought/preferences/scoped_preferences.py">ScopedPreferences</a> class which
is made available via the application&#8217;s &#8216;preferences&#8217; trait:</p>
<div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">application</span> <span class="o">=</span> <span class="n">Application</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="s">&#39;myapplication&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">application</span><span class="o">.</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;yellow&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">application</span><span class="o">.</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;yellow&#39;</span>
</pre></div>
<p>Hence, you use the Envisage preferences just like you would any other scoped
preferences.</p>
<p>It also registers itself as the default preferences node used by the
<a class="reference external" href="../../enthought/preferences/preferences_helper.py">PreferencesHelper</a> class. Hence you don&#8217;t need to provide a preferences node
explicitly to your helper:</p>
<div class="highlight"><pre><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>
<p>The only extra thing that Envisage does for you is to provide an extension
point that allows you to contribute any number of &#8216;.ini&#8217; files that are
loaded into the default scope when the application is started.</p>
<p>e.g. To contribute a preference file for my plugin I might use:</p>
<div class="highlight"><pre><span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
    <span class="o">...</span>

    <span class="nd">@contributes_to</span><span class="p">(</span><span class="s">&#39;enthought.envisage.preferences&#39;</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">get_preferences</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">application</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">[</span><span class="s">&#39;pkgfile://mypackage:preferences.ini&#39;</span><span class="p">]</span>
</pre></div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h4>Previous topic</h4>
            <p class="topless"><a href="Preferences.html" title="previous chapter">Preferences</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="../scripting/introduction.html" title="next chapter">Automatic script recording</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/preferences/PreferencesInEnvisage.txt">Show Source</a></li>
            </ul>
            <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>
        </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"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="../scripting/introduction.html" title="Automatic script recording"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="Preferences.html" title="Preferences"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">AppTools v3.1.0 documentation</a> &raquo;</li>
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2008, Enthought.
      Last updated on Dec 03, 2008.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
    </div>
  </body>
</html>