Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Set Icon

by PilotinControl (Pilgrim)
on Dec 22, 2020 at 17:54 UTC ( [id://11125620]=perlquestion: print w/replies, xml ) Need Help??

PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks!
I am having issues with setting an Icon on the console window using Perl Tk and Win32 console apps. The code posted below worked in windows xp/vista/7/8 and not in 10.
Perl Tk code below:

my $image=$mw->Photo(-file=> "logo.gif"); $mw->idletasks; $mw->Icon(-image => $image);
Win32 Console code below:
sub icon { my $sIcon = Win32::Console::SetIcon("logo.gif"); }
Thanks in advance!

Replies are listed 'Best First'.
Re: Set Icon
by kcott (Archbishop) on Dec 22, 2020 at 19:39 UTC

    G'day PilotinControl,

    If you're interested in icons that are a little fancier that solid squares, check out "Perl/Tk Transparent Icons".

    The page itself is rather old; it was last updated in 2007. I only found it a month or two ago when I was trying to create a hexagonal icon. The Perl code, as far as I remember, was all valid and I didn't need to change or fix anything. Some of the Gimp instructions were a little dated; however, it was easy enough to adjust the 2007 instructions for my 2019 Gimp version.

    I've never used any modules in the Win32:: namespace — I can't offer any help with that part of your question.

    — Ken

Re: Set Icon
by Bod (Parson) on Dec 22, 2020 at 18:28 UTC

    In a couple of Tk apps running on Windows 10 I have this....

    use Tk; use Tk::PNG; my $tk_win = new MainWindow; my $icon = $tk_win->Photo(-width => 32, -height => 32, -file => 'files +/icon.gif'); $tk_win->iconimage($icon);

      Thanks BOD! That worked perfectly for the TK app. Would this work for the Win32::Console app too?

        Hello PilotinControl

        I have been playing with Tk a little bit recently, but the question of whether Win32::Console does, in terms of icons, what Tk does seems a little off the mark.

        Tk and Console are two different applications. When you ask does this work with Console in the same way, I think you need to explain in a little more detail what it is that you are trying to do that should be the same for both Tk and Console.

        Win32::Console provides an api for interacting with the console, whereas Icons are usally an aspect of the window manager. In Tk terms you could think of Console as a special type of interactive Text widget, housed within a Top-Level frame.

        It doesnt really make sense to output an icon to a Text widget, although not saying that cannot be done, however consider the prevalance of ascii art on consoles. The smallest units of the console screen or output buffer is the character/font. Whereas the window manager needs to place an icon within say a top-level window bar, or for example on the desktop screen if the app is minimized.

        For Win32::Console to do something like this you might have to look for a related namespace that interacts with the window-manager of the console, rather than the console itself. Are you trying to create a new application or a new shell?

        I would suggest to continue hacking on Tk. And to gain better insight to differences of the screen and the widget also revisit the geometry managers, as well as the seemingly innocuous entry and scrollbar widgets. Understanding these widgets properly, as well as how the Top-Level windows interact may help towards understanding issues around when and where icon images can be used.

        If you have a bit of time of the holidays, maybe try using different geometry managers to position the widgets within different top-level windows. This is actually a very insightful practice.

        Of course, if I have missed the point of what it is you are trying to do, please do re-iterate in a little more detail what it is you are trying to achieve with Win32::Console that you are achieving with Tk::*

        hope this helps

Re: Set Icon
by Discipulus (Canon) on Dec 22, 2020 at 18:53 UTC
    Hello PilotinControl,

    ..and I have this working on Win10 using Pixmap:

    my $mw = MainWindow->new (); $mw->Icon(-image => $mw->Pixmap(-data => &tart_icon)); # ... sub tart_icon { return <<EOI /* XPM */ static char * Icon_xpm[] = { "32 32 4 1", " c #000000000000", "g c #00FF00", "X c #FF0000", "D c #FFFF00", " ", " ", # ...

    See the sub returning the icon

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Set Icon
by Bod (Parson) on Dec 23, 2020 at 23:19 UTC
    Win32 Console code below:
    sub icon { my $sIcon = Win32::Console::SetIcon("logo.gif"); }
    Thanks in advance!

    According to the Win32::Console documentation, a *.ico file is required not a *.gif file and the syntax is:

    $CONSOLE->SetIcon("C:/My/Path/To/Custom.ico");
    so I would try something like....
    my $CONSOLE = Win32::Console->new; $CONSOLE->SetIcon('C:/myIcon.ico');
    or...
    Win32::Console->SetIcon('C:/myIcon.ico');
    These are untested but might provide you with some some progress!

      Confirmation: start perl -MWin32::Console -e "my $C=Win32::Console->new(); $C->SetIcon('pp.ico'); $C->Title('Hello World'); sleep 10" worked for me. However, if I tried to run that without the start, the title would change but the icon would not. But that experiment also showed that the icon file can be relative (mine was in the current directory) rather than having to specify the whole path.

        Thanks pryrt - I couldn't carry out that test as the laptop I am currently using doesn't have Perl installed

        Perhaps start was needed just to allow a relative directory for the icon file.

        I can confirm with pryrt that the test above worked just as he described it would.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11125620]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (8)
As of 2024-04-19 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found