bugGNU Octave - Bugs: bug #44242, Adding a listener to the...

 
 

bug #44242: Adding a listener to the "children" property has no effect

Submitter:  Ben Abbott <bpabbott>
Submitted:  Fri 13 Feb 2015 09:28:15 PM UTC
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  pantxo
Originator Name:  Ben Abbott Open/Closed:  * Closed
Release:  * 3.8.2 Operating System:  * Any
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

( Jump to the original submission )

Wed 18 Feb 2015 05:11:22 PM UTC, comment #13: 

I just tested

tic, test ('../octaveclone/libinterp/corefcn/graphics.cc'), toc

The execution time is 4.85+/-0.1s with or without the patch, so yes, when there is no listener, the impact is negligible.
I don't see a practical case where listening "children" property may be useful, but as I showed this will cause listener functions to be called several times. Note that this is also true for other properties.

Pantxo Diribarne <pantxo>
Project Member
Wed 18 Feb 2015 04:55:08 PM UTC, comment #12: 

Is there any performance hit to this patch?  Or is it generally zero because adding a listener to the children property is infrequent?

Rik <rik5>
Project Administrator
Wed 18 Feb 2015 03:46:36 PM UTC, comment #11: 

Thank you Ben, I pushed the changeset at http://hg.savannah.gnu.org/hgweb/octave/rev/99ef3e58214e.

Closing report.

Pantxo Diribarne <pantxo>
Project Member
Tue 17 Feb 2015 07:28:43 PM UTC, comment #10: 

I applied you patch to the stable branch and it works for for me as well.

Ben Abbott <bpabbott>
Project Member
Tue 17 Feb 2015 06:34:23 PM UTC, comment #9: 

Hi,

The attached patch fixes the issue for me. Using listeners on axes children property is a bit noisy (e.g. Octave internally deletes recreates text labels when "nextplot" is "replace"):

>> clf ();
>> hax = axes ();
>> fcn = @() disp ("Children modified");
>> addlistener (hax, "children", fcn);
>> plot (rand (3))
Children modified
Children modified
Children modified
Children modified
Children modified
Children modified
Children modified
>> hold all
>> plot (rand (3))
Children modified
Children modified
Children modified
>> h = get (gca (), "children");
>> set (gca (), "children", flipud (h))
Children modified

(file #33111)

Pantxo Diribarne <pantxo>
Project Member
Sun 15 Feb 2015 09:18:37 AM UTC, comment #8: 

@Ben: yes it is possible on the c++ side to call "set" function without executing listeners and notifying toolkit. There are two boolean arguments that let you choose.

Pantxo Diribarne <pantxo>
Project Member
Sat 14 Feb 2015 04:45:43 PM UTC, comment #7: 

I'm not exactly trustworthy when it comes to reading c++, but it looks to me as if the listeners are not called when the children are modified from the c++ side, which is what happens when a new object is added to a parent.

To check I tried the modified script below.

1;
function my_handler (h, dummy)
  fprintf ("my_handler called\n");
endfunction
figure (1)
clf ()
hax = axes ();
plot (rand (3))
hold all
fcn = @my_handler;
prop = "children";
addlistener (hax, prop, fcn)
plot (rand (3))
h = get (gca (), prop);
set (gca (), prop, flipud (h))

Running this script does trigger the listener.

Is it possible that listeners are only triggered when the associated property is modified from an m-file, or command line?

Ben Abbott <bpabbott>
Project Member
Sat 14 Feb 2015 03:50:25 PM UTC, comment #6: 

Most properties XXX have their listener run in their corresponding set_XXX method. For some properties, the set_XXX is not generated automatically (marked S or s in the genprop.awk macro). Then the run_listeners method has to be added by hand to their specific set_XXX method. Maybe it has been forgotten for "children" properties ... I can't verify this guess now but if someone wants to investigate I'd watch in this direction.

Pantxo Diribarne <pantxo>
Project Member
Sat 14 Feb 2015 01:54:55 AM UTC, comment #5: 

Until we understand why addlistener doesn't work for "children" I'd hesitate to reduce the severity.

Ben Abbott <bpabbott>
Project Member
Sat 14 Feb 2015 01:19:18 AM UTC, comment #4: 

Can we lower the priority to minor?  Or is there a compelling use case for listeners on the "children" property of graphics objects?

Rik <rik5>
Project Administrator
Sat 14 Feb 2015 01:12:36 AM UTC, comment #3: 

I think the Matlab version of addlistener() is for classdef objects.

http://www.mathworks.com/help/matlab/ref/handle.addlistener.html

Ben Abbott <bpabbott>
Project Member
Sat 14 Feb 2015 12:27:13 AM UTC, comment #2: 

Matlab doesn't have a compatible addlistener() function. in R2014a,

fcn = @(h,arg1,arg2) disp ('hello world')

fcn =

    @(h,arg1,arg2)disp('hello world')

axes
addlistener (gca (), 'children', fcn)
The specified event is not supported by the object

Ben Abbott <bpabbott>
Project Member
Fri 13 Feb 2015 11:33:31 PM UTC, comment #1: 

Does this work in Matlab?  I expect so, but it would be nice to check.

Rik <rik5>
Project Administrator
Fri 13 Feb 2015 09:28:15 PM UTC, original submission:  

When run, the example below should print "my_hander called" to the command line.

1;
function my_handler (h, dummy)
  fprintf ("my_handler called\n");
endfunction
figure (1)
clf ()
hax = axes ();
plot (rand (3))
hold all
fcn = @my_handler;
addlistener (hax, "children", fcn)
plot (rand (3))

Ben Abbott <bpabbott>
Project Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by bpabbott (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only project members can vote.

     

     

     

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-02-18 pantxo StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2015-02-17 bpabbott StatusNone Patch Submitted
        Assigned toNone pantxo
    2015-02-17 pantxo Attached File- Added fix_children_listener.patch, #33111

    Back to the top


    Powered by Savane 3.9