For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > November 2004 > Re: Tk:ErrorDialog problem.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Tk:ErrorDialog problem.
Steve Lidie

2004-11-11, 3:57 pm


--Apple-Mail-2--520947612
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed


On Nov 11, 2004, at 11:09 AM, Beckett Richard-qswi266 wrote:

> Hi Steve!
>
> Are you still The Man (TM) for Tk::ErrorDialog? If not do you know who
> I should send this to?
>
> I am having a bit of a problem with it, but whatever it is, it's
> beyond me.
>
> I've attached the ErrorDialog.pm from my machine, with my 2 additional
> print statements. When I run this:
>
> use strict;
> use warnings;
> use Tk;
> use Tk::ErrorDialog;
> my $mw = new MainWindow();
> $mw->Button(-text => 'Go', -command => \&go)->pack;
> MainLoop;
> sub go {
> die "screaming";
> }
>
> I get the first of my print statements, the bell sound, but now error
> window, and no second print sttement. It looks like the problem lies
> with:
> my $ans = $d->Show;
>
> I also get the following errors in the console window after pressing
> 'go' then exiting the above script:
> D:\>error.pl
> Should show any moment!
> Background Error: window ".errordialog.dialog" was deleted before its
> visibility changed at C:/Perl/site/lib/Tk/Widget.p
> m line 926.
>
> I am running:
> ActiveState perl V5.8.4 build 810
> Tk [804.027] Tk - a Graphical User Interface Toolkit
>
> Thanks.
>
> R.
>
> <ErrorDialog.pm>


Hi Richard - I tried your program and it works perfectly for me, but
I'm running on Unix (Mac OS X), so that is likely the difference. Nor
do I have a Win32 machine available..... but, there are a lot of folks
on the mailing list (CCed), hopefully they can help out ...



--Apple-Mail-2--520947612
Content-Transfer-Encoding: quoted-printable
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="ErrorDialog.pm"
Content-Disposition: attachment;
filename=ErrorDialog.pm

package=20Tk::ErrorDialog;

use=20vars=20qw($VERSION);
$VERSION=20=3D=20sprintf=20'4. %03d',=20q$Revision:=20#7=20$=20=3D~=20=

/\D(\d+)\s*$/;

use=20Tk=20();
require=20Tk::Dialog;
use=20base=20qw(Tk::Toplevel);


#=20ErrorDialog=20- =20a=20translation=20of=20bgerror()=20fr
om=20Tcl/Tk=20=
to=20Perl/Tk.
#
#=20Currently=20TkPerl=20background=20er
rors=20are=20sent=20to=20=
stdout/stderr;=20use=20this
#=20module=20if=20you=20want=20them=20in
=20a=20window.=20=20You=20can=20=
also=20"roll=20your=20own"=20by
#=20supplying=20the=20routine=20Tk::Erro
r.

use=20strict;

Construct=20Tk::Widget=20'ErrorDialog';

my=20%options=20=3D=20(=20-buttons=20=3D>=20['OK',=20'Skip=20Messages',=20=
'Stack=20trace'],
=20=20=20=20=20=20=20=20=20=20=20=20=20=
20=20=20-bitmap=20=20=3D>=20=
'error'
=20=20=20=20=20=20=20=20=20=20=20=20=20=
20);
my=20$ED_OBJECT;

sub=20import
{
=20my=20$class=20=3D=20shift;
=20while=20(@_)
=20=20{
=20=20=20my=20$key=20=3D=20shift;
=20=20=20my=20$val=20=3D=20shift;
=20=20=20$options{$key}=20=3D=20$val;
=20=20}
}

sub=20Populate=20{

=20=20=20=20#=20ErrorDialog=20constructo
r.=20=20Uses=20`new'=20method=20=
from=20base=20class
=20=20=20=20#=20to=20create=20object=20c
ontainer=20then=20creates=20the=20=
dialog=20toplevel=20and=20the
=20=20=20=20#=20traceback=20toplevel.

=20=20=20=20my($cw,=20$args)=20=3D=20@_;


=20=20=20=20my=20$dr=20=3D=20$cw->Dialog(
=20=20=20=20=20=20=20=20-title=20=20=20=20=20=20=20=20=20=20=3D>=20=
'Error=20in=20'.$cw->MainWindow->name,
=20=20=20=20=20=20=20=20- text=20=20=20=20=20=20=20=20=20=20=20=3D
>=20=
'on-the-fly-text',
=20=20=20=20=20=20=20=20-bitmap=20=20=20=20=20=20=20=20=20=3D>=20=
$options{'-bitmap'},
=09-buttons=20=20=20=20=20=20=20=20=3D>=20$options{'-buttons'},
=20=20=20=20);
=20=20=20=20$cw->minsize(1,=201);
=20=20=20=20$cw->title('Stack=20Trace=20for=20Error');
=20=20=20=20$cw->iconname('Stack=20Trace');
=20=20=20=20my=20$t_ok=20=3D=20$cw->Button(
=20=20=20=20=20=20=20=20-text=20=20=20=20=3D>=20'OK',
=20=20=20=20=20=20=20=20-command=20=3D>=20[
=20=20=20=20=20=20=20=20=20=20=20=20sub=
20{
=09=09shift->withdraw;
=09=20=20=20=20},=20$cw,
=20=20=20=20=20=20=20=20]
=20=20=20=20);
=20=20=20=20my=20$t_text=20=3D=20$cw->Text(
=20=20=20=20=20=20=20=20-relief=20=20=3D>=20'sunken',
=20=20=20=20=20=20=20=20-bd=20=20=20=20=20=20=3D>=202,
=20=20=20=20=20=20=20=20-setgrid=20=3D>=20'true',
=20=20=20=20=20=20=20=20-width=20=20=20=3D>=2060,
=20=20=20=20=20=20=20=20-height=20=20=3D>=2020,
=20=20=20=20);
=20=20=20=20my=20$t_scroll=20=3D=20$cw->Scrollbar(
=20=20=20=20=20=20=20=20-relief=20=3D>=20'sunken',
=20=20=20=20=20=20=20=20-command=20=3D>=20['yview',=20$t_text],
=20=20=20=20);
=20=20=20=20$t_text->configure(-yscrollcommand=20=3D>=20['set',=20=
$t_scroll]);
=20=20=20=20$t_ok->pack(-side=20=3D>=20'bottom',=20-padx=20=3D>=20'3m',=20=
-pady=20=3D>=20'2m');
=20=20=20=20$t_scroll->pack(-side=20=3D>=20'right',=20-fill=20=3D>=20=
'y');
=20=20=20=20$t_text->pack(-side=20=3D>=20'left',=20-expand=20=3D>=20=
'yes',=20-fill=20=3D>=20'both');
=20=20=20=20$cw->withdraw;

=20=20=20=20$cw->Advertise(error_dialog=20=3D>=20$dr);=20#=20advertise=20=
dialog=20widget
=20=20=20=20$cw->Advertise(text=20=3D>=20$t_text);=20=20=20=20=20#=20=
advertise=20text=20widget
=20=20=20=20$cw->ConfigSpecs(-cleanupcode=20=3D>=20[PASSIVE=20=3D>=20=
undef,=20undef,=20undef],
=20=20=20=20=20=20=20=20=20=20=20=20=20=
20=20=20=20=20=20=20=20=
-appendtraceback=20=3D>=20[=20PASSIVE=20=3D>=20undef,=20undef,=201=20]);
=20=20=20=20$ED_OBJECT=20=3D=20$cw;
=20=20=20=20$cw->protocol('WM_DELETE_WINDOW'=20=3D>=20sub=20=
{$cw->withdraw});
=20=20=20=20return=20$cw;

}=20#=20end=20Populate

sub=20Tk::Error=20{

=20=20=20=20#=20Post=20a=20dialog=20box=
20with=20the=20error=20message=20=
and=20give=20the=20user=20a=20chance
=20=20=20=20#=20to=20see=20a=20more=20de
tailed=20stack=20trace.

=20=20=20=20my($w,=20$error,=20@msgs)=20
=3D=20@_;

=20=20=20=20my=20$grab=20=3D=20$w->grab('current');
=20=20=20=20$grab->Unbusy=20if=20(defined=20$grab);

=20=20=20=20$w-> ErrorDialog=20if=20not=20defined=20$ED_O
BJECT;

=20=20=20=20my($d,=20$t)=20=3D=20($ED_OB
JECT->Subwidget('error_dialog'),=20=
$ED_OBJECT->Subwidget('text'));
#=20=20=20chop=20$error;
=20=20=20=20$d->configure(-text=20=3D>=20"Error:=20=20$error");
=20=20=20=20$d->bell;
print=20"Should=20show=20any=20moment!\n";
=20=20=20=20my=20$ans=20=3D=20$d->Show;
print=20"Should=20be=20there=20now!\n";

=20=20=20=20$t->delete('0.0',=20'end')=20if=20not=20=
$ED_OBJECT->{'-appendtraceback'};
=20=20=20=20$t->insert('end',=20"\n");
=20=20=20=20$t->mark('set',=20'ltb',=20'end');
=20=20=20=20$t->insert('end',=20"---=20Begin=20Traceback=20=
---\n$error\n");
=20=20=20=20my=20$msg;
=20=20=20=20for=20$msg=20(@msgs)=20{
=09$t->insert('end',=20"$msg\n");
=20=20=20=20}
=20=20=20=20$t->yview('ltb');

=20=20=20=20$ED_OBJECT->deiconify=20if=20($ans=20=3D~=20/trace/i);

=20=20=20=20my=20$c=20=3D=20$ED_OBJECT->{Configure}{'-cleanupcode'};
=20=20=20=20& $c=20if=20defined=20$c;=09=09#=20execute
=20any=20cleanup=20=
code=20if=20it=20was=20defined
=20=20=20=20$w->break=20if=20($ans=20=3D~=20/skip/i);

}=20#=20end=20Tk::Error

1;

--Apple-Mail-2--520947612
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed




--Apple-Mail-2--520947612--

-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com