Sign up

when does a DrawingArea know its parent?

Under what circumstances does a DrawingArea know its parent?

That is, suppose you have code like this:

  import gtk.DrawingArea;
  class My_Class : DrawingArea {
    this(  ) {
      super( );
      // other stuff
    }
    void query( ) {
      Widget parent = this.getParent( );
      // do something with parent
   }
  }
  auto my_object = new My_Class( .... );
  Box b = get_from_glade_somehow( );
  b.add(my_object);
  containing_window.show( );
  my_object.query( );

Would you expect the getParent( ) call to return something non-null?

The reason i'm asking is i'm trying to debug something, and it would be handy to take a look at the parent.

However, the parent from getParent( ) is showing up as null.

I think that might be ok, as this is what happens in Oldrich Smehlik's gPolynomial app (hosted on github) in his Plot class.

And in that case, i'll just force in a reference to the parent at construction time and use that.

But if the DrawingArea really should already have a pointer to its parent for whatever reason, i don't want to hack in a second copy so unnecessarily.

(As a secondary issue, it's a unclear to me whether i have to make a call to super() inside the constructor.)

TIA for any info or references (maybe this is mostly a gtk question rather than a gtkd question?).

Re: when does a DrawingArea know its parent?

On Sun, 29 May 2016 20:20:23 GMT, dan hitt wrote:

Under what circumstances does a DrawingArea know its parent?

That is, suppose you have code like this:

  import gtk.DrawingArea;
  class My_Class : DrawingArea {
    this(  ) {
      super( );
      // other stuff
    }
    void query( ) {
      Widget parent = this.getParent( );
      // do something with parent
   }
  }
  auto my_object = new My_Class( .... );
  Box b = get_from_glade_somehow( );
  b.add(my_object);
  containing_window.show( );
  my_object.query( );

Would you expect the getParent( ) call to return something non-null?

The reason i'm asking is i'm trying to debug something, and it would be handy to take a look at the parent.

However, the parent from getParent( ) is showing up as null.

I think that might be ok, as this is what happens in Oldrich Smehlik's gPolynomial app (hosted on github) in his Plot class.

OK, so i was totally mistaken here :(

In Oldrich's code the parent certainly is not null, and it was not in my imitation code either, but i got my test results inverted.

So sorry for the noise!

dan