Again: creating new widgets

I am trying to figure out, how to create new widgets ("real" widgets
with own signals) by composing or extending existing Gtk2 widgets.

I read the Glib::Object::Subclass man page and the previous discussion
on this list but I still quite get it. I tried a very simple exapmple -
A time widget consisting of 2 spinbuttons put into a hbox:

use base qw(Gtk2::HBox);
use Glib::Object::Subclass
 signals => {
             wrapped => { }

sub minute_wrap {
   my ($sb_min,$sb_hour)= _;
   $sb_hour->spin($sb_min->get_value() ? 'GTK_SPIN_STEP_BACKWARD'
                                       : 'GTK_SPIN_STEP_FORWARD', 1);

sub new {
   my $class=shift;
   my $hbox   = new Gtk2::HBox(1,5);
   my $sb_hour= new Gtk2::SpinButton(
                    new Gtk2::Adjustment(0,0,23,1,1,1), 1,0);
   my $sb_minute= new Gtk2::SpinButton(
                      new Gtk2::Adjustment(0,0,59,1,10,10), 1,0);
   $sb_minute->signal_connect("wrapped", \&minute_wrap, $sb_hour);
   $sb_hour->signal_connect("wrapped", sub {
                                $hbox->signal_emit("wrapped") },0);
   bless $hbox, $class;
   return $hbox;

I tried several variations, but couldn't get this to work. Obviously,
as far as glib is concerned, the created object is still a Gtk2::HBox
and can't have a signal "wrapped". Is it possible to re-bless an existing
object this way or does the whole Glib::Object::Subclass mechanism
only work with brand new classes?

                      Peter Daum

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