Can a subclassed Dialog return a variable?



Hi, 
I was trying to create a subclassed Dialog that returned
the settings of some Scales. As hard as I tried, the Dialog
would only return the integer assigned to the buttons. Like:

The problem is that $self->{result} gets set and won't change.
I'm trying to change it from 42 to 43.

#!/usr/bin/perl
use strict;
use warnings;
use Gtk2 '-init';

package RGBDialog;
use strict;
use warnings;
use Carp;
use Gtk2;
use Glib qw(TRUE FALSE);

use base 'Gtk2::Dialog';
 
sub new {
        my $class = shift;
        # create 
        my $self = Gtk2::Dialog->new;
        bless $self, $class;

        $self->set_position('center-always'); 

    $self->{result} = 42;
    
    $self->{button0} =  $self->add_button ("Ok" => $self->{result});
    my $button1 = $self->add_button ("Reset" => 2);
    my $button2 = $self->add_button ("Cancel" => 3);

  $self->signal_connect (response => \&do_response );
# $self->signal_connect (response => sub { $_[0]->destroy });

return $self;
}

sub get_vals{
     my $self = shift;
         $self->show();
     return $self->{result};
 
#     $self->destroy;
# return 0;
 }


sub do_response {
  my ($self, $resp) = @_;
  print "response $resp\n";
   
   $self->{result} = 43;
 
 #  is there something here that could change the return value?  
 #  $self->{button0}->set("Ok" => $self->{result});
 #  Gtk2->main_iteration while Gtk2->events_pending;
   
   return $self->{result};
}

1;

package main;

my $window = Gtk2::Window->new;
my $button = Gtk2::Button->new ("Click me");
$button->signal_connect (clicked => \&do_stuff);
$window->set_border_width (25);
$window->add ($button);
$window->show_all;
$window->signal_connect (destroy => sub { Gtk2->main_quit });
Gtk2->main;

sub do_stuff{
   my $dialog = RGBDialog->new;

   my $response = $dialog->run;

   print 'returned ',$response,"\n";
}

__END__

Thanks,
zentara

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/CandyGram_for_Mongo.html 



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