Merging r11186:11273 from grc branch.
[debian/gnuradio] / grc / blocks / variable_config.xml
1 <?xml version="1.0"?>
2 <!--
3 ###################################################
4 ##Variable Config block:
5 ##  a variable that reads and writes to a config file
6 ###################################################
7  -->
8 <block>
9         <name>Variable Config</name>
10         <key>variable_config</key>
11         <import>import ConfigParser</import>
12         <var_make>self._$(id)_config = ConfigParser.ConfigParser()
13 self._$(id)_config.read($config_file)
14 if not self._$(id)_config.has_section($section):
15         self._$(id)_config.add_section($section)
16 try: $(id) = self._$(id)_config.$(type.get)($section, $option)
17 except: $(id) = $value
18 self.$(id) = $(id)</var_make>
19         <make></make>
20         <callback>self.set_$(id)($value)</callback>
21         <callback>self._$(id)_config.set($section, $option, str($writeback))
22 self._$(id)_config.write(open($config_file, 'w'))</callback>
23         <param>
24                 <name>Default Value</name>
25                 <key>value</key>
26                 <value>0</value>
27                 <type>$type</type>
28         </param>
29         <param>
30                 <name>Type</name>
31                 <key>type</key>
32                 <value>real</value>
33                 <type>enum</type>
34                 <option>
35                         <name>Float</name>
36                         <key>real</key>
37                         <opt>get:getfloat</opt>
38                 </option>
39                 <option>
40                         <name>Int</name>
41                         <key>int</key>
42                         <opt>get:getint</opt>
43                 </option>
44                 <option>
45                         <name>Bool</name>
46                         <key>bool</key>
47                         <opt>get:getbool</opt>
48                 </option>
49                 <option>
50                         <name>String</name>
51                         <key>string</key>
52                         <opt>get:get</opt>
53                 </option>
54         </param>
55         <param>
56                 <name>Config File</name>
57                 <key>config_file</key>
58                 <value>default</value>
59                 <type>file_open</type>
60         </param>
61         <param>
62                 <name>Section</name>
63                 <key>section</key>
64                 <value>main</value>
65                 <type>string</type>
66         </param>
67         <param>
68                 <name>Option</name>
69                 <key>option</key>
70                 <value>key</value>
71                 <type>string</type>
72         </param>
73         <param>
74                 <name>WriteBack</name>
75                 <key>writeback</key>
76                 <value>None</value>
77                 <type>raw</type>
78         </param>
79         <doc>
80 This block represents a variable that can be read from a config file.
81
82 To save the value back into the config file: \
83 enter the name of another variable into the writeback param. \
84 When the other variable is changed at runtime, the config file will be re-written.
85         </doc>
86 </block>