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;

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.


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"



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) = @_;


       "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");


   # Display dialog



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:

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,


See what's on at the movies in your area. Find out now:

gtk-perl-list mailing list
gtk-perl-list gnome org

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