Making a subclass help

  I'm pretty new to gtk-perl, I've only been using it for the past few 
days. I've been trying to make a subclass consisting of a button with an 
image in it and an extra variable. So far I've been able to put most of 
this together, using some gtk2-perl tutorials as a base, but the one thing 
that has me stumped is getting the image to be updated. The following is 
what I have so far :


#!/usr/bin/perl -w

use strict;

package Mup::IButton;

use Gtk2;

#define a button with an index and an embedded image
use Glib::Object::Subclass
    signals => {
        show => \&on_show,
    properties => [
        Glib::ParamSpec->int (
                'index', # name
                'Index', # nickname
                'The index number of the button', #blurb
                0, # min
                32767, # max
                undef, # default
                [qw/readable writable/] #flags
        Glib::ParamSpec->string (
            'The image file to load into the button',
            [qw/readable writable/]
        my $self = shift;
        $self->{index} = undef;
        $self->{image} = "blank.png";
        my $image = Gtk2::Image->new_from_file($self->{image});

sub on_show {
        my $self = shift;
        $self->set_image (image => $self->{image});

sub set_index{
    my $self = shift;
    my %params = @_;
    $self->{index} = $params{index};

sub get_index{
    my $self = shift;
    return $self->{index};

sub set_image{
    my $self = shift;
    my %params = @_;
    if (-e $params{image}){
        $self->{image} = $params{image};

sub get_image{
    my $self = shift;
    return $self->{image};


As I said above this mostly works in that, when used, a button is created 
with an image in it. However when I use the set_image method that I 
defined to say change the image to "ball.png" the image variable in 
updated but I'm not sure how to then update the actual image based on 

I've been looking about for a way to do this. I've seen EventBox mentioned 
a few times but from what I've read the EventBox has to be inside the 
object that I want to affect, not something that I can do with an Image.


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