RE: setting icon for TGMainFrame

From: Valeri Onuchin <Valeri.Onoutchine_at_cern.ch>
Date: Mon, 10 Sep 2007 20:06:18 +0200


Hi Tom,

  1. try to use TString for cases "// snprintf() not available"
  2. in SetIconPixmap("historooticon.png") you must specify full path name to the icon file. i.e.
    /home/tjrob/root/icons/historooticon.png

Another possibility one can embed an icon into application, the code is below. We can provide a helper method for this.

Regards. Valeriy

// in fact, an XPM file can be included as
// #include "bld_rgb.xpm"

/* XPM */

char *bld_rgb[] = {
/* width height num_colors chars_per_pixel */
" 32 32 3 1",
/* colors */

". c #008000",
"# c #ff0000",
"a c #0000ff",

/* pixels */
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"##########...........aaaaaaaaaaa",
"#########............aaaaaaaaaaa"

};

TGMainFrame *window = new TGMainFrame(gClient->GetRoot(),200,200); TImage *img = TImage::Create();
img->SetImageBuffer(bld_rgb, TImage::kXpm); gVirtualX->SetIconPixmap(window->GetId(), img->GetPixmap()); delete img;
window->MapRaised();

-----Original Message-----
From: owner-roottalk_at_root.cern.ch on behalf of Tom Roberts Sent: Mon 9/10/2007 7:24 PM
To: 'ROOT Talk'
Subject: Re: [ROOT] setting icon for TGMainFrame  

This is driving me crazy! Here's my code (inside a large macro):

         // set Gui.IconPath
         char tmp[1024];
         sprintf(tmp,"%s:%s",getenv("HOME"),
				gEnv->GetValue("Gui.IconPath","."));
         assert(strlen(tmp)<sizeof(tmp)); // snprintf() not available
         gEnv->SetValue("Gui.IconPath",tmp);
printf("Gui.IconPath='%s'\n",gEnv->GetValue("Gui.IconPath","."));
         window = new TGMainFrame(gClient->GetRoot(),200,200,
				kVerticalFrame);
         window->SetIconPixmap("historooticon.png");


Here's the output on Linux:

Gui.IconPath='/home/tjrob:/home/tjrob/icons:/home/tjrob/root/icons:.' root [1] .!ls -l /home/tjrob/historooticon.png -rw-r--r-- 1 tjrob tjrob 591 Sep 10 11:56 /home/tjrob/historooticon.png

That output looks fine, BUT I GET THE WRONG ICON (the default X-windows "X").

If I copy historooticon.png to either /home/tjrob/root/icons or "." then I get the correct icon.

What is going on? Why doesn't it use the updated Gui.IconPath?

Tom Roberts

Ilka Antcheva wrote:

> Hi Tom,
> 
> Define for your class const TGPicture *fIconPic;
> In your class constructor use:
> fIconPic = SetIconPixmap("your_icon.png");
> In your class destructor (to avoid memory leak):
> if (fIconPic) gClient->FreePicture(fIconPic);
> 
> If you need to specify in addition the special path to the icon 
> directory, you may have a look at 
> http://root.cern.ch/phpBB2/viewtopic.php?t=5390
> 
> Cheers, Ilka
> 
> Tom Roberts wrote:
>> My Root application is implemented as a TGMainFrame. How can I set the 
>> icon for this window? The documentation is obscure ("... this is 
>> typically done via the window manager", but no hint how to do that).
>>
>> I need to handle Windows, Linux, and Mac OS X, and have versions of my 
>> icon in .ico, .png, and .icns formats.
>>
>>
>> Tom Roberts
>>
Received on Mon Sep 10 2007 - 20:06:35 CEST

This archive was generated by hypermail 2.2.0 : Tue Sep 11 2007 - 05:50:01 CEST