Search code examples
robjectuser-interfacegwidgets

Is there a way to get the container from a gWidget?


question

I note that delete(obj,widget,...) requires the container/parent obj of the widget that is to be deleted. Is there an easy way to pull this from widget directly?

context

I'm trying to write a quick 'foolproof' widget refresh function that deletes and re-adds the same widget (a la https://stackoverflow.com/a/6571570/2023432) or another one to replace it, and ran into the above problem early:

refresh.widget <- function(old.widget, new.widget = old.widget) {
    delete(old.widget$container, old.widget)
    new.widget
}

Solution

  • The only workaround I can think of is to build a hierarchy for each widget tree with some functions that will take in a list; something like

    widget.tree <- list()
    add.widget <- function(tree,my.parent,new.widget) {
      widget.tree[new.widget] <- list(widget = new.widget, 
                                      parent = my.parent)
      add(my.parent, new.widget)
    }
    

    and then interacting with widgets in a tree solely through functions that operate on these attributes. This seems kind of like a lot of machinery though, which starts to take you back to working directly with GUI toolkits through R, losing you the ease of gWidgets. I'm not going to use this workaround, myself. As @jverzani said, it's far better to use gWidgets2 if you can.