[gtkada] Changing a pixmap

Preben Randhol randhol at pvv.org
Thu Mar 27 13:38:23 CET 2003


Jean-Pierre Rosen <rosen at adalog.fr> wrote on 27/03/2003 (13:26) :
> > 
> The pixmap is in a Packer (and was generated from Glade).  Part of the
> trouble is that Gtk.Pixmap is not documented in the (otherwise
> excellent) reference manual.  How to use set is not obvious...  It
> refers to Gdk.Pixmaps, so you have to create a Gdk.pixmaps from file
> first.  But then, you must pass it a window. Which one? etc. I
> certainly can sort it out by trial and error, but it looks awfully
> complicated for my need, which is:
> 
> "I have a picture of a red button and a picture of a green button in
> XPM format. I want to display sometimes red, sometimes green".

  Say you have this pixmap in a Vbox, then you will have to remove the
  old pixmap and then pack the new pixmap into it.

      Pack_Start (Status_Vbox, Green_Pixmap, True, True, 0);
   
   now you want to put in the Red_Pixmap:

      Remove (Status_Vbox, Get_Child (Status_Vbox, 0));
      Pack_Start (Status_Vbox, Red_Pixmap, True, True, 0);
      Show_All (Status_Vbox);

   And you do the same when you want it Green again.
   However note that when you make the Red_Pixmap and Green_Pixmap
   either from file or data, that you call Ref (Green_Pixmap) and ditto
   for the red. Otherwise they will be destroyed when you remove them
   from the parent.

-- 
Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
                 «For me, Ada95 puts back the joy in programming.»



More information about the gtkada mailing list