Imported Upstream version 3.2.2
[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 try: $(id) = self._$(id)_config.$(type.get)($section, $option)
15 except: $(id) = $value
16 self.$(id) = $(id)</var_make>
17         <make></make>
18         <callback>self.set_$(id)($value)</callback>
19         <callback>self._$(id)_config = ConfigParser.ConfigParser()
20 self._$(id)_config.read($config_file)
21 if not self._$(id)_config.has_section($section):
22         self._$(id)_config.add_section($section)
23 self._$(id)_config.set($section, $option, str($writeback))
24 self._$(id)_config.write(open($config_file, 'w'))</callback>
25         <param>
26                 <name>Default Value</name>
27                 <key>value</key>
28                 <value>0</value>
29                 <type>$type</type>
30         </param>
31         <param>
32                 <name>Type</name>
33                 <key>type</key>
34                 <value>real</value>
35                 <type>enum</type>
36                 <option>
37                         <name>Float</name>
38                         <key>real</key>
39                         <opt>get:getfloat</opt>
40                 </option>
41                 <option>
42                         <name>Int</name>
43                         <key>int</key>
44                         <opt>get:getint</opt>
45                 </option>
46                 <option>
47                         <name>Bool</name>
48                         <key>bool</key>
49                         <opt>get:getbool</opt>
50                 </option>
51                 <option>
52                         <name>String</name>
53                         <key>string</key>
54                         <opt>get:get</opt>
55                 </option>
56         </param>
57         <param>
58                 <name>Config File</name>
59                 <key>config_file</key>
60                 <value>default</value>
61                 <type>file_open</type>
62         </param>
63         <param>
64                 <name>Section</name>
65                 <key>section</key>
66                 <value>main</value>
67                 <type>string</type>
68         </param>
69         <param>
70                 <name>Option</name>
71                 <key>option</key>
72                 <value>key</value>
73                 <type>string</type>
74         </param>
75         <param>
76                 <name>WriteBack</name>
77                 <key>writeback</key>
78                 <value>None</value>
79                 <type>raw</type>
80         </param>
81         <doc>
82 This block represents a variable that can be read from a config file.
83
84 To save the value back into the config file: \
85 enter the name of another variable into the writeback param. \
86 When the other variable is changed at runtime, the config file will be re-written.
87         </doc>
88 </block>