Re: Creating new widgets

Hi Matthew;

On Fri, 2006-10-13 at 11:34 +1000, Matthew Braid wrote:
Hi again,

Now, the problem I've hit here is that the column_types property seems
to be set _after_ INIT_INSTANCE is called, which means when I'm
building the first row (which must always be shown - at the moment I
don't enforce that but I will) I don't know what to build. 


This happens because what you want is a constructor property.
Unfortunately, as I said here:

gtk-perl does not allow implementing the GObject::constructor virtual

One workaround I've found is to remove the initial add_row from
INIT_INSTANCE and instead put it in the set function for the
column_types property. This seems just a tad hacky to me, but does
seem to work.

The only way you can work around the lack of the constructor vfunc is to
rely on a perl-only property: create your own constructor function,

  sub new_with_template {
      my ($class, $template) = @_;
      my $retval = $class->new->apply_template($template);
      return $retval;

where "apply_template" is the function where you build your own rows
using the template string you pass.


[1] The GObject construction chain in C goes like this:

  class init -> base init -> init -> constructor

  class init: initialise class-wide stuff like signals and properties
  base init: called each time a class is instanced by derived classes
  init: initialise the instance
  constructor: create the instance, get the constructor and constructor
               only properties.

The only part that can be overridden by the Glib::Object perl bindings
is the init, which is INIT_INSTANCE.  this means that you get to set
up the *initial* state of an object's new instance.  since you want your
object to be constructed differently depending on a constructor property
you should override the constructor - but, in perl, you really can't.


Emmanuele Bassi,  E: ebassi gmail com

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]