Search code examples
rgwidgets

How to add a spinning wheel animation to a gWidgets GUI


I have just started making GUI's in R and as a first step I'm working with gWidgets before venturing into some lower level frameworks...

I would like to add a spinning wheel animation to show that a process is running. While gWidgets doesn't seem to support this, RGtk2 does.

So my basic question is how to add an RGtk2 widget to a gWidgets GUI when the widget is not 'natively' supported by gWidgets. Also, how do you manipulate the widget once added...

Thanks in advance

Thomas


Solution

  • Here is how it can be done in gWidgets or gWidgets2 (on github):

    library(gWidgets) ## or gWidgets2
    options(guiToolkit="RGtk2")
    library(RGtk2)    ## needed
    
    w <- gwindow()
    g <- ggroup(cont=w)
    g1 <- ggroup(cont=g) ## holds spinner
    
    b1 <- gbutton("stop spinner", cont=g, handler=function(h,...) {
      spin$stop()
    })
    b2 <- gbutton("remove spinner", cont=g, handler=function(...) {
      delete(g, g1)
    })
    
    
    spin <- gtkSpinner()
    spin$start()
    
    ## pack into g1 box container:
    ## in gWidgets2 can do this: add(g1, spin)
    ## for gWidgets it can be hacked:
    g1@widget@widget$packStart(spin)
    

    In gWidgets2 there is a gprogressbar widget to do something similar, but not this.