~gdesklets-desklet-team/gdesklets/0.36

« back to all changes in this revision

Viewing changes to doc/book/prefs-system.xml

  • Committer: Robert Pastierovic
  • Date: 2007-10-07 10:08:42 UTC
  • Revision ID: pastierovic@gmail.com-20071007100842-fdvp2vzmqgh1j87k
merged 0.3x branch and basic documentation and some other changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<section id="prefs-system" xmlns:xi="http://www.w3.org/2001/XInclude">
 
2
  <title>Preferences System</title>
 
3
 
 
4
<section><title>Preferences Dialog</title>
 
5
 
 
6
  <para>Every applet can provide a dialog where users can change the
 
7
    configuration.
 
8
    This dialog usually consists of several pages for different categories,
 
9
    and is defined in the <filename>.display</filename> file inside the
 
10
    <link linkend="prefs-tag-prefs"><command>&lt;prefs&gt;</command></link>
 
11
    tag.</para>
 
12
 
 
13
  <para>Each of the pages lists a number of configuration elements, such as
 
14
    entry fields, spin buttons, file selectors, font selectors, etc.</para>
 
15
 
 
16
  <screenshot>
 
17
    <mediaobject>
 
18
      <imageobject>
 
19
        <imagedata fileref="gfx/prefs" format="PNG"/>
 
20
      </imageobject>
 
21
    </mediaobject>
 
22
  </screenshot>
 
23
 
 
24
</section>
 
25
 
 
26
 
 
27
 
 
28
<section><title>Bindings</title>
 
29
 
 
30
  <para>Every configuration element is directly bound to a readable and
 
31
    writable object in the scripting environment. This can be a control property
 
32
    as well as a display element's property, or just a variable in the scripts.
 
33
    </para>
 
34
 
 
35
  <para>The bound object is where you can read the configuration setting from.
 
36
    The direct binding can be seen in the following example.</para>
 
37
 
 
38
  <programlisting><![CDATA[
 
39
<display>
 
40
 
 
41
  <label id="mylabel" value="Change me!" font="Serif 1cm"/>
 
42
 
 
43
 
 
44
  <prefs>
 
45
 
 
46
    <string label="Label Text:" bind="Dsp.mylabel.value"/>
 
47
 
 
48
  </prefs>
 
49
 
 
50
</display>
 
51
  ]]></programlisting>
 
52
 
 
53
  <para>After opening the preferences dialog, you can change the value of the
 
54
    label by editing the string configuration element. If you restart the
 
55
    display or <application>gDesklets</application>, you will see that the
 
56
    current label text has been saved.</para>
 
57
 
 
58
  <para>That way it is possible to save the configuration of any object across
 
59
    sessions.</para>
 
60
 
 
61
</section>
 
62
 
 
63
 
 
64
 
 
65
<section><title>Default Value</title>
 
66
 
 
67
  <para>The default value for any configuration setting is the initial value of
 
68
    the object to which it is bound. The settings are read in after the
 
69
    initialization of the display. So, if values were saved, the bound objects
 
70
    will be set to them immediately after the initialization phase.</para>
 
71
 
 
72
</section>
 
73
 
 
74
 
 
75
 
 
76
<section><title>Callback Function <emph>[new in 0.34]</emph></title>
 
77
 
 
78
  <para>Sometimes, it is neccessary to react to configuration changes in a
 
79
    special way. For example, an URI should be checked for validity before it
 
80
    is actually being used. The
 
81
    <link linkend="prefs-tag-prefs"><command>&lt;prefs&gt;</command></link> tag,
 
82
    as well as all other preferences tags, provides a callback hook for that 
 
83
    purpose.</para>
 
84
  
 
85
  <para>It may also be beneficial to change preferences when others change.  
 
86
    This can be done with the <literal>Prefs</literal> namespace.</para>
 
87
 
 
88
  <programlisting><![CDATA[
 
89
<prefs callback="prefs_cb">
 
90
  
 
91
  <page label="Test">
 
92
  
 
93
    <boolean id="ex_bool" label="Checkbox!" bind="ex_bool_is_set" callback="check_ex_bool"/>
 
94
  
 
95
    <enum id="e" label="some enum" bind="foo"/>
 
96
  
 
97
  </page>
 
98
  
 
99
</prefs>
 
100
 
 
101
<script>
 
102
 
 
103
  Prefs.e.items = [(label, value), (label, value), (label, value)]
 
104
  Prefs.ex_bool.value = False
 
105
 
 
106
</script>
 
107
 
 
108
]]></programlisting>
 
109
 
 
110
  <para>The callback function specified in the hook will be called whenever
 
111
    a configuration setting changes its value. The callback function is called
 
112
    with two arguments; the name of the bound object, and the new value.</para>
 
113
 
 
114
</section>
 
115
 
 
116
</section>