This is not strictly a NIM question - but it is in service to an attempt to write a semi-cross-platform nim gui library. The question concerns gtk2
There is a need to load a pixbuf from a stock image - such as gtk-dialog-error.
There seems to be no pixbuf_new_from_stock function.
The following attempted work-around:
var stockid = "gtk-dialog-error"
echo "stockid=",stockid
var img = image_new_from_stock(stockid,32)
echo "img=",cast[int](img).toHex(8)
var pixbuf = get_pixbuf(img)
echo "pixbuf=",cast[int](pixbuf).toHex(8)
produced this console output:
stockid=gtk-dialog-error
img=0858CC20
(test25:5319): Gtk-CRITICAL **: IA__gtk_image_get_pixbuf: assertion 'image->storage_type == GTK_IMAGE_PIXBUF || image->storage_type == GTK_IMAGE_EMPTY' failed
pixbuf=00000000
Can anyone suggest a way to implement pixbuf_new_from_stock ?
There are good reasons for wanting to do that - having to do with wrapping both MSWIN and GTK with a common interface.
BTW, is there a way to convert Gtk error locations such as 5319 into nim source line numbers??
What do you think where the problem is? Are you following a C example or the Krause book?
As you know I am using only GTK3 -- but from my memory of examples and the Krause book I think that the second parameter of gtk_image_new_from_stock is generally a C enum of type GtkIconSize. So allowed values may be 0,1,2... and the absolute size value 32 may be invalid. Well just a guess, I have not the gtk2 sources or the gtk2 nim wrapper available currently.
For your last question, the number (5319) is the process id, so it contains no information of error location. GTK developers generally compile whole GTK (and maybe other libs too) with debugger support, and then seems to be able to find error locations with gdb. I tried that once to find the reason for a gtk warning, but was not really successful. Generally it is easier to write just correct code, so you need no low level debugging.
[EDIT]
I just asked Google and found this, maybe it is helpful for you: (I am not really sure if that is GTK2 or GTK3 unfortunately)
Your tip was better than useful. Here is nimish code that worked (with some inessential validating code):
var iconset = icon_factory_lookup_default("gtk-dialog-error")
echo "iconset=",cast[int](iconset).toHex(8)
if iconset==nil: quit("Bad Icon Id")
var dmystyle = style_new() # contrary to some docs, style CANNOT be NULL
var pixbuf = iconset.render_icon(dmystyle,TEXT_DIR_NONE,
STATE_NORMAL,ICON_SIZE_DIALOG,nil,nil)
echo "stock pixbuf=",cast[int](pixbuf).toHex(8)