Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Custom methods on Megawidgets

3 views
Skip to first unread message

Scott Parrill

unread,
Apr 8, 2013, 5:08:12 PM4/8/13
to tc...@perl.org
All,

I seem to be missing something simple here but I can't see it. I've
created a megawidget that I want to have a public method on with the
following code

CustomWidgetTest.pl
------------------------------
use Tkx;
use CustomWidget;

$mw = Tkx::widget->new(".");
$cw = $mw->new_MyCustomWidget;
$cw->m_Fred();
------------------------------


CustomWidget.pm
------------------------------
package CustomWidget;

use base qw(Tkx::widget Tkx::MegaConfig);

__PACKAGE__->_Mega("MyCustomWidget");
__PACKAGE__->_Config();

sub _Populate {
my($class, $widget, $path, %opt) = @_;

my $self = $class->new($path)->_parent->new_frame(-name => $path,
-class =>
"MyCustomWidget",
);
$self->new_ttk__entry(-name => 'e');

return $self;
}

sub _mpath {
my $self = shift;
return $self;
}

sub m_Fred {
print "FRED\n";
}

1;
------------------------------

When I try to use the m_Fred() method, $cw->m_Fred(), I get a 'bad option
"Fred": must be cget or configure' error. What else do I need to do to
register the method?

Thanks,
Scott

----------------------------------------------------------------------
Scott Parrill
Information Technology Specialist
Enterprise Technology Services /
Wyoming State Geological Survey
State of Wyoming
P.O. Box 1347
Laramie, WY 82073
Phone: 307-766-2286 x242
Fax: 307-766-2605
E-mail: Scott....@wyo.gov<https://uwmail.uwyo.edu/owa/redir.aspx?C=4dc4ce62e583463fb8ad86380018935b&URL=mailto%3aScott.Parrill%40wyo.gov>
----------------------------------------------------------------------
E-Mail to and from me, in connection with the transaction of public
business, is subject to the Wyoming Public Records Act and may be
disclosed to third parties.
----------------------------------------------------------------------


E-Mail to and from me, in connection with the transaction
of public business, is subject to the Wyoming Public Records
Act and may be disclosed to third parties.

Gisle Aas

unread,
Apr 9, 2013, 5:22:56 PM4/9/13
to Scott Parrill, tc...@perl.org
You need a call to:

$self->_class($class);

about here. This will bless self and make sure that other Tkx::widgets wrapping
this $path get blessed as well.

Regards,
Gisle
0 new messages