addlistener() question

Ben Abbott bpabbott at mac.com
Wed Dec 31 23:41:12 CST 2008


On Dec 31, 2008, at 11:52 PM, Shai Ayal wrote:

> On Thu, Jan 1, 2009 at 1:45 AM, Ben Abbott <bpabbott at mac.com> wrote:
>> I've been experimenting with addlistener() with the intent of adding
>> listeners for particular aspects of the graphics backend(s).
>>
>>> addlistener (H, PROP, FCN)
>>> PROP must be a string naming a valid property of the graphics object
>>> handle, H.
>>> FCN can be a function handle, a string or a cell array whose first  
>>> element
>>> is a function handle.
>>
>> So my question is; Does anyone have a thought of how to listen for  
>> a change
>> to "units" and have the call back function modify the value(s)  
>> associated
>> with the units? For example, consider the Matlab commands below
>>
>>>> figure(1)
>>>> get (gcf, 'position')
>>
>> ans =  440   314   560   420
>>
>>>> set (gcf, 'units', 'inches')
>>>> get (gcf, 'position')
>>
>> ans =  5.8572       4.1761       7.4716       5.6037
>>
>> To implement this action in Octave, both the "units" setting prior  
>> to and
>> after the "set" command must be known. Might there be a creative  
>> way to pass
>> the units setting prior to the "set" command to the callback?
>
> I'm not sure this is the best way. The way it is currently implemented
> is the graphics system always storing the values in a fixed set of
> units and doing the translation "on-the-fly" when you set/get the
> values (e.g. for the position property, always keep the value in
> pixels, and if the units are not pixels, set/get will translate the
> values into the appropriate units): I think the mechanism is already
> in place:
> http://hg.savannah.gnu.org/hgweb/octave/file/cc3ac5eb6be3/src/graphics.cc#l177
>
> but maybe Michael has a better grasp of this portion of the code...
>
> Shai

Thanks Shai.

It does appear that something is listening to the figure position, and  
that some of my committed work on gnuplot_drawnow() has a problem with  
it (my fault, I think).

In any event, I was inclined to use m-files to implement the  
listeners. Mainly for two reasons; (1) I'm clumsy at best with c/c++  
and (2) m-files do not require that I recompile.

I'm working on a m-file function that handles all such callbacks for  
listeners. It is simple enough to turn on or off a listener in favor  
of another. So, think I'll begin with m-file implementations first and  
then look at converting to c/c++. In that effort, Michael's work will  
be quite helpful to me.

btw, I have found a solution to my question. My solution is to have  
the callback function delete the listener and create a new one in its  
place, and to pass to the callback the current value to the property  
being modified.

If anyone has a better solution, please say the word. In the meantime,  
I'll spend some time reviewing Michael's efforts.

Ben






More information about the Octave-maintainers mailing list