Re: Gtk2 and inheritance



Guillaume Cottenceau wrote:

But here I was mistaken (probably I should get more sleep ;). In fact 
inheritance without the ability of attaching additional attributes to an
object, is useless.

Use `$object->set_data' and `$object->get_data'.

Ok - I hoped that the solution would be that easy ;) Thanks. It's better
than converting the slim scalar references into fat hash references ;)

So we agree, re-blessing gtk2 objects from perl code is useless :).

Sorry - but here I disagree ;) The re-blessing is still necessary, 
otherwise the methods of my class are not visible. I can live with the 
fact, that the class has to use the set_data() method to store its 
attributes, but the re-blessing is still necessary (and thus the 
SvREADONLY_on(obj) needs to be dropped - Goran, is that Ok with you?)

To inherit from Gtk2 classes is useful. I use this to get text entries,
which are checked automatically:

  my $entry = My::Gtk2::Entry->new;
  $entry->show;
  $entry->set_is_numeric(1);
  $entry->set_has_min_value(0);
  $entry->set_has_max_value(255),

The My::Gtk2::Entry class connects the needed signals and checks changed
values automatically, opens a message window if a value is illegal and 
restores the old value. All this is implemented on a very low level, so
my application can be absolutely sure, that the entered values are 
always valid.

I used this quite often with Gtk and so I really like to keep using it 
with Gtk2 ;)

Regards,

Joern

-- 
Think, before you code.




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