Is it possible to define this sub Start_Click in package Test and get it
working so that the entire GUI code is hidden from package main?
Yes, by using NEM.
I did a search of the archives and i found something called NEM at
http://sourceforge.net/mailarchive/message.php?msg_id=11271102 and at
http://sourceforge.net/mailarchive/message.php?msg_id=12559985.
Is there some documentation or a working example of using the NEM?
If you are using the latest version of Win32-GUI you should find some
examples in the samples folder (if not, you could browse the CVS samples
folder on sourceforge).
NEM (New Event Model) should really be used over the OEM (Old Event Model).
The OEM initially looks simpler, because of it's VB style semantics, but it
is slower and less flexible than NEM. Both models can be used together.
The difference between the two event modules is quite subtle. The NEM needs
a sub reference of a function that will be run when the event is fired,
while OEM will look for the function in the main name space.
There are two main ways to associate a sub ref to an event, when
window/control is created, or dynamically as the programme is running.
When the control is created, you add an event handler prefixed with 'on':
-onClick => sub {print 'clicked';},
a complete example for a treeview control would look like:
$win->AddTreeView(
-width => 217,
-name => 'TV',
-tabstop => 1,
-left => 0,
-visible => 1,
-checkboxes => 0,
-buttons => 1,
-top => 0,
-lines => 1,
-showselalways => 1,
-height => 457,
-hottrack => 0,
-rootlines => 1,
-editlabels => 1,
-onBeginLabelEdit => \&TV_BeginLabelEdit,
-onEndLabelEdit => \&TV_EndLabelEdit,
-onExpand => \&TV_Expand,
-onCollapse => \&TV_Collapse,
-onNodeClick => \&TV_NodeClick,
-onRightClick => \&TV_RightClick,
-onKeyDown => \&TV_KeyDown,
);
To add (or change) an event handler at runtime you can use the SetEvent
method of the control:
$win->myButton->SetEvent('Click',sub {print 'Clicked';});
Back to your example:
$self->{'CNF'}->{'Window'}->AddButton( -name => "Start",
-align => "center",
-height => 30,
-width => 60,
-text => "Start",
-top => 510,
-left => 360,
-tabstop => 1,
-onClick => \&StartClick,
);
and add this sub to your Test package:
sub StartClick {
#first parm in NEM is always the control
my $self=shift;
print "$self has been clicked!\n";
}
Hope that is of some help.
Cheers,
jez.