Re: OOP Help, Accessing variable from within same class.



This is more basic perl than Gtk related, but I assume you use this class like:

my $dlg = ClassificationDialog->new;
$dlg->show;

If that's the case, at the start of the show function add:

my $self = shift;

and then access the title with:

$title = $self->{TITLE};

Object oriented perl stuff can be found in the perlobj, perlboot,
perltoot, perltooc, and perlbot sections of the perldoc.

MB

2009/12/30 Zettai Muri <zettaimuri ymail com>:
Hi All,

I am displaying a screen/dialog when a menu item is clicked.

When the menu item is clicked the following code is executed:
sub on_setup_sources_activate
{
   my $model = ClassnModel::create_source_model;
   my $classfn_dialog = ClassificationDialog->new
                       (
                           "MODEL" => $model,
                           "TITLE" => "Source Maintenance"
                       );

   $classfn_dialog->show;

}

The package for the class appears as:
---------------- START OF PACKAGE --------------------
package ClassificationDialog;

my $dialog_builder = Gtk2::Builder->new;

sub new
{

   my($class) = shift;
   my(%params) = @_;

   bless
   {

       "MODEL" => $params{"MODEL"},
       "TITLE" => $params{"TITLE"}


   }, $class;

}

sub show
{

   $dialog_builder->add_from_file ("../../gui/DialogClassificationSetup.ui");

   # Get dialog from widget tree.
   my $dialog = $dialog_builder->get_object('dialog_classfn_setup');

   # Set title Works:
   #$dialog->set_title("Here is the title");
   $dialog->set_title(&get_title);

   TreeViewModel::setup_source_treeview($tv_classfns);
   $tv_classfns->set_model(&get_model);

   # Display dialog
   $dialog->show_all;

}

...

sub get_title
{
   my ($self) = @_;
   return $self->{"TITLE"};
}

---------------- END OF PACKAGE --------------------

I am using get_title as a bit of a hack at the moment because it worked in another class to get some member 
values.  However, would someone be able to to tell me how to directly access the TITLE value after the 
object has been created and this value initialised?

I was hoping to set the title with something similar to:
$dialog->set_title($class{'TITLE'});
$dialog->set_title($params{'TITLE'});

But this doesn't work as I don't really understand the syntax correctly or how to access the TITLE value.

Hope everyone had a great Xmas and is all set for the New Year celebrations.

Many thanks,

ZM.


     __________________________________________________________________________________
See what's on at the movies in your area. Find out now: http://au.movies.yahoo.com/session-times/

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




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