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

global iconimage

5 views
Skip to first unread message

Ch Lamprecht

unread,
Feb 17, 2007, 5:48:55 PM2/17/07
to
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? 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?

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

Slaven Rezic

unread,
Feb 19, 2007, 5:43:56 PM2/19/07
to
Ch Lamprecht <ch.l...@online.de> writes:

> 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

Ch Lamprecht

unread,
Feb 19, 2007, 5:48:03 PM2/19/07
to
Slaven Rezic wrote:
> Ch Lamprecht <ch.l...@online.de> writes:
>
>
>>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
>
Here is a first shot (I know it needs to be more general):


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();

Jack

unread,
Feb 20, 2007, 11:38:41 PM2/20/07
to

"Slaven Rezic" <sla...@rezic.de> wrote in message
news:87tzxh9...@biokovo.herceg.de...

> Ch Lamprecht <ch.l...@online.de> writes:
>
>> 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.

This is a great idea...
..as long as we are able to override the Toplevel icon to separate images if
desired :-)


Jack


0 new messages