Search code examples
rwindowiconsgwidgets

How do I change the WM icon for a gwindow() using gWidgets in R?


I would like to change the Window Manager icon (in the top left corner of my gwindow()), using gWidgets in R. I want to add my own picture rather than using the R logo in the corner. I have loaded the picture into R, just by calling gimage("imagename.jpg"). I can manage to open this image up in a window, by calling gimage("imagename.jpg", cont=gwindow(cont=T)), but not as the icon.

I feel like this should be something really simple to do. I have googled how to do it, but can't find an answer. I found that, using RGtk2, you just add the argument icon=imagename when creating the window.

I tried this with gWidgets as well by calling gwindow(icon=gimage("imagename.jpg"), cont=T), however this didn't do anything different than just calling gwindow without the extra argument.

This seems like it should be really simple, but I can't find an answer anywhere. Any help would be greatly appreciated.

Thanks.


Solution

  • There is nothing in gWidgets here to help, but if you load RGtk2, then the setIcon method of the GtkWindow can help you, but you need to get it first:

    Try something like:

    w <- gwindow()
    require(RGtk2)
    img <- gdkPixbufNewFromFile("your_icon.png")
    getToolkitWidget(w)$setIcon(img$retval)