0

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
}
Community
  • 1
  • 1
bright-star
  • 6,016
  • 6
  • 42
  • 81
  • 1
    In `gWidgets2` this becomes easy, as containers have a children field, so the children can be accessed by `container$children`. You may have to filter to get the one you want. Heads up: if I recall correctly `delete` for some toolkits really does delete the widget, for others it just removes it from the container. – jverzani Jan 01 '15 at 12:16
  • Definitely looking forward to migrating to gWidgets2 once I finish this project. Thanks! – bright-star Jan 01 '15 at 23:07
  • Sorry then, keeping track of children at the `gWidgets` level wasn't added until the rewrite. Not sure how you would work around this. – jverzani Jan 02 '15 at 15:56

1 Answers1

1

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.

bright-star
  • 6,016
  • 6
  • 42
  • 81