Christoph
use warnings;
use strict;
use Tk;
package Tk::Toplevel;
my $logo = <<'logo_end';
/* XPM */
static char * logo_xpm[] = {
"32 32 5 1",
" c None",
". c #FD000A",
"+ c #FD6463",
"@ c #FEBEBE",
"# c #FEFFFC",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"########........##.....@########",
"#########@....+####@.###########",
"##########+....@###.@###########",
"###########.....##++############",
"###########@....+@.#############",
"############+.....@#############",
"#############.....##############",
"#############@....@#############",
"#############@.....#############",
"#############.+....+############",
"############++#+....@###########",
"###########@.###.....###########",
"###########.@###@....+##########",
"##########++#####+....@#########",
"########+....###........########",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################",
"################################"};
logo_end
;
my $icon;
sub InitObject
{
my ($self,$args) = @_;
$self->SUPER::InitObject($args);
$icon = $self->Pixmap(-data=>$logo)unless $icon;
$self->after(0,sub{$self->iconimage($icon)});
}
package main;
my $mw = MainWindow->new;
my $tp = $mw->Toplevel();
MainLoop;
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
> Hi,
> in search of a possibility to specify an iconimage that would be used
> by all Toplevels of an application, I ended up with code like below.
> Is there a built in solution I overlooked?
I don't think so.
> If not, wouldn't it be nice
> to have a configure option for MainWindow, allowing to specify an
> iconfile/icondata to be used by all Toplevels 'below' that
> MainWindow?
Yes, I think this is worth to take into consideration. It's now on the Tk
TODO list.
Regards,
Slaven
--
Slaven Rezic - slaven <at> rezic <dot> de
babybike - routeplanner for cyclists in Berlin
handheld (e.g. Compaq iPAQ with Linux) version of bbbike
http://bbbike.sourceforge.net
use warnings;
use strict;
use Tk;
package Tk::Toplevel;
sub InitObject{
my ($self,$args) = @_;
$self->SUPER::InitObject($args);
my $mw = $self;
while ($mw->parent){$mw = $mw->parent}
if ($mw->cget('-appicon')){
$self->afterIdle(sub{$self->iconimage($mw->cget('-appicon'))}) ;
}
}
package MainWindow;
sub Populate{
my ($self,$args) = @_;
$self->SUPER::Populate($args);
$self->ConfigSpecs(-appicondata => ['METHOD'],
-appiconfile => ['METHOD'],
-appicon => ['PASSIVE']
);
$self->configure(%$args);
}
sub appicondata{
my $self = shift;
$self->configure(-appicon => $self->Pixmap(-data=>$_[0]));
}
sub appiconfile{
my $self = shift;
$self->configure('-appicon' => $self->Pixmap(-file=>$_[0]));
}
package main;
#my $mw = MainWindow->new(-appiconfile => 'logo.xpm');
my $mw = MainWindow->new(-appicondata => $logo);
$mw->Toplevel();
This is a great idea...
..as long as we are able to override the Toplevel icon to separate images if
desired :-)
Jack