[Gtk-sharp-list] Problem loading icons: is this a bug?

Raúl Moratalla raul.moratalla@ono.com
Sat, 17 Jul 2004 02:21:30 +0200


Fredrik Nilsson escribió:

>On fre, 2004-07-16 at 20:42 +0200, Raúl Moratalla wrote:
>  
>
>>Hi!
>>
>>I use glade for edit the interface of my application and I add to a form 
>>or to a button an icon: When I execute the application I get the 
>>following error and it crashes:
>>(<unknown>:31877): GLib-CRITICAL **: file gutils.c: line 577 
>>(g_path_get_dirname): assertion `file_name != NULL' failed
>>
>>(<unknown>:31877): GdkPixbuf-CRITICAL **: file gdk-pixbuf-io.c: line 761 
>>(gdk_pixbuf_new_from_file): assertion `filename != NULL' failed
>>
>>Unhandled Exception: System.NullReferenceException: Object reference not 
>>set to an instance of an object
>>in (unmanaged) (wrapper managed-to-native) 
>>Glade.XML:glade_xml_new_from_buffer (byte[],int,string,string)
>>in <0x00004> (wrapper managed-to-native) 
>>Glade.XML:glade_xml_new_from_buffer (byte[],int,string,string)
>>in <0x00133> Glade.XML:.ctor 
>>(System.Reflection.Assembly,string,string,string)
>>in [0x00017] (at /home/raul/MonoDevelopProjects/glade1/Main.cs:21) 
>>GladeApp:.ctor (string[])
>>in [0x00001] (at /home/raul/MonoDevelopProjects/glade1/Main.cs:11) 
>>GladeApp:Main (string[])
>>
>>
>>press any key to continue...
>>
>>It seems that can't load the icon. I looked into the xml file and I can 
>>see the following line:
>>  <property name="icon">App.png</property>
>>
>>I changed it with the complete path to the image and the application now 
>>loads and shows the icon, but if I want to distribute the source code 
>>this is a problem. Is this a bug or am I doing something wrong?
>>I tried to load and assign the icons to my window or my buttons using 
>>code but I am a bit confused and I don't know how to do it :( (I think 
>>that I should use Gdk.Pixbuf) Anyone could explain to me how to do it? I 
>>would to knowt if the application crashes if I assign the icon by code.
>>
>>Best regards,
>>
>>Raúl
>>    
>>
>
>Hi Raúl!
>
>Guess who... yes, it's me again! ;)
>
>I'm not an expert on this, but this is one way to do it...
>Don't set the icons in glade, instead do it in the program.
>
>In Monodevelop, add the icons to 'Resource Files', and it will be
>embedded in the exe.
>
>For the window, use this:
>window1.Icon = new Gdk.Pixbuf (null, "icon-file-name.png");
>
>For the button you can do this:
>In glade, set a random Icon from the defaults (e.g. Cancel), click on
>the Icon in the button and notice it's name (or change it to what you
>want), e.g. image1.
>In the program, use this code:
>image1.Pixbuf = new Gdk.Pixbuf (null, "other-icon-file-name.png");
>
>Of course you need to 'auto-define' window1 and image1 with the usual:
>[Widget] Gtk.Window window1;
>[Widget] Gtk.Image image1;
>But that you propably already know...
>
>
>Now I have to go and paint a roof :)
>
>Good luck,
>
>/Fredrik
>
>_______________________________________________
>Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>
>  
>
Thanks Fredrik, I coded something like this:

Gdk.Pixbuf test = new Gdk.Pixbuf ("App.ico");
 window1.Icon=test;

but this didn't work. I read the documentation but I should be sleeping 
because I didn't try to call the constructor with those parameters ;)
Now it works without any problem, and I will not use glade for assign 
the icons :)

Thanks again for all your useful information, you're helping me a lot to 
learn and improve my (little) knowledge of C#/MONO/GTK.

Regards,

Raúl