Re: Function to return Gtk2::Table



can you please provide your sscce.glade file?

On Fri, May 15, 2009 at 02:42:52PM +1000, Peter E Dennis wrote:
Hi All,

I am trying to create a function that when a button is clicked it will
create a table of widgets laid out in 2 rows x 9 columns and add it to
a vbox.

At the moment I am trying to do the following:

#!/usr/bin/perl
use Gtk2 -init;
use Gtk2::GladeXML;

# Read in glade file with gui
$gladexml = Gtk2::GladeXML->new('sscce.glade');

# Get main window vbox
$vbox1 = $gladexml->get_widget('vbox1');

# Get vbox to hold created tables
$vbox2 = $gladexml->get_widget('vbox2');

# Create a table of widgets
$table = &ret_table();

# Show the widgets?
$vbox2->pack_start_defaults($table); #get undefined error here...
$vbox2->show_all;
$vbox1->pack_start_defaults($vbox2);
$vbox1->show_all;

# Get main window from widget tree.
$main_window = $gladexml->get_widget('window1');

# Quit when user clicks on the close button/alt-f4 etc.
$main_window->signal_connect (destroy => sub { Gtk2->main_quit; });

# Maximise window
$main_window->maximize;

# Run main loop.
Gtk2->main;


sub ret_table
{
    my $table = Gtk2::Table->new(2,9,FALSE);

    # Title Row
    my $lbl_num = Gtk2::Label->new("Num");
    my $lbl_time = Gtk2::Label->new("Time/Session");
    my $lbl_objectives = Gtk2::Label->new("Objectives/Learning Outcomes");
    my $lbl_tasks = Gtk2::Label->new("Activities/Tasks/Content");
    my $lbl_resources = Gtk2::Label->new("Resources");

    my $tcol_sep1 = Gtk2::VSeparator->new;
    my $tcol_sep2 = Gtk2::VSeparator->new;
    my $tcol_sep3 = Gtk2::VSeparator->new;
    my $tcol_sep4 = Gtk2::VSeparator->new;

    # Entry Row
    my $chk_num = Gtk2::CheckButton->new("1.");
    my $e_time = Gtk2::Entry->new;
    my $txtv_objectives = Gtk2::TextView->new;
    my $txtv_tasks = Gtk2::TextView->new;
    my $txtv_resources = Gtk2::TextView->new;

    my $rcol_sep1 = Gtk2::VSeparator->new;
    my $rcol_sep2 = Gtk2::VSeparator->new;
    my $rcol_sep3 = Gtk2::VSeparator->new;
    my $rcol_sep4 = Gtk2::VSeparator->new;

    # Layout title row
    $table->attach_defaults($lbl_num, 0, 1, 0, 1);
    $table->attach_defaults($tcol_sep1, 1, 2, 0, 1);
    $table->attach_defaults($lbl_time, 2, 3, 0, 1);
    $table->attach_defaults($tcol_sep2, 3, 4, 0, 1);
    $table->attach_defaults($lbl_objectives, 4, 5, 0, 1);
    $table->attach_defaults($tcol_sep3, 5, 6, 0, 1);
    $table->attach_defaults($lbl_tasks, 6, 7, 0, 1);
    $table->attach_defaults($tcol_sep4, 7, 8, 0, 1);
    $table->attach_defaults($lbl_resources, 8, 9, 0, 1);

    # Layout entry row
    $table->attach_defaults($chk_num, 0, 1, 0, 1);
    $table->attach_defaults($rcol_sep1, 1, 2, 0, 1);
    $table->attach_defaults($e_time, 2, 3, 0, 1);
    $table->attach_defaults($rcol_sep2, 3, 4, 0, 1);
    $table->attach_defaults($txtv_objectives, 4, 5, 0, 1);
    $table->attach_defaults($rcol_sep3, 5, 6, 0, 1);
    $table->attach_defaults($txtv_tasks, 6, 7, 0, 1);
    $table->attach_defaults($rcol_sep4, 7, 8, 0, 1);
    $table->attach_defaults($txtv_resources, 8, 9, 0, 1);

    return $table;
}

However at the moment I get the following error:
Can't call method "pack_start_defaults" on an undefined value at
./main.pl line 18.

This is the line:
$vbox2->pack_start_defaults($table); # get undefined error here.

Is the table not being defined or is it the vbox?

Am I going the right way about this?

Many thanks,

Peter.
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

-- 
_________________________
Ryan Niebur
ryanryan52 gmail com

Attachment: signature.asc
Description: Digital signature



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