[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Mac::Dialogs questions



Alan Fry writes:
|I find Chris's method [END block] works but Brian's [DESTROY method]
|doesn't.
|Does anyone disagree?

Yes. :-)

I used the little progress dialog example Alan posted a week or so ago
and added a DESTROY function:

#!perl

# Save this as SimpleStatus.pm and place in a folder
# named 'Mac' in the site-library path.

package Mac::SimpleStatus;

use Mac::Dialogs;

sub new {
    my $pkg = shift;
    my $item = [ 8, new Rect ( 5, 0, 245, 15 ), ''];
    my $bnd = new Rect 14, 24, 264, 39;
    my $dlg = new MacDialog $bnd, '', 1, 1993, 0, ($item);
    my $ref = {};
    $ref->{dlg} = $dlg;
    bless $ref, $pkg
}

sub data {
    my($me, $data) = @_;
    my $dlg = $me->{dlg};
    SetDialogItemText($dlg->window, 1, $data);
}

sub close {
    my $me = shift;
    my $dlg = $me->{dlg};
    dispose $dlg
}

sub DESTROY {
	$_[0]->close;
}

1;

#!perl

# Save this file as 'run_SimpleStatus' and put it any
# convenient place.
# NB there MUST be a close() command somewhere in the
# calling script or the window will get stuck open.

use Mac::SimpleStatus;

$str = 'This window will close in 5 seconds';
$dlg = Mac::SimpleStatus->new();
$dlg->data($str);
sleep(5);
$dlg->close;

If I run this and hit command-period while it's sleeping, the window
goes away. If I remove the sub DESTROY (or just rename it) and hit
command-period, the window sticks around as Alan's comments indicate.
I can also add an END block and it works as well.

Alan, do you have a short example where a DESTROY method doesn't work?
I'd be interested in seeing it.

Brian

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch