Re: Variable Config Read and Write Questions

2021-11-29 Thread Jeff Long
Submitted Issue https://github.com/gnuradio/gnuradio/issues/5359.

On Mon, Nov 29, 2021 at 7:31 PM Jeff Long  wrote:

> The Variable Config is definitely a strange one, when used as you are
> using it (read and write to runtime-selectable sections). Here's the code
> it generates for handling a change in section (e.g., toggling between 40
> and 80 in your example). I've created two config variables, freq and lna.
>
> def set_section(self, section):
> self.section = section
> self._freq_config_config = configparser.ConfigParser()
> self._freq_config_config.read('/tmp/testconfig.ini')
> if not self._freq_config_config.has_section(self.section):
> self._freq_config_config.add_section(self.section)
> self._freq_config_config.set(self.section, 'freq', str(self.freq))
> self._freq_config_config.write(open('/tmp/testconfig.ini', 'w'))
> self._lna_config_config = configparser.ConfigParser()
> self._lna_config_config.read('/tmp/testconfig.ini')
> if not self._lna_config_config.has_section(self.section):
> self._lna_config_config.add_section(self.section)
> self._lna_config_config.set(self.section, 'lna', str(self.lna))
> self._lna_config_config.write(open('/tmp/testconfig.ini', 'w'))
> self._section_callback(self.section)
>
> which says it will do exactly what you're seeing. This is the first time
> I've heard of the block, actually, so I'm sure it's not getting much
> attention!
>
> I'll put in an Issue on this. You should probably find another way to do
> what you are thinking of, since I don't think this will be addressed right
> away. Thanks for the report.
>
> On Mon, Nov 29, 2021 at 6:22 PM Elmore's  wrote:
>
>> Variable Config
>> ID: I_image_config
>> Section: image_sections[image_chooser]
>> Option: I_image_correct
>> Write Back: I_Gain
>>
>> GUI Range
>> ID: I_Gain
>> Default: I_image_config
>>
>> I found a question similar to this one on the forum but no one answered
>> it so I hope I can get a response to this one.
>>
>> I have shown above my configuration for two blocks in my flowgraph.
>>
>> I wish to write to and read from an INI file with 5 sections.
>>
>> I can successfully write the value of I_Gain to I_image_correct in a
>> single section when I make an adjustment to the I_Gain Range control. I
>> want to use a Chooser with the ID: image_chooser to select another section
>> to write a value of I_Gain to that section. However, the Chooser callback
>> writes the current value of I_Gain immediately to the file without my
>> making a change to I_Gain. This is a major problem if I wish to select a
>> Section that I had already stored a value in. Whatever the current value of
>> I_Gain happens to be is written to the Section. For example: I change
>> I_Gain to 1.1 for Section 40. I then select Section 80 which immediately
>> upon selection has 1.1 written to it. I then select I_Gain = 1.5 which
>> stores that value in Section 80. I then select Section 40 in hopes of using
>> I_Gain = 1.1 but find that in the process of selection the value of I_Gain
>> has changed to 1.5. This makes no sense since it defeats the purpose of
>> saving a configuration in a file.
>>
>> How do I save parameters to different sections without the sections being
>> overwritten?
>>
>> The other main issue is how do I read from the file so that I can set
>> I_Gain when the Section is selected? I don’t see how to do this. The only
>> time I have seen the file read is on initialization. I presume this is due
>> to the fact that I set the default value of I_Gain to I_image_config. I
>> need to to be able to read a value on demand.
>>
>> By the way, I have 3 parameters to save and recall in each of 5 Sections.
>>
>> Any help will be greatly appreciated. I have been wrestling with this
>> issue for quite some time.
>>
>>
>>
>>
>> 
>>  Virus-free.
>> www.avg.com
>> 
>> <#m_8892035469763263520_m_-7819765792157969049_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>


Re: Variable Config Read and Write Questions

2021-11-29 Thread Jeff Long
The Variable Config is definitely a strange one, when used as you are using
it (read and write to runtime-selectable sections). Here's the code it
generates for handling a change in section (e.g., toggling between 40 and
80 in your example). I've created two config variables, freq and lna.

def set_section(self, section):
self.section = section
self._freq_config_config = configparser.ConfigParser()
self._freq_config_config.read('/tmp/testconfig.ini')
if not self._freq_config_config.has_section(self.section):
self._freq_config_config.add_section(self.section)
self._freq_config_config.set(self.section, 'freq', str(self.freq))
self._freq_config_config.write(open('/tmp/testconfig.ini', 'w'))
self._lna_config_config = configparser.ConfigParser()
self._lna_config_config.read('/tmp/testconfig.ini')
if not self._lna_config_config.has_section(self.section):
self._lna_config_config.add_section(self.section)
self._lna_config_config.set(self.section, 'lna', str(self.lna))
self._lna_config_config.write(open('/tmp/testconfig.ini', 'w'))
self._section_callback(self.section)

which says it will do exactly what you're seeing. This is the first time
I've heard of the block, actually, so I'm sure it's not getting much
attention!

I'll put in an Issue on this. You should probably find another way to do
what you are thinking of, since I don't think this will be addressed right
away. Thanks for the report.

On Mon, Nov 29, 2021 at 6:22 PM Elmore's  wrote:

> Variable Config
> ID: I_image_config
> Section: image_sections[image_chooser]
> Option: I_image_correct
> Write Back: I_Gain
>
> GUI Range
> ID: I_Gain
> Default: I_image_config
>
> I found a question similar to this one on the forum but no one answered it
> so I hope I can get a response to this one.
>
> I have shown above my configuration for two blocks in my flowgraph.
>
> I wish to write to and read from an INI file with 5 sections.
>
> I can successfully write the value of I_Gain to I_image_correct in a
> single section when I make an adjustment to the I_Gain Range control. I
> want to use a Chooser with the ID: image_chooser to select another section
> to write a value of I_Gain to that section. However, the Chooser callback
> writes the current value of I_Gain immediately to the file without my
> making a change to I_Gain. This is a major problem if I wish to select a
> Section that I had already stored a value in. Whatever the current value of
> I_Gain happens to be is written to the Section. For example: I change
> I_Gain to 1.1 for Section 40. I then select Section 80 which immediately
> upon selection has 1.1 written to it. I then select I_Gain = 1.5 which
> stores that value in Section 80. I then select Section 40 in hopes of using
> I_Gain = 1.1 but find that in the process of selection the value of I_Gain
> has changed to 1.5. This makes no sense since it defeats the purpose of
> saving a configuration in a file.
>
> How do I save parameters to different sections without the sections being
> overwritten?
>
> The other main issue is how do I read from the file so that I can set
> I_Gain when the Section is selected? I don’t see how to do this. The only
> time I have seen the file read is on initialization. I presume this is due
> to the fact that I set the default value of I_Gain to I_image_config. I
> need to to be able to read a value on demand.
>
> By the way, I have 3 parameters to save and recall in each of 5 Sections.
>
> Any help will be greatly appreciated. I have been wrestling with this
> issue for quite some time.
>
>
>
>
> 
>  Virus-free.
> www.avg.com
> 
> <#m_-7819765792157969049_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>


Variable Config Read and Write Questions

2021-11-29 Thread Elmore's
Variable Config
ID: I_image_config
Section: image_sections[image_chooser]
Option: I_image_correct
Write Back: I_Gain

GUI Range
ID: I_Gain
Default: I_image_config

I found a question similar to this one on the forum but no one answered it so I 
hope I can get a response to this one.

I have shown above my configuration for two blocks in my flowgraph.

I wish to write to and read from an INI file with 5 sections.

I can successfully write the value of I_Gain to I_image_correct in a single 
section when I make an adjustment to the I_Gain Range control. I want to use a 
Chooser with the ID: image_chooser to select another section to write a value 
of I_Gain to that section. However, the Chooser callback writes the current 
value of I_Gain immediately to the file without my making a change to I_Gain. 
This is a major problem if I wish to select a Section that I had already stored 
a value in. Whatever the current value of I_Gain happens to be is written to 
the Section. For example: I change I_Gain to 1.1 for Section 40. I then select 
Section 80 which immediately upon selection has 1.1 written to it. I then 
select I_Gain = 1.5 which stores that value in Section 80. I then select 
Section 40 in hopes of using I_Gain = 1.1 but find that in the process of 
selection the value of I_Gain has changed to 1.5. This makes no sense since it 
defeats the purpose of saving a configuration in a file.

How do I save parameters to different sections without the sections being 
overwritten?

The other main issue is how do I read from the file so that I can set I_Gain 
when the Section is selected? I don’t see how to do this. The only time I have 
seen the file read is on initialization. I presume this is due to the fact that 
I set the default value of I_Gain to I_image_config. I need to to be able to 
read a value on demand.

By the way, I have 3 parameters to save and recall in each of 5 Sections.

Any help will be greatly appreciated. I have been wrestling with this issue for 
quite some time.



--
This email has been checked for viruses by AVG.
https://www.avg.com